home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: Product
/
Product.zip
/
DBDEMO.ZIP
/
DEMODB.ZIP
/
D30ACBC1.C
< prev
next >
Wrap
Text File
|
1991-07-03
|
38KB
|
1,386 lines
static unsigned char sqla_program_id[40] =
{111,65,65,66,65,67,66,67,84,71,82,65,89,32,32,32,68,51,48,65,
67,66,67,49,105,66,74,73,74,68,72,72,32,32,32,32,32,32,32,32};
#ifdef LINT_ARGS
short far pascal sqlaaloc(unsigned short,
unsigned short,
unsigned short,
void far *);
short far pascal sqlacall(unsigned short,
unsigned short,
unsigned short,
unsigned short,
void far *);
short far pascal sqladloc(unsigned short,
void far *);
short far pascal sqlasets(unsigned short,
unsigned char far *,
void far *);
short far pascal sqlasetv(unsigned short,
unsigned short,
unsigned short,
unsigned short,
void far *,
void far *,
void far *);
short far pascal sqlastop(void far *);
short far pascal sqlastrt(void far *,
void far *,
struct sqlca far *);
short far pascal sqlausda(unsigned short,
struct sqlda far *,
void far *);
#else
short far pascal sqlaaloc( );
short far pascal sqlacall( );
short far pascal sqladloc( );
short far pascal sqlasets( );
short far pascal sqlasetv( );
short far pascal sqlastop( );
short far pascal sqlastrt( );
short far pascal sqlausda( );
#endif
/************************************* *******************/
/* */
/* APPLICATION PROGRAM NAME: D30ACBC1.SQC of D30SCB01 */
/* */
/* PROGRAM LANGUAGE: 'C' Language */
/* */
/* PROGRAM DESCRIPTION: D30ACBC1.SQC is the import/create view pgm */
/* */
/* This program will create the necessary views */
/* that will be used throughout the BANKING */
/* scenario. */
/* */
/* In addition, 5 of the 7 tables that form the */
/* the BANK database, will be filled with actual */
/* data via the Import function. */
/* */
/* The remaining two tables will have their */
/* data filled during D30ACB03.SQC. */
/* */
/* AUTHOR: D. J. Grant DATE: 04/17/87 */
/* */
/* DATABASE: SHELBY 3 BANK database */
/* Tables: Customer/Box/Loan/Debits/Credits/Savings/Checking*/
/* */
/* INPUT FILES: Import files: */
/* */
/* CUSTOMER.WRK */
/* BOX.WR1 */
/* LOAN.WKS */
/* SAVINGS.WKS */
/* CHECKING.WK1 */
/* */
/* OUTPUT FILES: D30ACBC1.ERR - this is a file, written to disk, only */
/* when some type of error condition is returned from */
/* SQL. It serves as an error log, recording the error */
/* code, its corresponding error message, and any other */
/* useful information which the program might be able */
/* to give. */
/* */
/* CUSTERR - is a file that will be created as a */
/* result of an error on the import function for the */
/* CUSTOMER table. If this file does not exist, it */
/* will be created as a result of the error condition. */
/* */
/* Similarly, the following files will be created if */
/* an error occurs during the import function with */
/* regard to the respective tables: BOXERR, LOANERR */
/* SAVERR, and CHCKERR. */
/* */
/* *********************** PROLOGUE CONTINUED NEXT PAGE ***************** */
/* ****************************************** *********** */
/* *********************** PROLOGUE CONTINUED **************************** */
/* */
/* */
/* DEPENDENCIES: INVICTA, SHELBY 3 DATABASE KERNEL, */
/* creation of SHELBY 3 BANK database, */
/* pre-compilation with SQLPREP, */
/* binding to data base with SQLPREP or SQLBIND, */
/* compilation with IBM C/2, using */
/* compiler options: */
/* "/AL /DLINT_ARGS /DSQL_REL_10 /W2 /Od /FPa" */
/* */
/* FUNCTION CALLS: 'C' COMPILER LIBRARY */
/* stdio.h - fopen,fclose,fgets,fprintf */
/* malloc.h - malloc */
/* string.h - strcpy */
/* memory.h - memcpy */
/* */
/* SHELBY 3 LIBRARY */
/* sql.h - sqlaintp */
/* sqlenv.h - sqlestrd,sqlestpd */
/* - sqleisig (ctrl-break processing) */
/* sqlutil.h - import utility */
/* */
/* OTHER */
/* none */
/* */
/* ERROR CONDITIONS: */
/* NORMAL - specifically tested for and handled by the ap- */
/* plication program: (exit_normal) */
/* DOS (errorlvl) = 0. */
/* */
/* ABNORMAL - unexpected and resulting in program termination: */
/* (exit_error) */
/* DOS (errorlvl) = 2. */
/* */
/* MODIFICATIONS: */
/* Date Author Description */
/* */
/* 10/05/87 D.J. Grant - added enhanced exit_error code */
/* to handle < or > sqlaintp error.*/
/* - added file open error handling */
/* to display error message on */
/* screen. */
/* - add to each page.*/
/* - added code to restart database. */
/* - changed each table import process */
/* to use memcpy to specify the */
/* tcolumn list, instead of using */
/* a strcpy. */
/* - added DOS return code processing. */
/* - changed all program references to */
/* use new naming conventions. */
/* 10/26/87 D.J.Grant Added SQLEISIG function call, and */
/* enhances exit_error to also print */
/* SQLERRD[0] - [5] and SQL_ERRP. */
/* 03/08/88 D.J.Grant - deleted the ZP compiler option. */
/* - created new table - NEWCUST. */
/* - created views - VIEWBOX & VIEWCUST*/
/* 07/28/88 W.B.Brown - added two views using SET ops */
/* views will be exported in D30ACB05*/
/* 02/03/89 W.B.Brown - upgraded to release 3.0 */
/** END OF PROLOGUE ********************************************************/
/******************************************** ***************/
/*****************************************************************************/
/* SET UP INCLUDES */
/*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <sql.h>
#include <sqlenv.h>
#include <sqlutil.h>
#include <sqlca.h>
/*****************************************************************************/
/* DEFINITIONS AND DECLARATIONS */
/*****************************************************************************/
struct sqlca sqlca;
/* Set up error message buffer */
unsigned char msgbuf[512];
/* Declarations for D30ACBC1.ERR error file */
unsigned char errorfle[]="D30ACBC1.err";
unsigned char tcaseid[]="Test Case Id : D30ACBC1.SQC";
unsigned char descript[]="BANK: create views & import";
/* Declarations for BANK data base */
unsigned char database[]="bank"; /* establish database name */
unsigned char password[]=""; /* set up null password */
/* Declarations for import filnames */
unsigned char imp_cust[]="customer.wrk";
unsigned char imp_box []="box.wr1";
unsigned char imp_loan[]="loan.wks";
unsigned char imp_sav []="savings.wks";
unsigned char imp_chck[]="checking.wk1";
unsigned char imptype []="WSF";
/* Declarations for import Insert string for tclostrg */
unsigned char ins_cust[]="INSERT INTO CUSTOMER";
unsigned char ins_box []="INSERT INTO BOX ";
unsigned char ins_loan[]="INSERT INTO LOAN ";
unsigned char ins_sav []="INSERT INTO SAVINGS ";
unsigned char ins_chck[]="INSERT INTO CHECKING";
unsigned char custerr[] = "custerr.msg";
unsigned char boxerr[] = "boxerr.msg";
unsigned char loanerr[] = "loanerr.msg";
unsigned char saverr[] = "saverr.msg";
unsigned char chckerr[] = "chckerr.msg";
/*****************************************************************************/
unsigned char rte_label[16] = " "; /* progress marker */
unsigned char sqlerrp_value[9] = " "; /* error value */
/*****************************************************************************/
/******************************************** ***************/
int main (void);
main ()
{
FILE *ptr_errorfle; /* declare ptr to error fle */
/*****************************************************************************/
/* Import information: The following section sets up the environment for */
/* the 5 imports that will be performed during this program. Maximum */
/* pointers and memory allocations will be set up inorder to allow */
/* one set up for all 5 imports. */
/* */
/*****************************************************************************/
struct sqlchar *tcolstrg; /* pointer to tcolstrg */
struct sqlchar *filetmod; /* declare import structure */
struct sqldcol *dcoldata; /* pointer to dcolumn list */
char *ptr1, *ptr2, *ptr3; /* pointers for memory allocation */
int callerac = 0;
/* Program local variables */
int errlevel = 0; /* return code to DOS call pgm */
short dbas_cls = 0; /* database open/close flag */
short rc = 0; /* variable for return code */
/* Allocate storage for sqldcol; the number used in the assignment should */
/* be the maximum number of columns for any table. */
ptr1 = malloc((sizeof(char))+(sizeof(short))+(10*sizeof(struct sqldcoln)));
dcoldata = (struct sqldcol *)ptr1;
dcoldata->dcolmeth = 'D';
ptr2 = malloc(22);
tcolstrg = (struct sqlchar *)ptr2;
tcolstrg->length = 20;
ptr3 = malloc(3);
filetmod = (struct sqlchar *)ptr3;
filetmod->length = 0;
filetmod->data[0] = '\0';
/******************************************** ***************/
/*****************************************************************************/
/* ERROR HANDLING FOR SQL STATEMENTS */
/*****************************************************************************/
/*
EXEC SQL
WHENEVER SQLERROR GOTO exit_error;
*/
/*
EXEC SQL
WHENEVER SQLWARNING CONTINUE;
*/
/*
EXEC SQL
WHENEVER NOT FOUND CONTINUE;
*/
/*****************************************************************************/
strcpy(rte_label,"instal sqleisig");
sqleisig(&sqlca); /* ctrl-break processing */
if (sqlca.sqlcode != 0)
{
goto exit_error;
}
/***************************************************************************/
/*****************************************************************************/
/* START USING DATABASE */
/*****************************************************************************/
strcpy(rte_label,"start database ");
start_dbres:
sqlestrd (database,'S',&sqlca);
if (sqlca.sqlcode == -1015) /* If start db func */
{ /* fails, call restart */
strcpy(rte_label,"restart databas"); /* func. */
sqlerest(database,&sqlca); /* Check for failed */
if (sqlca.sqlcode != 0) /* restart; on error */
{ /* set dbase closed, */
dbas_cls = -1; /* go to error exit. */
goto exit_error;
}
strcpy(rte_label,"start database2");
sqlestrd (database,'S',&sqlca); /* Good restart-start */
} /* db again. */
if (sqlca.sqlcode != 0) /* Check 2nd start for */
{ /* failure; if failed, */
dbas_cls = -1; /* set flag to closed. */
goto exit_error; /* Also checks for any */
} /* other error code on */
/* 1st sqlestrd. */
/******************************************** ***************/
/* ***************** ADD FOREIGN KEYS TO TABLES ********************** */
strcpy(rte_label,"ADD FOREIGN KEY");
/*
EXEC SQL
ALTER TABLE SAVINGS FOREIGN KEY SSSN (S_SSN) REFERENCES CUSTOMER
ON DELETE RESTRICT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,1,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL
ALTER TABLE LOAN FOREIGN KEY LSSN (L_SSN) REFERENCES CUSTOMER
ON DELETE RESTRICT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,2,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL
ALTER TABLE CHECKING FOREIGN KEY CSSN (C_SSN1) REFERENCES CUSTOMER
ON DELETE RESTRICT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,3,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL
ALTER TABLE DEBITS FOREIGN KEY DACCT (DB_ACCNUMB) REFERENCES CHECKING
ON DELETE CASCADE;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,4,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL
ALTER TABLE CREDITS FOREIGN KEY CACCT (CR_ACCNUMB) REFERENCES CHECKING
ON DELETE CASCADE;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,5,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL COMMIT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)21,0,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/* *********************** GRANT PRIVILEGES *************************** */
strcpy(rte_label,"REVOKE PUBLIC ");
/*
EXEC SQL
REVOKE CREATETAB ON DATABASE FROM PUBLIC;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,6,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL
REVOKE BINDADD ON DATABASE FROM PUBLIC;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,7,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL
REVOKE CONNECT ON DATABASE FROM PUBLIC;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,8,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
strcpy(rte_label,"GRANT PRIVILEGE");
/*
EXEC SQL
GRANT DBADM ON DATABASE TO GDBADM, BADMIN;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,9,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL
GRANT CONNECT, BINDADD ON DATABASE TO GPREP, PREP;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,10,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL
GRANT CONNECT, CREATETAB ON DATABASE TO GCREATE, TCREATE;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,11,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL
GRANT CONNECT ON DATABASE TO GQRYSEL, QRYSEL, GEDIT, TEDIT, GTVCON,
TVCON, GSELINS, SELINS, REFER, TDELETE, TUPDATE, SELUPDEL, TEXECUTE,
EDITALT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,12,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL
GRANT SELECT ON TABLE CUSTOMER TO GQRYSEL, QRYSEL;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,13,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE CUSTOMER TO GEDIT, TEDIT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,14,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE CHECKING TO GEDIT, TEDIT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,15,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE SAVINGS TO GEDIT, TEDIT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,16,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL COMMIT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)21,0,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*****************************************************************************/
/* Create View 1 - for D30ACB02 (year end loan report) */
/*****************************************************************************/
strcpy (rte_label,"create vloan ");
/*
EXEC SQL
CREATE VIEW VLOAN AS
SELECT CU_SSN,CU_NAME,CU_ADDR1,CU_ADDR2,CU_ZIP,L_NUMB,L_TYPE,L_RATE,
L_PAYMT,L_BAL,L_INTODAT,L_DESCRIP,L_DATE,L_SSN,L_TERM
FROM CUSTOMER, LOAN
WHERE CUSTOMER.CU_SSN = LOAN.L_SSN;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,17,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*****************************************************************************/
/* Create View 2 - for D30ACB02 (savings report) */
/*****************************************************************************/
strcpy (rte_label,"create vsave ");
/*
EXEC SQL
CREATE VIEW VSAVE AS
SELECT CU_SSN,CU_NAME,S_INTTOD,S_ACCNUMB,S_BAL,S_SSN
FROM CUSTOMER, SAVINGS
WHERE CUSTOMER.CU_SSN = SAVINGS.S_SSN;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,18,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL COMMIT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)21,0,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/******************************************** ***************/
/* Create View 3 - for D30ACB06 (view import) */
/*****************************************************************************/
strcpy (rte_label,"create viewbox ");
/*
EXEC SQL
CREATE VIEW VIEWBOX AS
SELECT B_NUMB, B_SIZE, B_RENT
FROM BOX
WHERE B_SIZE = 'M';
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,19,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL COMMIT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)21,0,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*****************************************************************************/
/* Create View 4 - for D30ACB06 (view import) */
/*****************************************************************************/
strcpy (rte_label,"create viewcust");
/*
EXEC SQL
CREATE VIEW VIEWCUST AS
SELECT *
FROM NEWCUST;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,20,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL COMMIT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)21,0,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*****************************************************************************/
/* Create View 5 - for D30ACB05 (view export) */
/*****************************************************************************/
strcpy (rte_label,"create solloan ");
/*
EXEC SQL
CREATE VIEW SOLLOAN (SSN, SSNSC) AS
((SELECT CU_SSN, S_SSN
FROM CUSTOMER, SAVINGS
WHERE (CU_SSN = S_SSN) AND (S_BAL > 1000.00))
INTERSECT
(SELECT CU_SSN, C_SSN1
FROM CUSTOMER, CHECKING
WHERE (CU_SSN = C_SSN1) AND (C_ENDBAL > 1000.00))
EXCEPT
(SELECT CU_SSN, L_SSN
FROM CUSTOMER, LOAN
WHERE CU_SSN = L_SSN));
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,21,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL COMMIT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)21,0,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*****************************************************************************/
/* Create View 6 - for D30ACB05 (view export) */
/*****************************************************************************/
strcpy (rte_label,"create chkact ");
/*
EXEC SQL
CREATE VIEW CHKACT (ACCNUMB) AS
((SELECT C_ACCNUMB
FROM CHECKING
WHERE C_ACCNUMB NOT IN (SELECT DB_ACCNUMB FROM DEBITS))
INTERSECT
(SELECT C_ACCNUMB
FROM CHECKING
WHERE C_ACCNUMB NOT IN (SELECT CR_ACCNUMB FROM CREDITS)));
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,22,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL COMMIT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)21,0,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*****************************************************************************/
/* Create View 7 - for D30ACB05 (view export) */
/*****************************************************************************/
strcpy (rte_label,"create inactcus");
/*
EXEC SQL
CREATE VIEW INACTCUS (SSN) AS
(SELECT CU_SSN FROM CUSTOMER
WHERE CU_SSN NOT IN ((SELECT C_SSN1 FROM CHECKING)
UNION
(SELECT S_SSN FROM SAVINGS)
UNION
(SELECT L_SSN FROM LOAN)
UNION
(SELECT B_SSN FROM BOX)));
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,23,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL COMMIT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)21,0,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/**************************************** *******************/
/* Customer table import */
strcpy (rte_label,"import customer");
tcolstrg->length = 20;
memcpy(tcolstrg->data,ins_cust,20); /* default the tcolumn list */
sqluimp (database,imp_cust,dcoldata,tcolstrg,
imptype,filetmod,custerr,callerac,&sqlca);
if (sqlca.sqlcode < 0)
{
goto exit_error;
}
/*
EXEC SQL COMMIT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)21,0,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/* Box table import */
strcpy (rte_label,"import box data");
memcpy(tcolstrg->data,ins_box,20); /* default the tcolumn list */
sqluimp (database,imp_box,dcoldata,tcolstrg,
imptype,filetmod,boxerr,callerac,&sqlca);
if (sqlca.sqlcode < 0)
{
goto exit_error;
}
/*
EXEC SQL COMMIT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)21,0,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/* Loan table import */
strcpy (rte_label,"import loan dat");
memcpy(tcolstrg->data,ins_loan,20); /* default the tcolumn list */
sqluimp (database,imp_loan,dcoldata,tcolstrg,
imptype,filetmod,loanerr,callerac,&sqlca);
if (sqlca.sqlcode < 0)
{
goto exit_error;
}
/*
EXEC SQL COMMIT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)21,0,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/******************************************** ***************/
/* Savings table import */
strcpy (rte_label,"import savings ");
memcpy(tcolstrg->data,ins_sav,20); /* default the tcolumn list */
sqluimp (database,imp_sav,dcoldata,tcolstrg,
imptype,filetmod,saverr,callerac,&sqlca);
if (sqlca.sqlcode < 0)
{
goto exit_error;
}
/*
EXEC SQL COMMIT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)21,0,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/* Checking table import */
strcpy (rte_label,"import checking");
memcpy(tcolstrg->data,ins_chck,20); /* default the tcolumn list */
sqluimp (database,imp_chck,dcoldata,tcolstrg,
imptype,filetmod,chckerr,callerac,&sqlca);
printf("\n inserting data into table PERFDAT3 \n");
/*
EXEC SQL
INSERT INTO PERFDAT3 SELECT
CU_SSN , CU_NAME, CU_ADDR1 , CU_ADDR2 ,CU_ZIP , L_NUMB , L_TYPE, L_RATE ,
L_TERM ,L_PAYMT, L_BAL, L_INTODAT,L_DESCRIP, L_DATE, S_ACCNUMB , S_IRATE,
S_INTTOD, S_BAL, B_NUMB , B_SIZE,B_RENT , B_PAYUP, C_ACCNUMB , C_STARTBAL, C_ENDBAL
FROM CUSTOMER, LOAN, SAVINGS, BOX, CHECKING
WHERE CU_SSN = L_SSN AND CU_SSN = S_SSN AND CU_SSN = B_SSN AND CU_SSN = C_SSN1;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,24,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
printf("\n inserting data into table PERFDAt4 \n");
/*
EXEC SQL
INSERT INTO PERFDAt4 SELECT
CU_SSN , CU_NAME, CU_ADDR1 , CU_ADDR2 ,CU_ZIP , L_NUMB , L_TYPE, L_RATE ,
L_TERM ,L_PAYMT, L_BAL, L_INTODAT,L_DESCRIP, L_DATE, S_ACCNUMB , S_IRATE,
S_INTTOD, S_BAL, B_NUMB , B_SIZE,B_RENT , B_PAYUP, C_ACCNUMB , C_STARTBAL, C_ENDBAL
FROM CUSTOMER, LOAN, SAVINGS, BOX, CHECKING
WHERE CU_SSN = L_SSN AND CU_SSN = S_SSN AND CU_SSN = B_SSN AND CU_SSN = C_SSN1;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,25,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/*
EXEC SQL CREATE INDEX D3INDEX ON PERFDAT3 (CU_SSN ASC);
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)24,26,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
if (sqlca.sqlcode >= 0)
{
goto exit_normal; /* exit the program due to error */
}
/*
EXEC SQL COMMIT;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)21,0,0,0,0L);
if (sqlca.sqlcode < 0)
{
sqlastop(0L);
goto exit_error;
}
sqlastop(0L);
}
/******************************************** ***************/
/*****************************************************************************/
exit_error:
/* set up error file processing */
errlevel = 2; /* set DOS return code -error */
if ((ptr_errorfle = fopen(errorfle, "w")) == NULL)
{
printf ("\nUNABLE TO OPEN D30ACBC1.ERR\n"); /* can't open errorfle */
printf ("%s\n",rte_label); /* display msg - screen*/
printf ("SQLCODE IS %ld\n",sqlca.sqlcode);
goto continue_err;
} /* print to error file */
fprintf (ptr_errorfle,"%s\n%s\n",tcaseid,descript);
fprintf (ptr_errorfle,"%s\n",rte_label);
fprintf (ptr_errorfle,"SQLCODE IS %ld\n",sqlca.sqlcode);
/* SQL miscellaneous error info*/
fprintf(ptr_errorfle,"\nSQLERRD[0] is %ld",sqlca.sqlerrd[0]);
fprintf(ptr_errorfle,"\nSQLERRD[1] is %ld",sqlca.sqlerrd[1]);
fprintf(ptr_errorfle,"\nSQLERRD[2] is %ld",sqlca.sqlerrd[2]);
fprintf(ptr_errorfle,"\nSQLERRD[3] is %ld",sqlca.sqlerrd[3]);
fprintf(ptr_errorfle,"\nSQLERRD[4] is %ld",sqlca.sqlerrd[4]);
fprintf(ptr_errorfle,"\nSQLERRD[5] is %ld",sqlca.sqlerrd[5]);
memcpy (sqlerrp_value, sqlca.sqlerrp,8);
fprintf(ptr_errorfle,"\nSQLERRP is %s",sqlerrp_value);
rc = sqlaintp(msgbuf,512,0,&sqlca);
if (rc < 0) /* message retrieval err*/
{
fprintf (ptr_errorfle, "SQLAINTP ERROR. Return Code = %d",rc);
}
else if (rc > 0)
{ /* print error message */
fprintf (ptr_errorfle,"\n");
fprintf (ptr_errorfle,msgbuf);
}
fclose(ptr_errorfle); /* close the error file */
continue_err: /* reset sqlerror to eliminate*/
/* looping if Rollback fails */
/*
EXEC SQL
WHENEVER SQLERROR CONTINUE;
*/
/*
EXEC SQL
ROLLBACK WORK;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)28,0,0,0,0L);
sqlastop(0L);
}
/* Rollback any work */
if (sqlca.sqlcode < 0) /* Rollback failed */
{
if ((ptr_errorfle = fopen(errorfle,"a")) == NULL) /* open errorfle */
{ /* open failed - display msg. */
printf ("\nUNABLE TO OPEN D30ACBC1.ERR -- ROLLBACK FAILED");
goto exit_normal;
}
fprintf (ptr_errorfle,"\nSQLCODE IS %ld, ROLLBACK FAILED.",sqlca.sqlcode);
fclose(ptr_errorfle); /* close the error file */
}
/*****************************************************************************/
/******************************************** ***************/
exit_normal:
if (dbas_cls == 0)
{
sqlestpd (&sqlca); /* stop using the database */
}
return(errlevel); /* DOS error return code */
}