home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: Product
/
Product.zip
/
DBDEMO.ZIP
/
DEMODB.ZIP
/
D30ACBA1.C
< prev
next >
Wrap
Text File
|
1991-06-03
|
13KB
|
234 lines
/**************************************** ***************/
/* */
/* APPLICATION PROGRAM NAME: D30ACBA1.C of D30SCB01 */
/* */
/* PROGRAM LANGUAGE: 'C' Language */
/* */
/* PROGRAM DESCRIPTION: */
/* D30ACBA1 is the first program in the D30SCB01 application. */
/* This program will create the BANK data base. The data base */
/* will have the following attributes: */
/* */
/* - Data base has a comment */
/* */
/* AUTHOR: D.J.Grant DATE: 04/22/87 */
/* */
/* DATABASE: */
/* OS/2 EE DBM BANK DATABASE */
/* */
/* INPUT FILES: D30SCB01.INP - drive letter on which database will be */
/* created. */
/* */
/* OUTPUT FILES: */
/* D30ACBA1.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: */
/* OS/2 EE DBM , */
/* compilation with IBM C/2, using compiler options: */
/* "/AL /Gs /DLINT_ARGS /DSQL_REL_10 /W3 /Od /FPa" */
/* */
/* FUNCTION CALLS: */
/* COMPILER LIBRARY */
/* stdio.h - fopen,fclose,fgets,fprintf */
/* string.h - strcpy */
/* */
/* SHELBY 3 LIBRARY */
/* sql.h - sqlaintp */
/* sqlca.h - sqlca */
/* sqlenv.h - sqlecred, sqledrpd */
/* */
/* OTHER */
/* none */
/* */
/******************************************** (Prolog continued next page)*/
/** (Prolog continued) ****************** ***************/
/* */
/* ERROR CONDITIONS: */
/* */
/* NORMAL - specifically tested for and handled by the */
/* application program: (exit_normal) */
/* */
/* OS/2(errorlvl) return code = 0 */
/* */
/* ABNORMAL - unexpected and resulting in program termination: */
/* (exit_error) */
/* */
/* OS/2(errorlvl) return code = 2 */
/* MODIFICATIONS: */
/* Date Author Description */
/* */
/* 09/14/87 D.J. Grant - changed all internal program name */
/* references to match new naming */
/* conventions. */
/* - added the sqlenv.h functional call*/
/* - changed references of &MYSQLCA to */
/* sqlca (now in lowercase also). */
/* - added code to allow return codes */
/* to be passed back to DOS. */
/* - added to each */
/* page. */
/* - initialized rc to 0. */
/* - added more comments to program. */
/* */
/* 10/05/87 D.J. Grant - added rte_label to mark progress. */
/* - removed memory.h include. */
/* - removed OUTRECLEN variable process*/
/* - revised sqlaintp rc to read >0 */
/* instead of != 0. */
/* */
/* 02/29/88 D. J. Grant - added the database drive parameter*/
/* */
/* 02/03/89 W. B. Brown - upgraded to run on release 3.0 */
/* specifically, changed 'G20...' */
/* to 'D30...' and added drive input */
/* file. */
/* */
/*** (END OF PROLOG) *******************************************************/
/**************************************** *****************/
/*****************************************************************************/
/* SET UP INCLUDES */
/*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <sql.h>
#include <sqlca.h>
#include <sqlenv.h>
/*****************************************************************************/
/* DEFINITIONS AND DECLARATIONS */
/*****************************************************************************/
/* Set up SQLCA for this program */
/*********************************/
struct sqlca sqlca; /* declare sqlca */
/******************************/
/* define error msg buffer */
/******************************/
unsigned char msgbuf[512];
/***************************************************/
/* Declarations for create data base function call */
/***************************************************/
unsigned char database[]="bank"; /* establish database name */
unsigned char password[]=""; /* set up null password */
unsigned char dcomment[]="BANK data base - 7 tables"; /* comment */
short codepage = 0; /* set up zero for codepage */
unsigned char drive ='\0'; /* use default drive for db */
unsigned char drv ='\0'; /* unless parm is entered */
unsigned char inputfle[]="D30SCB01.INP"; /* DB DRIVE FILE */
/********************************************/
/* Declarations for D30ACBA1.ERR error file */
/********************************************/
unsigned char errorfle[]="D30ACBA1.ERR"; /* error file description */
unsigned char tcaseid[]="Test Case Id : D30ACBA1.C";
unsigned char descript[]=
"Create BANK data base ";
/***********************************************/
/* Set up variable to pass return codes to DOS */
/***********************************************/
short errorlvl = 0; /* variable used to pass return codes */
/* to DOS */
/**************************************** *****************/
int main (void);
main ()
{
/* declare local program variables */
unsigned char rte_label[16]; /* program progress marker */
short rc = 0; /* variable for return code */
FILE *ptr_output; /* declare output file */
FILE *ptr_input; /* declare input file */
/*****************************************************************************/
/* Issue a drop for the BANK database - unconditionally; continue on error. */
/*****************************************************************************/
strcpy(rte_label,"drop database ");
/* drop the BANK database if it */
sqledrpd (database,password,&sqlca); /* exists, otherwise go ahead */
/* and create it */
/*****************************************************************************/
/* Read input file D30SCB01.INP to get drive letter on which database will */
/* be created. */
/*****************************************************************************/
if ((ptr_input = fopen(inputfle,"r")) == NULL) /* open the input file*/
{
printf ("\nUNABLE TO OPEN D30SCB01.INP"); /* display on screen */
printf ("\nDATABASE WILL BE CREATED ON DEFAULT DRIVE");
goto create_db;
}
drv = fgetc(ptr_input);
drive = drv;
/*****************************************************************************/
/* Create BANK data base: No password, default drive, with comment */
/*****************************************************************************/
create_db:
strcpy(rte_label,"create database");
sqlecred (database,drive,password,dcomment,codepage,&sqlca);
rc = sqlaintp (msgbuf,512,0,&sqlca);
if (rc > 0)
{
goto exit_error; /* exit on error */
}
goto exit_normal; /* exit program - normally */
/**************************************** *****************/
/*****************************************************************************/
/** EXIT_ERROR ROUTINE */
/*****************************************************************************/
exit_error:
if ((ptr_output = fopen(errorfle,"w")) == NULL) /* open the error file*/
{
printf ("\nUNABLE TO OPEN D30ACBA1.ERR"); /* display on screen */
printf ("\nSQLCODE IS %ld",sqlca.sqlcode);
goto exit_normal;
}
/* print error information */
fprintf (ptr_output,"%s\n%s\n",tcaseid,descript);
fprintf (ptr_output,"%s\n",rte_label);
fprintf (ptr_output,msgbuf);
fprintf (ptr_output,"\nSQLCODE is %ld.\n",sqlca.sqlcode);
fclose(ptr_output); /* close the output file */
errorlvl = 2; /* set return code - 2 (error)*/
/*****************************************************************************/
/** EXIT_NORMAL ROUTINE */
/*****************************************************************************/
exit_normal:
return (errorlvl); /* return error level code */
}