home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: Product
/
Product.zip
/
DBDEMO.ZIP
/
DEMODB.ZIP
/
D30ACB03.SQC
< prev
next >
Wrap
Text File
|
1991-06-03
|
38KB
|
805 lines
/********************************** ******** PAGE 1 */
/* */
/* APPLICATION PROGRAM NAME: D30ACB03.SQC */
/* */
/* PROGRAM LANGUAGE: 'C' Language with Embedded SQL */
/* */
/* PROGRAM DESCRIPTION: */
/* D30ACB03 uses 'C' language to read two ASCII files */
/* created under PE2 which contain credit and debit */
/* transactions and uses imbedded SQL to insert these */
/* rows of transactions into the database tables CREDITS */
/* and DEBITS. The purpose of this program is to test the */
/* following functions of SHELBY: */
/* */
/* START DB (SHARED) (3.2.10) */
/* RESTART DB */
/* STOP DB (3.2.11) */
/* DATA TYPES: NUMERICAL (3.3.5.1) */
/* DECIMAL */
/* DATA TYPES: CHARACTER (3.3.5.2) */
/* HOST VARIABLES (3.3.7.3) */
/* IMBEDDED SQL (3.9.1) */
/* EXEC SQL (3.9.1.1) */
/* BEGIN/END DECLARE (3.9.1.2) */
/* INCLUDE (3.9.1.3) */
/* WHENEVER (3.9.1.5) */
/* SELECT (3.6.1) */
/* SUM,AVG,MIN,MAX,COUNT (3.3.8.2) */
/* INSERT (3.6.5) */
/* LOCK - EXCLUSIVE (3.6.8) */
/* COMMIT - with WORK option (3.6.9) */
/* ROLLBACK (3.6.10) */
/* 'C' LANGUAGE INTERFACE (3.11.1) */
/* HOST VARIABLES (3.11.1.1) */
/* LANGUAGE RESTRICTIONS (3.11.1.2) */
/* SPECIAL COMMANDS (3.11.1.3) */
/* PRECOMPILER (3.11.1.4) */
/* DB ENVIRONMENT (3.11.1.4) */
/* ERROR MSG (3.11.1.4) */
/* */
/* AUTHOR: W.B.Brown DATE: 06/16/87 */
/* */
/* DATA BASE: */
/* SHELBY 3 BANK database */
/* - CREDITS table */
/* - DEBITS table */
/* */
/* INPUT FILES: */
/* CREDITS.ASC - an ASCII file containing the data to be */
/* inserted into each row of the CREDITS table. The file was */
/* created using Personal Editor and saved in ASCII format by */
/* specifying "file credits.asc notabs". */
/* */
/* DEBITS.ASC - an ASCII file containing the data to be */
/* inserted into each row of the DEBITS table. The file was */
/* created using Personal Editor and saved in ASCII format by */
/* specifying "file debits.asc notabs". */
/* */
/* *************** PROLOG CONTINUED NEXT PAGE ********************** */
/* ** PROLOG CONTINUED ************ ******** PAGE 2 */
/* */
/* */
/* OUTPUT FILES: */
/* D30ACB03.ERR - This is a file, written to disk, only when */
/* some unexpected error condition is returned from SQL. It */
/* serves as an error log, recording the error code, its cor- */
/* responding error message, and any other useful information */
/* which the program might be able to give. */
/* */
/* D30ACB03.SUM - This is a file, written to disk with records */
/* containing summary data from both the input files and the */
/* tables (after the data has been inserted). Summary data */
/* will consist of the count of records read in/count of the */
/* rows in the tables; average check amount; average deposit */
/* amount; minimum and maximum on the same two columns; and the */
/* sum of those columns. Comparisons between input data and */
/* TABLE data will be recorded as matched or unmatched. */
/* */
/* DEPENDENCIES: */
/* INVICTA, SHELBY 3 DATABASE KERNEL, */
/* database manager started */
/* creation of SHELBY 3 BANK database, */
/* creation of CREDITS and DEBITS tables, */
/* precompiling and binding with SQLPREP */
/* compilation with IBM C Compiler 2.0, using compiler options: */
/* "/AL /Gs /DLINT_ARGS /DSQL_REL_10 /W3 /Od " */
/* */
/* FUNCTION CALLS: */
/* COMPILER LIBRARY */
/* stdio.h - fopen,fclose,fgets,fprintf */
/* memory.h - memcpy */
/* string.h - strcpy */
/* stdlib.h - data conversion */
/* math.h - math conversion */
/* SHELBY 3 LIBRARY */
/* sql.h - sqlaintp; sqlenv - sqlestrd,sqlestpd,sqlerest */
/* sqlutil.h - insert */
/* sqlca.h - sqlca.sqlcode */
/* sqlenv.h - sqleisig (ctrl-break processing) */
/* OTHER */
/* none */
/* */
/* ERROR CONDITIONS: */
/* 'C' NORMAL - specifically tested for and handled by the ap- */
/* plication program: */
/* log error, exit thru "end" routine. */
/* */
/* SQL ABNORMAL - unexpected and resulting in program termination: */
/* log error, exit thru "ret_code" & "end" routine */
/* -1015 Restart Database */
/* */
/* MODIFICATIONS: */
/* Date Author Description */
/* */
/* 09/02/87 W.B.Brown Debug & add screen print routine if */
/* error file fails to open. */
/* */
/* 10/26/87 D.J.Grant Added SQLEISIG function call, and */
/* enhances exit_error to also print */
/* SQLERRD[0] - [5] and SQL_ERRP. */
/* */
/* 2/09/88 W.B.Brown Removed COMMIT HOLD - DCR 214 */
/* after INSERTing. */
/* 8/02/88 W.B.Brown Added a flag to determine if summary*/
/* file has been opened */
/* 2/03/89 W.B.Brown Upgraded to release 3.0 */
/***************************************************************************/
/* Include library functions **** ******** PAGE 3 */
#include <stdio.h>
#include <memory.h>
#include <string.h>
#include <sql.h>
#include <sqlenv.h>
#include <sqlutil.h>
#include <sqlca.h>
#include <stdlib.h>
#include <math.h>
/* Define lengths for input records and for routine labels */
#define CRECLEN 27 /* Credit input record - 25 bytes, \n,\0 */
#define DEBLEN 32 /* Debit input record - 30 bytes, \n.\0 */
#define RTELBLEN 16 /* Labels for routines - error tracking */
/* The following field definitions are for the length of each field in input */
/* These lengths will be used to move fields from input record to host vars */
#define CRACNOLN 8 /* Checking acct. no. for a credit */
#define CRDATELN 8 /* Transaction date (mm-dd-yy) */
#define CRAMTLN 9 /* Deposit amount - decimal (8,2) */
#define DBACNOLN 8 /* Checking acct. no. for a debit */
#define DBDATELN 8 /* Transaction date (mm-dd-yy) */
#define DBAMTLN 9 /* Check amount - decimal (8,2) */
#define DBCKNOLN 5 /* Check number */
struct sqlca sqlca;
/* The following definitions are for input/output/error tracking purposes: */
/* an input buffer to hold the ASCII record */
/* a message buffer for use with SQL error messages */
/* a field for tracking progress thru the program */
/* database name, error file, and summary file */
unsigned char crdt_buff[CRECLEN]; /* Input buffer for credits */
unsigned char debt_buff[DEBLEN]; /* Input buffer for debits */
unsigned char msg_buf[512]; /* SQL error message buffer */
unsigned char rte_label[RTELBLEN]; /* Routine label for error tracking */
unsigned char dbase[] = "BANK";
unsigned char password[] = "";
unsigned char errfile[] = "D30ACB03.ERR";
unsigned char sumdata[] = "D30ACB03.SUM";
unsigned char credfile[] = "credits.asc";
unsigned char debfile[] = "debits.asc";
unsigned char sqlerrp_value[9] = " "; /* error value */
int errlevel = 0;
/* **************************** ******** PAGE 4 */
/* */
/* THIS COMMENT BOX SHOWS THE DEFINITION OF THE TABLES ON THE DATABASE. */
/* */
/* CREDITS TABLE DEBITS TABLE */
/* CR_ACCNUMB CHAR(8) NOT NULL DB_ACCNUMB CHAR(8) NOT NULL */
/* CR_TRANDATE CHAR(8) NOT NULL DB_TRANDATE CHAR(8) NOT NULL */
/* CR_DEPAMT DEC(8,2) NOT NULL DB_AMT DEC(8,2) NOT NULL */
/* DB_CHECKNO CHAR(5) NOT NULL */
/* */
/* **************************************************************** */
/* ********************************************************************** */
/* SQL DECLARE SECTION - Host variables - used to insert data from the */
/* input buffers to the CREDITS and DEBITS tables */
/* ********************************************************************** */
EXEC SQL BEGIN DECLARE SECTION;
/* Credit transaction fields */
unsigned char craccno[8];
unsigned char crdate[8];
double cramt;
/* Debit transaction fields */
unsigned char dbaccno[8];
unsigned char dbdate[8];
double dbamt;
unsigned char dbchkno[5];
/* Host variables for summary data from CREDITS and DEBITS tables after */
/* data has been inserted into these tables. */
long crd_cnt;
long deb_cnt;
double crd_sum;
double deb_sum;
double crd_min;
double deb_min;
double crd_max;
double deb_max;
double crd_avg;
double deb_avg;
EXEC SQL END DECLARE SECTION;
/* *********************************************************************** */
/* END OF SQL DECLARE SECTION - Host variables */
/* *********************************************************************** */
/* ** BEGIN MAIN FUNCTION ******* ******** PAGE 5 */
int main (void);
main ()
{
/* Declare input files, output error file, and output summary data file */
FILE *ptr_crinput; /* Credit input file pointer */
FILE *ptr_dbinput; /* Debit input file pointer */
FILE *ptr_errfile; /* Error file pointer */
FILE *ptr_sumdata; /* Summary file pointer */
/* Declare a short integer to receive the return code message length-SQL */
/* Declare a short integer to indicate credits fle open(0), failed(-1). */
/* Declare a short integer to indicate error file open(-1) or closed(0). */
/* (Error file is open for error, therefore (-1) is used for open.) */
/* Declare a short integer to indicate dbase open(0) or failed (-1). */
short rc = 0; /* From sqlaintp - initialize to 0 */
short crd_opn = 0; /* Initialize to open. */
short err_cls = 0; /* Initialize to closed. */
short sum_cls = 0; /* Initialize to closed. */
short dbas_cls = 0; /* Initialize to open. */
/* Declare and initialize counters for summary data on records read */
/* from the ASCII files. */
long cr_count = 0;
long db_count = 0;
double cr_sum = 0.0;
double db_sum = 0.0;
double cr_min = 999999.99;
double db_min = 999999.99;
double cr_max = 0.0;
double db_max = 0.0;
double cr_avg = 0.0;
double db_avg = 0.0;
short crsum_match = 0;
short crcnt_match = 0;
short crmin_match = 0;
short crmax_match = 0;
short cravg_match = 0;
short dbsum_match = 0;
short dbcnt_match = 0;
short dbmin_match = 0;
short dbmax_match = 0;
short dbavg_match = 0;
/* Declare a char variable for the decimal fields read in and use them later */
/* to convert to double type. */
unsigned char ch_cramt[10];
unsigned char ch_dbamt[10];
/* PAGE 6 */
/* In order to access individual fields in the input ASCII file, each field */
/* will have an assigned pointer corresponding to the position offset in */
/* the input buffer; each field will be referenced by its pointer. */
unsigned char *ptr_craccno; /* Credit trans. ptrs */
unsigned char *ptr_crdate;
unsigned char *ptr_cramt;
unsigned char *ptr_dbaccno; /* Debit trans. ptrs */
unsigned char *ptr_dbdate;
unsigned char *ptr_dbamt;
unsigned char *ptr_dbchkno;
ch_cramt[9] = '\0'; /* Set last char in */
ch_dbamt[9] = '\0'; /* interim var to null */
ptr_craccno = crdt_buff; /* Credit trans fields */
ptr_crdate = crdt_buff + 8;
ptr_cramt = crdt_buff + 16;
ptr_dbaccno = debt_buff; /* Debit trans fields */
ptr_dbdate = debt_buff + 8;
ptr_dbamt = debt_buff + 16;
ptr_dbchkno = debt_buff + 25;
/* ***************************** ******* PAGE 7 */
/* */
/* SQL EXCEPTION HANDLING */
/* Whenever an error occurs during the execution of an SQL statement, */
/* (sqlcode = negative number), go to error routine. */
/* If a warning occurs (sqlcode = positive number), continue with the next */
/* executable statement in the program. */
/* If a row is not found or a selected table is empty, go to error routine. */
/* */
/* ************************************* */
EXEC SQL
WHENEVER SQLERROR GOTO ret_code;
EXEC SQL
WHENEVER SQLWARNING CONTINUE;
EXEC SQL
WHENEVER NOT FOUND GOTO ret_code;
/* ************************************* */
strcpy(rte_label,"instal sqleisig");
sqleisig(&sqlca); /* ctrl-break processing */
if (sqlca.sqlcode != 0)
{
goto ret_code;
}
/* **************************************** */
/* */
/* Store routine name "open credits" in rte_label for progress tracking; */
/* Open Credit file with appropriate pointer; check for error on open; */
/* in case of error, open the error file and write a message on errfile */
/* */
/* ***************************************** */
strcpy(rte_label,"open credit asc");
if ((ptr_crinput = fopen(credfile,"r")) == NULL)
{
crd_opn = -1;
goto ret_code;
}
/* ****************************** ********* PAGE 8 */
/* */
/* Store the name of the routine in rte_label for error tracking */
/* Start the database using the function "sqlestrd"; check for error on */
/* start-database function. */
/* */
/* ****************************** */
/* */
strcpy(rte_label,"start database ");
start_dbres:
sqlestrd (dbase,password,'S',&sqlca);
if (sqlca.sqlcode == -1015) /* If start db func */
{ /* fails, call restart */
strcpy(rte_label,"restart databas"); /* func. */
sqlerest(dbase,password,&sqlca); /* Check for failed */
if (sqlca.sqlcode != 0) /* restart; on error */
{ /* set dbase closed, */
dbas_cls = -1; /* go to error exit. */
goto ret_code;
}
strcpy(rte_label,"start database2");
sqlestrd (dbase,password,'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 ret_code; /* Also checks for any */
} /* other error code on */
/* 1st sqlestrd. */
/* ***************************** */
/* */
/* Store the name of the routine in rte_label for error tracking. */
/* LOCK THE CREDITS TABLE IN EXCLUSIVE MODE TO INSERT ROWS OF DATA. */
/* Check for unsuccessful LOCK; on error go to log error and exit. */
/* */
/* ****************************** */
strcpy(rte_label,"lock credit exm");
EXEC SQL
LOCK TABLE CREDITS IN EXCLUSIVE MODE;
/* *************************** ******** PAGE 9 */
/* */
/* Until end of file is reached on the CREDITS.ASC file, read each row, */
/* calculate summary data, move each field from input buffer to the SQL */
/* host variable, insert from the host variables to the CREDITS table. */
/* */
/* ******************************* */
cred_loop:
while ((fgets(crdt_buff,CRECLEN,ptr_crinput)) != NULL)
{
/* Move fields from input buffer to host variables. */
memcpy(craccno,ptr_craccno,CRACNOLN); /* CR Acct. No. */
memcpy(crdate,ptr_crdate,CRDATELN); /* CR Trans. Date */
memcpy(ch_cramt,ptr_cramt,CRAMTLN); /* CR Deposit Amt. */
cramt = atof(ch_cramt); /* Convert to double */
/* Calculate summary data from input record. */
cr_count = cr_count + 1; /* Count of creds */
cr_sum = cramt + cr_sum; /* Total deposit amts */
if (cramt < cr_min)
{
cr_min = cramt; /* Find/assign MIN amt */
}
if (cramt > cr_max)
{
cr_max = cramt; /* Find/assign MAX amt */
}
/* Insert data from host variables to columns in CREDITS table */
strcpy(rte_label, "insert ccommand");
EXEC SQL
INSERT INTO CREDITS (CR_ACCNUMB, CR_TRANDATE, CR_DEPAMT)
VALUES (:craccno, :crdate, :cramt);
} /* End While Loop */
/* ************************** ******** PAGE 10 */
/* */
/* Check for no credit transactions - log on error file, end pgm; else: */
/* When end of input file is reached, calculate the average for "cramt", */
/* and using SELECT and SUM, MIN, MAX, AVG, COUNT, calculate summary data */
/* from the data inserted into the CREDITS table. */
/* Compare the input summary data with the table inserted data and set */
/* flags (0 for unequal, 1 for equal) to be printed out with the summary */
/* data to file G20ACB03.SUM. */
/* */
/* ********************************* */
strcpy(rte_label, "no credit input");
if (cr_count == 0)
{
fclose (ptr_crinput);
goto ret_code;
}
/* Calculate the average for credit amount field from input field. */
cr_avg = (cr_sum / cr_count);
/* Select summary data from columns in CREDITS table. */
strcpy(rte_label, "select ccommand");
EXEC SQL
SELECT SUM(CR_DEPAMT), AVG(CR_DEPAMT), MIN(CR_DEPAMT), MAX(CR_DEPAMT),
COUNT(*)
INTO :crd_sum, :crd_avg, :crd_min, :crd_max, :crd_cnt
FROM CREDITS;
/* Compare input summary data with table summary data for match. */
if (cr_sum == crd_sum)
{
crsum_match = 1;
}
if (cr_count == crd_cnt)
{
crcnt_match = 1;
}
if (cr_min == crd_min)
{
crmin_match = 1;
}
if (cr_max == crd_max)
{
crmax_match = 1;
}
if (cr_avg == crd_avg)
{
cravg_match = 1;
}
/* *************************** ********* PAGE 11 */
/* */
/* Print summary data & match data for credits to summary file. */
/* */
/* ************************************************************ */
strcpy(rte_label,"open sumry file");
if ((ptr_sumdata = fopen(sumdata, "w")) == NULL)
{
goto ret_code;
}
sum_cls = 1;
fprintf(ptr_sumdata,"CREDIT TABLE ROW COUNT: %ld\n",crd_cnt);
fprintf(ptr_sumdata,"CREDIT.ASC ROW COUNT: %ld\n",cr_count);
fprintf(ptr_sumdata,"CREDIT TABLE DEPAMT SUM: %.2f\n",crd_sum);
fprintf(ptr_sumdata,"CREDIT.ASC DEPAMT SUM: %.2f\n",cr_sum);
fprintf(ptr_sumdata,"CREDIT TABLE DEPAMT MIN: %.2f\n",crd_min);
fprintf(ptr_sumdata,"CREDIT.ASC DEPAMT MIN: %.2f\n",cr_min);
fprintf(ptr_sumdata,"CREDIT TABLE DEPAMT MAX: %.2f\n",crd_max);
fprintf(ptr_sumdata,"CREDIT.ASC DEPAMT MAX: %.2f\n",cr_max);
fprintf(ptr_sumdata,"CREDIT TABLE DEPAMT AVG: %.2f\n",crd_avg);
fprintf(ptr_sumdata,"CREDIT.ASC DEPAMT AVG: %.2f\n",cr_avg);
fprintf(ptr_sumdata,"%d%d%d%d%d\n",
crcnt_match, crsum_match, crmin_match, crmax_match, cravg_match);
/* UNLOCK, RELEASE CREDITS TABLE. CLOSE CREDITS.ASC FILE. */
fclose(ptr_crinput);
EXEC SQL COMMIT WORK;
/* ************************************************************************* */
/* */
/* DEBIT INPUT AND INSERTION INTO DEBITS TABLE SECTION */
/* */
/* ************************************************************************* */
/* Open Debit file with appropriate pointer; check for error on open; */
/* in case of error, open the error file and write a message on errfile */
strcpy(rte_label,"open debits asc");
if ((ptr_dbinput = fopen(debfile,"r")) == NULL)
{
goto ret_code;
}
/* ***************************** */
/* */
/* Store the name of the routine in rte_label for error tracking. */
/* Lock the DEBITS table in exclusive mode for insertion. */
/* */
/* ****************************** */
strcpy(rte_label,"lock debits tbl");
EXEC SQL
LOCK TABLE DEBITS IN EXCLUSIVE MODE;
/* ***************************** ******** PAGE 12 */
/* */
/* Until end of file is reached on the DEBITS.ASC file, read each row, */
/* calculate summary data, move each field from input buffer to the SQL */
/* host variable, insert from the host variables to the DEBITS table. */
/* */
/* ******************************* */
dbet_loop:
while ((fgets(debt_buff,DEBLEN,ptr_dbinput)) != NULL)
{
/* Move fields from input buffer to host variables. */
memcpy(dbaccno,ptr_dbaccno,DBACNOLN); /* DB Acct. No. */
memcpy(dbdate,ptr_dbdate,DBDATELN); /* DB Trans. Date */
memcpy(ch_dbamt,ptr_dbamt,DBAMTLN); /* DB Check Amt. */
dbamt = atof(ch_dbamt); /* Convert to double */
memcpy(dbchkno,ptr_dbchkno,DBCKNOLN); /* DB Check No. */
/* Calculate summary data from input record. */
db_count = db_count + 1; /* Count of debits */
db_sum = dbamt + db_sum; /* Total check amts */
if (dbamt < db_min)
{
db_min = dbamt; /* Find/assign MIN amt */
}
if (dbamt > db_max)
{
db_max = dbamt; /* Find/assign MAX amt */
}
/* Insert data from host variables to columns in DEBITS table */
strcpy(rte_label, "insert dcommand");
EXEC SQL
INSERT INTO DEBITS (DB_ACCNUMB, DB_TRANDATE, DB_AMT, DB_CHECKNO)
VALUES (:dbaccno, :dbdate, :dbamt, :dbchkno);
} /* End While Loop */
/* ************************** ******** PAGE 13 */
/* */
/* Check for no debits on input file, log error, end pgm; else: */
/* When end of input file is reached, calculate the average for "dbamt", */
/* and using SELECT and SUM, MIN, MAX, AVG, COUNT, calculate summary data */
/* from the data inserted into the DEBITS table. */
/* Compare the input summary data with the table inserted data and set */
/* flags (0 for unequal, 1 for equal) to be printed out with the summary */
/* data to file D30ACB03.SUM. */
/* */
/* ********************************* */
strcpy (rte_label, "no debit input ");
if (db_count == 0)
{
fclose (ptr_dbinput);
goto ret_code;
}
/* Calculate the average for debit (check) amount field from input. */
db_avg = (db_sum / db_count);
/* Calculate summary data from columns in DEBITS table. */
strcpy(rte_label, "select dcommand");
EXEC SQL
SELECT SUM(DB_AMT), AVG(DB_AMT), MIN(DB_AMT), MAX(DB_AMT), COUNT(*)
INTO :deb_sum, :deb_avg, :deb_min, :deb_max, :deb_cnt
FROM DEBITS;
/* Compare input summary data with table summary data for match. */
if (db_sum == deb_sum)
{
dbsum_match = 1;
}
if (db_count == deb_cnt)
{
dbcnt_match = 1;
}
if (db_min == deb_min)
{
dbmin_match = 1;
}
if (db_max == deb_max)
{
dbmax_match = 1;
}
if (db_avg == deb_avg)
{
dbavg_match = 1;
}
/* *************************** *********** PAGE 14 */
/* */
/* Print summary data & match data for debits to summary file. */
/* */
/* *********************************************************** */
fprintf(ptr_sumdata,"DEBIT TABLE ROW COUNT: %ld\n",deb_cnt);
fprintf(ptr_sumdata,"DEBIT.ASC ROW COUNT: %ld\n",db_count);
fprintf(ptr_sumdata,"DEBIT TABLE DEPAMT SUM: %.2f\n",deb_sum);
fprintf(ptr_sumdata,"DEBIT.ASC DEPAMT SUM: %.2f\n",db_sum);
fprintf(ptr_sumdata,"DEBIT TABLE DEPAMT MIN: %.2f\n",deb_min);
fprintf(ptr_sumdata,"DEBIT.ASC DEPAMT MIN: %.2f\n",db_min);
fprintf(ptr_sumdata,"DEBIT TABLE DEPAMT MAX: %.2f\n",deb_max);
fprintf(ptr_sumdata,"DEBIT.ASC DEPAMT MAX: %.2f\n",db_max);
fprintf(ptr_sumdata,"DEBIT TABLE DEPAMT AVG: %.2f\n",deb_avg);
fprintf(ptr_sumdata,"DEBIT.ASC DEPAMT AVG: %.2f\n",db_avg);
fprintf(ptr_sumdata,"%d%d%d%d%d\n",
dbcnt_match, dbsum_match, dbmin_match, dbmax_match, dbavg_match);
/* CLOSE DEBITS.ASC FILE. UNLOCK, RELEASE DEBITS TABLE. */
fclose(ptr_dbinput);
EXEC SQL COMMIT WORK;
/* */
goto end;
/* ******************************* */
/* */
/* EXIT ERROR ROUTINE - Log error information to screen or print file. */
/* */
/* ******************************* */
ret_code:
errlevel = 2;
if ((ptr_errfile = fopen(errfile, "w")) == NULL)
{
printf ("\nUNABLE TO OPEN D30ACB03.ERR\n");
printf ("%s\n",rte_label);
printf ("SQLCODE IS %ld\n",sqlca.sqlcode);
printf("Number of CREDIT inserts: %ld\n", cr_count);
printf("Number of DEBIT inserts: %ld\n", db_count);
goto continue_err;
}
err_cls = 1;
fprintf(ptr_errfile,"%15s\n",rte_label);
fprintf(ptr_errfile,"SQLCODE IS %ld\n",sqlca.sqlcode);
/* SQL miscellaneous error info*/
fprintf(ptr_errfile,"\nSQLERRD[0] is %ld",sqlca.sqlerrd[0]);
fprintf(ptr_errfile,"\nSQLERRD[1] is %ld",sqlca.sqlerrd[1]);
fprintf(ptr_errfile,"\nSQLERRD[2] is %ld",sqlca.sqlerrd[2]);
fprintf(ptr_errfile,"\nSQLERRD[3] is %ld",sqlca.sqlerrd[3]);
fprintf(ptr_errfile,"\nSQLERRD[4] is %ld",sqlca.sqlerrd[4]);
fprintf(ptr_errfile,"\nSQLERRD[5] is %ld",sqlca.sqlerrd[5]);
memcpy (sqlerrp_value, sqlca.sqlerrp, 8);
fprintf(ptr_errfile,"\nSQLERRP is %s",sqlerrp_value);
rc = sqlaintp(msg_buf,512,0,&sqlca);
if (rc < 0)
{
fprintf (ptr_errfile, "SQLAINTP ERROR. Return Code = %d",rc);
}
else if (rc > 0)
{
fprintf (ptr_errfile,"\n");
fprintf (ptr_errfile,msg_buf);
}
fprintf(ptr_errfile,"\nNumber of CREDIT inserts: %ld\n", cr_count);
fprintf(ptr_errfile,"Number of DEBIT inserts: %ld\n", db_count);
/* *************************** ********** PAGE 15 *** */
continue_err:
EXEC SQL
WHENEVER SQLERROR CONTINUE;
EXEC SQL
ROLLBACK WORK;
if (sqlca.sqlcode < 0)
{
if ((ptr_errfile = fopen(errfile,"a")) == NULL)
{
printf ("\nUNABLE TO OPEN D30ACB03.ERR -- ROLLBACK FAILED");
goto end;
}
fprintf (ptr_errfile,"\nSQLCODE IS %ld, ROLLBACK FAILED.",sqlca.sqlcode);
}
/* ************************** ******** PAGE 16 */
/* */
/* END OF PROGRAM - ROUTINE LABEL "END" */
/* */
/* ************************************* */
end:
if (sum_cls != 0)
{ /* Summary file was */
fclose(ptr_sumdata); /* opened if there */
} /* were any credits. */
if ((dbas_cls == 0) && (crd_opn == 0)) /* Database was opened */
{ /* if credit file open */
strcpy(rte_label,"stop database ");
sqlestpd (&sqlca); /* Stop using database */
}
if (err_cls == 1) /* If an SQL or 'C' */
{ /* error has occurred */
fclose(ptr_errfile); /* close error file. */
}
return(errlevel);
} /* END MAIN FUNCTION */