home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Product / Product.zip / DBDEMO.ZIP / DEMODB.ZIP / D30ACBA1.C < prev    next >
Text File  |  1991-06-03  |  13KB  |  234 lines

  1. /****************************************       ***************/
  2. /*                                                                         */
  3. /*  APPLICATION PROGRAM NAME:  D30ACBA1.C of D30SCB01                   */
  4. /*                                                                         */
  5. /*  PROGRAM LANGUAGE: 'C' Language                                         */
  6. /*                                                                         */
  7. /*  PROGRAM DESCRIPTION:                                                   */
  8. /*            D30ACBA1 is the first program in the D30SCB01 application.   */
  9. /*            This program will create the BANK data base.  The data base  */
  10. /*            will have the following attributes:                          */
  11. /*                                                                         */
  12. /*              - Data base has a comment                                  */
  13. /*                                                                         */
  14. /*  AUTHOR:   D.J.Grant                      DATE: 04/22/87                */
  15. /*                                                                         */
  16. /*  DATABASE:                                                              */
  17. /*            OS/2 EE DBM BANK DATABASE                                    */
  18. /*                                                                         */
  19. /*  INPUT FILES:  D30SCB01.INP - drive letter on which database will be    */
  20. /*                created.                                                 */
  21. /*                                                                         */
  22. /*  OUTPUT FILES:                                                          */
  23. /*            D30ACBA1.ERR - this is a file, written to disk, only when    */
  24. /*            some unexpected error condition is returned from SQL.  It    */
  25. /*            serves as an error log, recording the error code, its cor-   */
  26. /*            responding error message, and any other useful information   */
  27. /*            which the program might be able to give.                     */
  28. /*                                                                         */
  29. /*  DEPENDENCIES:                                                          */
  30. /*            OS/2 EE DBM ,                                                */
  31. /*            compilation with IBM C/2, using compiler options:            */
  32. /*                     "/AL /Gs /DLINT_ARGS /DSQL_REL_10 /W3 /Od /FPa"     */
  33. /*                                                                         */
  34. /*  FUNCTION CALLS:                                                        */
  35. /*            COMPILER LIBRARY                                             */
  36. /*                 stdio.h - fopen,fclose,fgets,fprintf                    */
  37. /*                 string.h - strcpy                                       */
  38. /*                                                                         */
  39. /*            SHELBY 3 LIBRARY                                             */
  40. /*                 sql.h    - sqlaintp                                     */
  41. /*                 sqlca.h  - sqlca                                        */
  42. /*                 sqlenv.h - sqlecred, sqledrpd                           */
  43. /*                                                                         */
  44. /*            OTHER                                                        */
  45. /*                 none                                                    */
  46. /*                                                                         */
  47. /********************************************  (Prolog continued next page)*/
  48.  
  49. /** (Prolog continued) ******************       ***************/
  50. /*                                                                         */
  51. /*  ERROR CONDITIONS:                                                      */
  52. /*                                                                         */
  53. /*            NORMAL - specifically tested for and handled by the          */
  54. /*                     application program:  (exit_normal)                 */
  55. /*                                                                         */
  56. /*                     OS/2(errorlvl)   return code = 0                    */
  57. /*                                                                         */
  58. /*            ABNORMAL - unexpected and resulting in program termination:  */
  59. /*                       (exit_error)                                      */
  60. /*                                                                         */
  61. /*                     OS/2(errorlvl)   return code = 2                    */
  62. /*  MODIFICATIONS:                                                         */
  63. /*            Date      Author         Description                         */
  64. /*                                                                         */
  65. /*           09/14/87   D.J. Grant     - changed all internal program name */
  66. /*                                         references to match new naming  */
  67. /*                                         conventions.                    */
  68. /*                                     - added the sqlenv.h functional call*/
  69. /*                                     - changed references of &MYSQLCA to */
  70. /*                                         sqlca (now in lowercase also).  */
  71. /*                                     - added code to allow return codes  */
  72. /*                                         to be passed back to DOS.       */
  73. /*                                     - added     to each    */
  74. /*                                         page.                           */
  75. /*                                     - initialized rc to 0.              */
  76. /*                                     - added more comments to program.   */
  77. /*                                                                         */
  78. /*           10/05/87   D.J. Grant     - added rte_label to mark progress. */
  79. /*                                     - removed memory.h include.         */
  80. /*                                     - removed OUTRECLEN variable process*/
  81. /*                                     - revised sqlaintp rc to read >0    */
  82. /*                                         instead of != 0.                */
  83. /*                                                                         */
  84. /*           02/29/88   D. J. Grant    - added the database drive parameter*/
  85. /*                                                                         */
  86. /*           02/03/89   W. B. Brown    - upgraded to run on release 3.0    */
  87. /*                                       specifically, changed 'G20...'    */
  88. /*                                       to 'D30...' and added drive input */
  89. /*                                       file.                             */
  90. /*                                                                         */
  91. /*** (END OF PROLOG) *******************************************************/
  92.  
  93. /****************************************       *****************/
  94. /*****************************************************************************/
  95. /*  SET UP INCLUDES                                                          */
  96. /*****************************************************************************/
  97. #include <stdio.h>
  98. #include <string.h>
  99. #include <sql.h>
  100. #include <sqlca.h>
  101. #include <sqlenv.h>
  102.  
  103. /*****************************************************************************/
  104. /*  DEFINITIONS AND DECLARATIONS                                             */
  105. /*****************************************************************************/
  106. /* Set up SQLCA for this program */
  107. /*********************************/
  108.  
  109.         struct sqlca sqlca;                       /* declare sqlca           */
  110.  
  111. /******************************/
  112. /*  define error msg buffer   */
  113. /******************************/
  114.  
  115.         unsigned char msgbuf[512];
  116.  
  117. /***************************************************/
  118. /* Declarations for create data base function call */
  119. /***************************************************/
  120.  
  121.         unsigned char  database[]="bank";  /* establish database name        */
  122.         unsigned char  password[]="";      /* set up null password           */
  123.         unsigned char  dcomment[]="BANK data base - 7 tables";  /*  comment  */
  124.  
  125.                 short  codepage  = 0;      /* set up zero for codepage       */
  126.         unsigned char  drive     ='\0';     /* use default drive for db      */
  127.         unsigned char drv ='\0';            /* unless parm is entered        */
  128.         unsigned char inputfle[]="D30SCB01.INP";  /* DB    DRIVE FILE        */
  129. /********************************************/
  130. /* Declarations for D30ACBA1.ERR error file */
  131. /********************************************/
  132.  
  133.         unsigned char  errorfle[]="D30ACBA1.ERR";  /* error file description */
  134.         unsigned char   tcaseid[]="Test Case Id : D30ACBA1.C";
  135.         unsigned char  descript[]=
  136.                        "Create BANK data base ";
  137.  
  138. /***********************************************/
  139. /* Set up variable to pass return codes to DOS */
  140. /***********************************************/
  141.  
  142.         short errorlvl = 0;            /* variable used to pass return codes */
  143.                                        /*   to DOS                           */
  144.  
  145. /****************************************       *****************/
  146.  
  147. int  main (void);
  148.      main ()
  149. {
  150.  
  151. /* declare local program variables */
  152.  
  153.    unsigned char rte_label[16];                  /* program progress marker  */
  154.    short rc = 0;                                 /* variable for return code */
  155.    FILE *ptr_output;                             /* declare output file      */
  156.    FILE *ptr_input;                              /* declare input file       */
  157.  
  158. /*****************************************************************************/
  159. /*  Issue a drop for the BANK database - unconditionally; continue on error. */
  160. /*****************************************************************************/
  161.    strcpy(rte_label,"drop  database ");
  162.                                              /* drop the BANK database if it */
  163.    sqledrpd (database,password,&sqlca);      /* exists, otherwise go ahead   */
  164.                                              /* and create it                */
  165.  
  166. /*****************************************************************************/
  167. /*  Read input file D30SCB01.INP to get drive letter on which database will  */
  168. /*  be created.                                                              */
  169. /*****************************************************************************/
  170.  
  171.     if ((ptr_input = fopen(inputfle,"r")) == NULL)    /* open the input file*/
  172.        {
  173.  
  174.         printf ("\nUNABLE TO OPEN D30SCB01.INP");      /* display on screen  */
  175.         printf ("\nDATABASE WILL BE CREATED ON DEFAULT DRIVE");
  176.         goto create_db;
  177.  
  178.         }
  179.  
  180.       drv = fgetc(ptr_input);
  181.       drive = drv;
  182.  
  183. /*****************************************************************************/
  184. /*  Create BANK data base:  No password, default drive, with comment         */
  185. /*****************************************************************************/
  186.   create_db:
  187.  
  188.    strcpy(rte_label,"create database");
  189.  
  190.    sqlecred (database,drive,password,dcomment,codepage,&sqlca);
  191.  
  192.         rc = sqlaintp (msgbuf,512,0,&sqlca);
  193.  
  194.         if (rc > 0)
  195.         {
  196.         goto exit_error;                  /* exit on error */
  197.         }
  198.  
  199.    goto exit_normal;                      /* exit program - normally */
  200.  
  201.  
  202. /****************************************       *****************/
  203. /*****************************************************************************/
  204. /**  EXIT_ERROR ROUTINE                                                      */
  205. /*****************************************************************************/
  206. exit_error:
  207.  
  208.     if ((ptr_output = fopen(errorfle,"w")) == NULL)    /* open the error file*/
  209.     {
  210.  
  211.         printf ("\nUNABLE TO OPEN D30ACBA1.ERR");      /* display on screen  */
  212.         printf ("\nSQLCODE IS %ld",sqlca.sqlcode);
  213.         goto exit_normal;
  214.  
  215.     }
  216.  
  217.                                               /* print error information     */
  218.         fprintf (ptr_output,"%s\n%s\n",tcaseid,descript);
  219.         fprintf (ptr_output,"%s\n",rte_label);
  220.         fprintf (ptr_output,msgbuf);
  221.         fprintf (ptr_output,"\nSQLCODE is %ld.\n",sqlca.sqlcode);
  222.  
  223.         fclose(ptr_output);                    /* close the output file      */
  224.  
  225.         errorlvl = 2;                          /* set return code - 2 (error)*/
  226.  
  227. /*****************************************************************************/
  228. /**  EXIT_NORMAL ROUTINE                                                     */
  229. /*****************************************************************************/
  230. exit_normal:
  231.  
  232.         return (errorlvl);                        /* return error level code */
  233.  }
  234.