home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: Product
/
Product.zip
/
DBDEMO.ZIP
/
DEMODB.ZIP
/
D30ACBD1.C
< prev
next >
Wrap
Text File
|
1991-07-03
|
21KB
|
633 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,68,49,99,65,117,81,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
/********************************** ******** PAGE 1 */
/* */
/* APPLICATION PROGRAM NAME: D30ACBD1.SQC */
/* */
/* PROGRAM LANGUAGE: 'C' Language with Embedded SQL */
/* */
/* PROGRAM DESCRIPTION: */
/* D30ACBD1 uses 'C' language to create indexes on all */
/* tables in the BANK database, and to do runstats */
/* using the newly created indexes. The following functions */
/* of SHELBY are tested: */
/* */
/* START DB (SHARED) (3.2.10) */
/* RESTART DB */
/* STOP DB (3.2.11) */
/* DATA TYPES: NUMERICAL (3.3.5.1) */
/* DATA TYPES: CHARACTER (3.3.5.2) */
/* 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) */
/* ROLLBACK (3.6.10) */
/* CREATE INDEXEX */
/* RUNSTATS */
/* 'C' LANGUAGE INTERFACE (3.11.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: S. L. Pettit DATE: 11/01/87 */
/* */
/* DATA BASE: */
/* SHELBY 3 BANK database */
/* - CREDITS table - LOAN table */
/* - DEBITS table - SAVINGS table */
/* - CUSTOMER table - BOX table */
/* - CHECKING table */
/* */
/* INPUT FILES: NONE */
/* */
/* *************** PROLOG CONTINUED NEXT PAGE ********************** */
/* ** PROLOG CONTINUED ************ ******** PAGE 2 */
/* */
/* */
/* OUTPUT FILES: */
/* D30ACBD1.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. */
/* */
/* DEPENDENCIES: */
/* INVICTA, SHELBY 3 DATABASE KERNEL, */
/* database manager started */
/* creation of SHELBY 3 BANK database, */
/* creation of all tables in BANK database, */
/* 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 */
/* string.h - strcpy */
/* SHELBY 3 LIBRARY */
/* sql.h - sqlaintp; sqlenv - sqlestrd,sqlestpd,sqlerest */
/* 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 */
/* */
/* 10/26/87 D.J.Grant Added SQLEISIG function call, and */
/* enhances exit_error to also print */
/* SQLERRD[0] - [5] and SQL_ERRP. */
/* 11/30/87 W.B.Brown Add prolog */
/* 02/03/89 W.B.Brown Upgrade for release 3.0 */
/***************************************************************************/
#include <stdio.h>
#include <string.h>
#include <sql.h>
#include <sqlenv.h>
#include <sqlutil.h>
/*
EXEC SQL INCLUDE sqlca;
*/
/* SQL Communication Area - SQLCA - structures and constants */
#ifndef SQLCODE
/* SQL Communication Area - SQLCA */
struct sqlca
{
unsigned char sqlcaid[8]; /* Eyecatcher = 'SQLCA ' */
long sqlcabc; /* SQLCA size in bytes = 136 */
long sqlcode; /* SQL return code */
short sqlerrml; /* Length for SQLERRMC */
unsigned char sqlerrmc[70]; /* Error message tokens */
unsigned char sqlerrp[8]; /* Diagnostic information */
long sqlerrd[6]; /* Diagnostic information */
unsigned char sqlwarn[8]; /* Warning flags */
unsigned char sqlext[8]; /* Reserved */
};
#define SQLCODE sqlca.sqlcode
#define SQLWARN0 sqlca.sqlwarn[0]
#define SQLWARN1 sqlca.sqlwarn[1]
#define SQLWARN2 sqlca.sqlwarn[2]
#define SQLWARN3 sqlca.sqlwarn[3]
#define SQLWARN4 sqlca.sqlwarn[4]
#define SQLWARN5 sqlca.sqlwarn[5]
#define SQLWARN6 sqlca.sqlwarn[6]
#define SQLWARN7 sqlca.sqlwarn[7]
#endif
struct sqlca sqlca;
#define LABELLEN 16 /* statement label length for error logging */
/* 15 characters + string null */
unsigned char msgbuf[512];
unsigned char s_label[LABELLEN];
unsigned char database[] = "BANK"; /* database name */
unsigned char password[] = ""; /* password to database */
unsigned char errfile[] = "D30ACBD1.ERR"; /* error file DOS name */
unsigned char errpterm[9] = " "; /* Null terminated string */
/* for printing sqlerrp */
unsigned char customer[] = "DBSYSADM.CUSTOMER";
unsigned char box[] = "DBSYSADM.BOX";
unsigned char checking[] = "DBSYSADM.CHECKING";
unsigned char savings[] = "DBSYSADM.SAVINGS";
unsigned char loan[] = "DBSYSADM.LOAN";
unsigned char credits[] = "DBSYSADM.CREDITS";
unsigned char debits[] = "DBSYSADM.DEBITS";
/***************************************************************************/
/* SQL DECLARE SECTION - For this program none are declared. */
/***************************************************************************/
/*
EXEC SQL BEGIN DECLARE SECTION;
*/
/*
EXEC SQL END DECLARE SECTION;
*/
/***************************************************************************/
int main (void);
main ()
{
FILE *ptr_error; /* declare error file */
int errorlevel = 0; /* to be returned to DOS */
short rc = 0; /* return code from sqlaintp (error mes- */
/* sage retrieval function) */
unsigned char *ptr_idxlist[2];
int numidx;
install_sig:
strcpy (s_label, "install_sig:");
sqleisig (&sqlca); /* Install DBM supplied signal */
/* handling routine. */
if (sqlca.sqlcode != 0)
{
goto exit_error;
}
/*
EXEC SQL
WHENEVER SQLERROR GOTO exit_error;
*/
/*
EXEC SQL
WHENEVER SQLWARNING CONTINUE;
*/
/*
EXEC SQL
WHENEVER NOT FOUND CONTINUE;
*/
start_db:
sqlestrd (database,password,'S',&sqlca); /* Start using specified DB, */
/* with specified password, in */
/* shared mode. */
if (sqlca.sqlcode == -1015) /* If the database needs to be */
{ /* restarted, due to previ- */
strcpy (s_label,"restart:"); /* ous system failure, issue */
sqlerest (database,password,&sqlca); /* restart, followed by */
if (sqlca.sqlcode != 0) /* another start using. */
{
goto exit_error;
}
sqlestrd (database,password,'S',&sqlca);
}
strcpy(s_label,"start_db: ");
if (sqlca.sqlcode != 0)
{
goto exit_error;
}
create_index1:
strcpy(s_label,"create_index1:");
printf ("\n CREATING BOX INDEX ON BOX NUMBER \n");
/*
EXEC SQL
CREATE UNIQUE INDEX IDX_B_NUMB ON BOX (B_NUMB);
*/
{
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);
}
create_index2:
strcpy(s_label,"create_index2:");
printf ("\n CREATING LOAN INDEX ON LOAN NUMBER \n");
/*
EXEC SQL
CREATE UNIQUE INDEX IDX_L_NUMB ON LOAN (L_NUMB);
*/
{
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);
}
create_index3:
strcpy(s_label,"create_index3:");
printf ("\n CREATING LOAN INDEX ON LOAN SSN \n");
/*
EXEC SQL
CREATE INDEX IDX_L_SSN ON LOAN (L_SSN);
*/
{
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);
}
create_index4:
strcpy(s_label,"create_index4:");
printf ("\n CREATING SAVINGS INDEX ON SAVINGS NUMBER \n");
/*
EXEC SQL
CREATE UNIQUE INDEX IDX_S_ACCNUMB ON SAVINGS (S_ACCNUMB);
*/
{
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);
}
create_index5:
strcpy(s_label,"create_index5:");
printf ("\n CREATING SAVINGS INDEX ON SAVINGS SSN \n");
/*
EXEC SQL
CREATE INDEX IDX_S_SSN ON SAVINGS (S_SSN);
*/
{
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);
}
create_index6:
strcpy(s_label,"create_index7:");
printf ("\n CREATING CHECKING INDEX ON CHECKING SSN1 \n");
/*
EXEC SQL
CREATE INDEX IDX_C_SSN1 ON CHECKING (C_SSN1);
*/
{
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);
}
create_index7:
strcpy(s_label,"create_index7:");
printf ("\n CREATING CREDITS INDEX ON CREDITS NUMBER \n");
/*
EXEC SQL
CREATE INDEX IDX_CR_ACCNUMB ON CREDITS (CR_ACCNUMB);
*/
{
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);
}
create_index8:
strcpy(s_label,"create_index8:");
printf ("\n CREATING DEBITS INDEX ON DEBITS NUMBER \n");
/*
EXEC SQL
CREATE INDEX IDX_DB_ACCNUMB ON DEBITS (DB_ACCNUMB);
*/
{
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);
}
runstat1:
strcpy(s_label,"runstat1:");
ptr_idxlist[0] = "DBSYSADM.IDX_B_NUMB";
numidx = 1;
// printf ("\n RUNSTATS ON BOX NUMBER INDEX \n");
// sqlustat (box, numidx, ptr_idxlist, 'B', 'R', &sqlca);
// if (sqlca.sqlcode != 0)
// {
// goto exit_error;
// }
runstat2:
strcpy(s_label,"runstat2:");
ptr_idxlist[0] = "DBSYSADM.IDX_L_NUMB";
ptr_idxlist[1] = "DBSYSADM.IDX_L_SSN";
numidx = 2;
// printf ("\n RUNSTATS ON LOAN NUMBER AND SSN \n");
// sqlustat (loan, numidx, ptr_idxlist, 'B', 'R', &sqlca);
// if (sqlca.sqlcode != 0)
// {
// goto exit_error;
// }
runstat3:
strcpy(s_label,"runstat3:");
ptr_idxlist[0] = "DBSYSADM.IDX_S_ACCNUMB";
ptr_idxlist[1] = "DBSYSADM.IDX_S_SSN";
numidx = 2;
// printf ("\n RUNSTATS ON SAVINGS NUMBER AND SSN \n");
// sqlustat (savings, numidx, ptr_idxlist, 'B', 'R', &sqlca);
// if (sqlca.sqlcode != 0)
// {
// goto exit_error;
// }
runstat4:
strcpy(s_label,"runstat4:");
ptr_idxlist[0] = "DBSYSADM.IDX_C_SSN1";
numidx = 1;
// printf ("\n RUNSTATS ON CHECKING NUMBER AND SSN1 \n");
// sqlustat (checking, numidx, ptr_idxlist, 'B', 'R', &sqlca);
// if (sqlca.sqlcode != 0)
// {
// goto exit_error;
// }
runstat5:
strcpy(s_label,"runstat5:");
ptr_idxlist[0] = "DBSYSADM.IDX_CR_ACCNUMB";
numidx = 1;
// printf ("\n RUNSTATS ON CREDITS NUMBER INDEX \n");
// sqlustat (credits, numidx, ptr_idxlist, 'B', 'R', &sqlca);
// if (sqlca.sqlcode != 0)
// {
// goto exit_error;
// }
runstat6:
strcpy(s_label,"runstat6:");
ptr_idxlist[0] = "DBSYSADM.IDX_DB_ACCNUMB";
numidx = 1;
// printf ("\n RUNSTATS ON DEBITS NUMBER INDEX \n");
// sqlustat (debits, numidx, ptr_idxlist, 'B', 'R', &sqlca);
// if (sqlca.sqlcode != 0)
// {
// goto exit_error;
// }
goto exit_normal;
exit_error:
/* if unable to open errfile, */
/* write messages to screen. */
if ((ptr_error = fopen(errfile, "w")) == NULL)
{
printf ("\nUNABLE TO OPEN D30ACBD1.ERR\n");
printf ("%s SQLCODE IS %ld\n",s_label,sqlca.sqlcode);
goto continue_err;
}
fprintf (ptr_error,"%s\n",s_label); /* write error information to */
/* file. */
fprintf (ptr_error,"SQLCODE IS %ld\n",sqlca.sqlcode);
fprintf (ptr_error,"SQLERRD[0] IS %ld\n",sqlca.sqlerrd[0]);
fprintf (ptr_error,"SQLERRD[1] IS %ld\n",sqlca.sqlerrd[1]);
fprintf (ptr_error,"SQLERRD[2] IS %ld\n",sqlca.sqlerrd[2]);
fprintf (ptr_error,"SQLERRD[3] IS %ld\n",sqlca.sqlerrd[3]);
fprintf (ptr_error,"SQLERRD[4] IS %ld\n",sqlca.sqlerrd[4]);
fprintf (ptr_error,"SQLERRD[5] IS %ld\n",sqlca.sqlerrd[5]);
memcpy (errpterm,sqlca.sqlerrp,8);
fprintf (ptr_error,"SQLERRP IS %s\n",errpterm);
rc = sqlaintp (msgbuf,512,50,&sqlca); /* call error message retreival */
if (rc < 0) /* -- retrieve failed. */
{
fprintf (ptr_error,"SQLAINTP ERROR. Return code = %d",rc);
}
else if (rc > 0) /* -- retrieve successful. */
{
fprintf (ptr_error,msgbuf);
}
fclose (ptr_error); /* close error file */
continue_err:
errorlevel = 2;
/*
EXEC SQL /- reset sqlerror handling to -/
WHENEVER SQLERROR CONTINUE;
*/
/* prevent endless error loop */
/* if rollback should fail. */
/*
EXEC SQL
ROLLBACK WORK;
*/
{
sqlastrt(sqla_program_id,0L,&sqlca);
sqlacall((unsigned short)28,0,0,0,0L);
sqlastop(0L);
}
if (sqlca.sqlcode != 0) /* If error, add on to already */
/* created errfile. If unable */
/* to open, write to screen. */
{
if ((ptr_error = fopen(errfile, "a")) == NULL)
{
printf ("\nUNABLE TO OPEN D30ACBD1.ERR -- ROLLBACK FAILED.");
goto exit_normal;
}
fprintf (ptr_error,"\nSQLCODE IS %ld, ROLLBACK FAILED.",sqlca.sqlcode);
fclose (ptr_error);
}
exit_normal:
sqlestpd (&sqlca); /* stop using the database */
end:
return(errorlevel);
}