home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a524 / 42.ddi / demo / samplec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-04  |  17.5 KB  |  640 lines

  1. #ifdef RCSID
  2. static char *RCSid = 
  3.    "$Header: samplec.pc,v 6.0 88/06/16 19:25:58 rchoplin Exp $ samplec.pc Copyr (c) 1986 Oracle";
  4. #endif /* RCSID */
  5.  
  6. /*
  7.  * $Date: 88/06/16 19:25:58 $ $Revision: 6.0 $ samplec.pc Copyr (c) 1986 Oracle
  8.  */
  9.  
  10. /* VOID sample
  11.  
  12.    sample  is a simple example program which adds new employee
  13.            records to the personnel data base.  Checking
  14.            is done to insure the integrity of the data base.
  15.            The employee numbers are automatically selected using
  16.            the current maximum employee number + 10.
  17.  
  18.            The program queries the user for data as follows:
  19.  
  20.            Enter employee name:
  21.            Enter employee job:
  22.            Enter employee salary:
  23.            Enter employee dept:
  24.  
  25.            The program terminates if EOF (end of file) or a null
  26.            string (<return> key) is entered when the employee name
  27.            is requested.
  28.  
  29.            If the record is successfully inserted, the following
  30.            is printed:
  31.  
  32.            ename added to department dname as employee # nnnnnn
  33.  
  34.            To build and run SAMPLE (assumes that SQLCA file is in "SQLCA.H"):
  35.  
  36.                $ pcc iname=samplec.pc prog=xxx$sample userid=scott/tiger
  37.                $ cc -O -c samplec.c
  38.                $ cc -o samplec samplec.o -lsql -lhlic -lhli
  39.                $ samplec
  40.  
  41.           where "xxx" is your logon id. E.g.:
  42.  
  43.                $ pcc iname=samplec prog=oracle$sample userid=scott/tiger
  44.  
  45.           The idea here is to pick a unique name for the program, so that
  46.           anyone precompiling pgms into "scott/tiger" will have unique names
  47.           for their pgms (e.g., if I have a prog=sample userid=scott/tiger;
  48.           and you have a prog=sample userid=scott/tiger, then we have a
  49.           conflict...).
  50. */
  51. #include <stdio.h>
  52. #include <ctype.h>
  53.  
  54. /* SQL stmt #1
  55. EXEC SQL BEGIN DECLARE SECTION;
  56. VARCHAR uid[20];
  57. */
  58. struct {
  59.   unsigned short len;
  60.   unsigned char arr[20];
  61.   } uid;
  62. /*
  63.                                        /o username                            o/
  64. VARCHAR pwd[20];
  65. */
  66. struct {
  67.   unsigned short len;
  68.   unsigned char arr[20];
  69.   } pwd;
  70. /*
  71.                                        /o password                            o/
  72.  
  73. */
  74. int     empno;                         /* employee number                     */
  75. /*
  76. VARCHAR ename[15];
  77. */
  78. struct {
  79.   unsigned short len;
  80.   unsigned char arr[15];
  81.   } ename;
  82. /*
  83.                                        /o employee name                       o/
  84. */
  85. int     deptno;                        /* department number                   */
  86. /*
  87. VARCHAR dname[15];
  88. */
  89. struct {
  90.   unsigned short len;
  91.   unsigned char arr[15];
  92.   } dname;
  93. /*
  94.                                        /o department name                     o/
  95.  
  96. VARCHAR job[15];
  97. */
  98. struct {
  99.   unsigned short len;
  100.   unsigned char arr[15];
  101.   } job;
  102. /*
  103.                                        /o employee job                        o/
  104. */
  105. int     sal;                           /* employee salary                     */
  106. /* SQL stmt #2
  107. EXEC SQL END DECLARE SECTION;
  108. */
  109. static struct {
  110. unsigned long   sq001N;
  111. unsigned char  *sq001V[4];
  112. unsigned long   sq001L[4];
  113. unsigned short  sq001T[4];
  114. unsigned short *sq001I[4];
  115. } sq001 = {4};
  116. static struct {
  117. unsigned long   sq002N;
  118. unsigned char  *sq002V[1];
  119. unsigned long   sq002L[1];
  120. unsigned short  sq002T[1];
  121. unsigned short *sq002I[1];
  122. } sq002 = {1};
  123. static char sq003[45] =
  124. "SELECT NVL(MAX(EMPNO),0)+10 INTO:b1 FROM EMP"
  125. ;
  126. static struct {
  127. unsigned long   sq004N;
  128. unsigned char  *sq004V[1];
  129. unsigned long   sq004L[1];
  130. unsigned short  sq004T[1];
  131. unsigned short *sq004I[1];
  132. } sq004 = {1};
  133. static struct {
  134. unsigned long   sq005N;
  135. unsigned char  *sq005V[1];
  136. unsigned long   sq005L[1];
  137. unsigned short  sq005T[1];
  138. unsigned short *sq005I[1];
  139. } sq005 = {1};
  140. static char sq006[48] =
  141. "SELECT DNAME INTO:b1 FROM DEPT WHERE DEPTNO=:b2"
  142. ;
  143. static struct {
  144. unsigned long   sq007N;
  145. unsigned char  *sq007V[1];
  146. unsigned long   sq007L[1];
  147. unsigned short  sq007T[1];
  148. unsigned short *sq007I[1];
  149. } sq007 = {1};
  150. static struct {
  151. unsigned long   sq008N;
  152. unsigned char  *sq008V[1];
  153. unsigned long   sq008L[1];
  154. unsigned short  sq008T[1];
  155. unsigned short *sq008I[1];
  156. } sq008 = {1};
  157. static struct {
  158. unsigned long   sq009N;
  159. unsigned char  *sq009V[1];
  160. unsigned long   sq009L[1];
  161. unsigned short  sq009T[1];
  162. unsigned short *sq009I[1];
  163. } sq009 = {1};
  164. static char sq010[71] =
  165. "INSERT INTO EMP(EMPNO,ENAME,JOB,SAL,DEPTNO)VALUES(:b1,:b2,:b3,:b4,:b5)"
  166. ;
  167. static struct {
  168. unsigned long   sq011N;
  169. unsigned char  *sq011V[5];
  170. unsigned long   sq011L[5];
  171. unsigned short  sq011T[5];
  172. unsigned short *sq011I[5];
  173. } sq011 = {5};
  174. static struct {
  175. unsigned long   sq012N;
  176. unsigned char  *sq012V[1];
  177. unsigned long   sq012L[1];
  178. unsigned short  sq012T[1];
  179. unsigned short *sq012I[1];
  180. } sq012 = {1};
  181. static struct {
  182. unsigned long   sq013N;
  183. unsigned char  *sq013V[1];
  184. unsigned long   sq013L[1];
  185. unsigned short  sq013T[1];
  186. unsigned short *sq013I[1];
  187. } sq013 = {1};
  188. static int SQLTM[8];
  189. static int sqlcun[3] = {
  190. 0,0,0};
  191. static int sqlusi[1] = {
  192. 0};
  193. static unsigned long sqlami = 0;
  194. static int SQLBT0 = 1;
  195. static int SQLBT1 = 2;
  196. static int SQLBT2 = 4;
  197. static int SQLBT3 = 9;
  198. static unsigned long sqlvsn = 10315;
  199. static int IAPSUCC = 0;
  200. static int IAPFAIL = 1403;
  201. static int IAPFTL  = 535;
  202. extern  void  sqlab2();
  203. extern  void  sqlad2();
  204. extern  void  sqlbs2();
  205. extern  void  sqlcom();
  206. extern  void  sqlexe();
  207. extern  void  sqlfch();
  208. extern  void  sqliem();
  209. extern  void  sqllo2();
  210. extern  void  sqlopn();
  211. extern  void  sqlosq();
  212. extern  void  sqlrol();
  213. extern  void  sqlsca();
  214. extern  void  sqlscc();
  215. extern  void  sqlsch();
  216. extern  void  sqltfl();
  217. /* SQL stmt #3
  218. EXEC SQL INCLUDE sqlca.h;
  219. */
  220. /*
  221.  * $Header: sqlca.h,v 10301.3 89/02/22 11:07:56 nsalah Exp $ sqlca.h Copyr (c) 1987 Oracle
  222.  */
  223.  
  224. /* v1pcc,10301,v1pcc$src:[defs.10301] */
  225. /* Copyright (c) 1985,1986 by Oracle Corporation. */
  226.  
  227. /*
  228. NAME
  229.   SQLCA : SQL Communications Area.
  230. FUNCTION
  231.   Contains no code. Oracle fills in the SQLCA with status info
  232.   during the execution of a SQL stmt.
  233. NOTES
  234.   If the symbol SQLCA_STORAGE_CLASS is defined, then the SQLCA
  235.   will be defined to have this storage class. For example:
  236.  
  237.     #define SQLCA_STORAGE_CLASS extern
  238.  
  239.   will define the SQLCA as an extern.
  240.  
  241.   If the symbol SQLCA_INIT is defined, then the SQLCA will be
  242.   statically initialized. Although this is not necessary in order
  243.   to use the SQLCA, it is a good pgming practice not to have
  244.   unitialized variables. However, some C compilers/OS's don't
  245.   allow automatic variables to be init'd in this manner. Therefore,
  246.   if you are INCLUDE'ing the SQLCA in a place where it would be
  247.   an automatic AND your C compiler/OS doesn't allow this style
  248.   of initialization, then SQLCA_INIT should be left undefined --
  249.   all others can define SQLCA_INIT if they wish.
  250.  
  251. MODIFIED
  252.   Clare      12/06/84 - Ch SQLCA to not be an extern.
  253.   Clare      10/21/85 - Add initialization.
  254.   Bradbury   01/05/86 - Only initialize when SQLCA_INIT set
  255.   Clare      06/12/86 - Add SQLCA_STORAGE_CLASS option.
  256. */
  257.  
  258. #ifndef SQLCA
  259. #define SQLCA 1
  260.  
  261. struct   sqlca
  262.          {
  263.          /* ub1 */ char    sqlcaid[8];
  264.          /* b4  */ long    sqlabc;
  265.          /* b4  */ long    sqlcode;
  266.          struct
  267.            {
  268.            /* ub2 */ unsigned short sqlerrml;
  269.            /* ub1 */ char           sqlerrmc[70];
  270.            } sqlerrm;
  271.          /* ub1 */ char    sqlerrp[8];
  272.          /* b4  */ long    sqlerrd[6];
  273.          /* ub1 */ char    sqlwarn[8];
  274.          /* ub1 */ char    sqlext[8];
  275.          };
  276.  
  277. #ifdef   SQLCA_STORAGE_CLASS
  278. SQLCA_STORAGE_CLASS struct sqlca sqlca
  279. #else
  280.          struct sqlca sqlca
  281. #endif
  282.  
  283. #ifdef  SQLCA_INIT
  284.          = {
  285.          {'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '},
  286.          sizeof(struct sqlca),
  287.          0,
  288.          { 0, {0}},
  289.          {'N', 'O', 'T', ' ', 'S', 'E', 'T', ' '},
  290.          {0, 0, 0, 0, 0, 0},
  291.          {0, 0, 0, 0, 0, 0, 0, 0},
  292.          {0, 0, 0, 0, 0, 0, 0, 0}
  293.          }
  294. #endif
  295.          ;
  296.  
  297. #endif
  298.  
  299. /* end SQLCA */
  300.  
  301. main()
  302. {
  303.  
  304. /* -----------------------------------------------------------------------------
  305.    logon to ORACLE, and open the cursors. The program exits if any errors occur.
  306. ----------------------------------------------------------------------------- */
  307.  
  308.    strcpy(uid.arr,"SCOTT");
  309.    uid.len = strlen(uid.arr);
  310.    strcpy(pwd.arr,"TIGER");
  311.    pwd.len = strlen(pwd.arr);
  312.  
  313. /* SQL stmt #4
  314.    EXEC SQL WHENEVER SQLERROR GOTO errexit;
  315.    EXEC SQL CONNECT :uid IDENTIFIED BY :pwd;
  316. */
  317. {     /* beginning of SQL code gen stmt */
  318. sqlsca(&sqlca);
  319. sq001.sq001V[0] = (unsigned char *)&uid.len;
  320. sq001.sq001L[0] = (unsigned long)22;
  321. sq001.sq001T[0] = (unsigned short)9;
  322. sq001.sq001I[0] = (unsigned short *)0;
  323. sq001.sq001V[1] = (unsigned char *)&pwd.len;
  324. sq001.sq001L[1] = (unsigned long)22;
  325. sq001.sq001T[1] = (unsigned short)9;
  326. sq001.sq001I[1] = (unsigned short *)0;
  327. sq001.sq001T[2] = (unsigned short)10;
  328. sq001.sq001T[3] = (unsigned short)10;
  329. SQLTM[0] = (int)0;
  330. SQLTM[1] = (int)10;
  331. sqllo2(
  332.   &sq001.sq001N,sq001.sq001V,sq001.sq001L,sq001.sq001T,
  333.   &sqlami, &SQLTM[0], &SQLTM[1], &sqlvsn);
  334. if (sqlca.sqlcode < 0)  goto errexit;
  335. }   /* ending of SQL code gen stmt */
  336.  
  337. /* -----------------------------------------------------------------------------
  338.    Retrieve the current maximum employee number
  339. ----------------------------------------------------------------------------- */
  340.  
  341. /* SQL stmt #6
  342.    EXEC SQL SELECT NVL(MAX(EMPNO),0) + 10
  343.               INTO :empno
  344.               FROM EMP;
  345. */
  346. {     /* beginning of SQL code gen stmt */
  347. sqlsca(&sqlca);
  348. if ( !sqlusi[0] )
  349.   {  /* OPEN SCOPE */
  350. sq002.sq002T[0] = (unsigned short)10;
  351. SQLTM[0] = (int)4;
  352. sqlbs2(&sq002.sq002N, sq002.sq002V,
  353.   sq002.sq002L, sq002.sq002T, sq002.sq002I,
  354.   &SQLTM[0], &sqlusi[0]);
  355.   }  /* CLOSE SCOPE */
  356. sqlsch(&sqlusi[0]);
  357. sqlscc(&sqlcun[0]);
  358. sqltfl(&SQLTM[0], &SQLBT0);
  359. if ( !SQLTM[0] )
  360.   {  /* OPEN SCOPE */
  361. SQLTM[0] = (int)16384;
  362. sqlopn(&SQLTM[0], &SQLBT3, &sqlvsn);
  363. SQLTM[0] = (int)44;
  364. sqlosq(sq003, &SQLTM[0]);
  365. sq004.sq004V[0] = (unsigned char *)&empno;
  366. sq004.sq004L[0] = (unsigned long)4;
  367. sq004.sq004T[0] = (unsigned short)3;
  368. sq004.sq004I[0] = (unsigned short *)0;
  369. sqlad2(&sq004.sq004N, sq004.sq004V,
  370.   sq004.sq004L, sq004.sq004T, sq004.sq004I);
  371.   }  /* CLOSE SCOPE */
  372. SQLTM[0] = (int)1;
  373. sqlexe(&SQLTM[0]);
  374. SQLTM[0] = (int)1;
  375. SQLTM[1] = (int)0;
  376. sqlfch(&SQLTM[0], &SQLTM[1]);
  377. if (sqlca.sqlcode < 0)  goto errexit;
  378. }   /* ending of SQL code gen stmt */
  379.  
  380. /* -----------------------------------------------------------------------------
  381.    read the user's input from STDIN.  If the employee name is
  382.    not entered, exit.
  383.    Verify that the entered department number is valid and echo the
  384.    department's name
  385. ----------------------------------------------------------------------------- */
  386.  
  387.    for( ; ; empno+=10 )
  388.      {
  389.      int l;
  390.  
  391.      /* Get employee name to be inserted.
  392.  
  393.         IMPORTANT NOTE: beware of coding as follows (I got burnt, 1st time):
  394.  
  395.           ename.len = asks("Enter employee name  : ", ename.arr);
  396.           if ( ename.len <= 0 )
  397.             ..etc..
  398.  
  399.         In the above, asks() returns an int, but ename.len is an unsigned
  400.         short (see SQLCA). Therefore, the "if" fails for <EOF> (which returns
  401.         -1) because, by definition, the unsigned short can't be negative.
  402.      */
  403.      l = asks("Enter employee name  : ",ename.arr);
  404.  
  405.      if ( l <= 0 )
  406.        break;
  407.  
  408.      ename.len = l;
  409.  
  410.      job.len = asks("Enter employee job   : ",job.arr);
  411.      askn("Enter employee salary: ",&sal);
  412.      for ( ; ; )
  413.        {
  414.        if ( askn("Enter employee dept  :   ",&deptno) < 0 )
  415.          break;
  416.  
  417. /* SQL stmt #7
  418.        EXEC SQL WHENEVER NOT FOUND GOTO nodept;
  419.        EXEC SQL SELECT DNAME
  420.                   INTO :dname
  421.                   FROM DEPT
  422.                   WHERE DEPTNO = :deptno;
  423. */
  424. {     /* beginning of SQL code gen stmt */
  425. sqlsca(&sqlca);
  426. if ( !sqlusi[0] )
  427.   {  /* OPEN SCOPE */
  428. sq005.sq005T[0] = (unsigned short)10;
  429. SQLTM[0] = (int)4;
  430. sqlbs2(&sq005.sq005N, sq005.sq005V,
  431.   sq005.sq005L, sq005.sq005T, sq005.sq005I,
  432.   &SQLTM[0], &sqlusi[0]);
  433.   }  /* CLOSE SCOPE */
  434. sqlsch(&sqlusi[0]);
  435. sqlscc(&sqlcun[1]);
  436. sqltfl(&SQLTM[0], &SQLBT0);
  437. if ( !SQLTM[0] )
  438.   {  /* OPEN SCOPE */
  439. SQLTM[0] = (int)16384;
  440. sqlopn(&SQLTM[0], &SQLBT3, &sqlvsn);
  441. SQLTM[0] = (int)47;
  442. sqlosq(sq006, &SQLTM[0]);
  443. sq007.sq007V[0] = (unsigned char *)&deptno;
  444. sq007.sq007L[0] = (unsigned long)4;
  445. sq007.sq007T[0] = (unsigned short)3;
  446. sq007.sq007I[0] = (unsigned short *)0;
  447. sqlab2(&sq007.sq007N, sq007.sq007V,
  448.   sq007.sq007L, sq007.sq007T, sq007.sq007I);
  449. sq008.sq008V[0] = (unsigned char *)&dname.len;
  450. sq008.sq008L[0] = (unsigned long)17;
  451. sq008.sq008T[0] = (unsigned short)9;
  452. sq008.sq008I[0] = (unsigned short *)0;
  453. sqlad2(&sq008.sq008N, sq008.sq008V,
  454.   sq008.sq008L, sq008.sq008T, sq008.sq008I);
  455.   }  /* CLOSE SCOPE */
  456. SQLTM[0] = (int)1;
  457. sqlexe(&SQLTM[0]);
  458. SQLTM[0] = (int)1;
  459. SQLTM[1] = (int)0;
  460. sqlfch(&SQLTM[0], &SQLTM[1]);
  461. if (sqlca.sqlcode == 1403)  goto nodept;
  462. if (sqlca.sqlcode < 0)  goto errexit;
  463. }   /* ending of SQL code gen stmt */
  464.  
  465.        dname.arr[dname.len] = '\0';
  466.  
  467. /* SQL stmt #9
  468.        EXEC SQL WHENEVER NOT FOUND STOP;
  469. */
  470.  
  471.        /* Here if deptno was found in dbs. Insert new employee into dbs. */
  472.  
  473. /* SQL stmt #10
  474.        EXEC SQL INSERT INTO EMP(EMPNO,ENAME,JOB,SAL,DEPTNO)
  475.                   VALUES (:empno,:ename,:job,:sal,:deptno);
  476. */
  477. {     /* beginning of SQL code gen stmt */
  478. sqlsca(&sqlca);
  479. if ( !sqlusi[0] )
  480.   {  /* OPEN SCOPE */
  481. sq009.sq009T[0] = (unsigned short)10;
  482. SQLTM[0] = (int)4;
  483. sqlbs2(&sq009.sq009N, sq009.sq009V,
  484.   sq009.sq009L, sq009.sq009T, sq009.sq009I,
  485.   &SQLTM[0], &sqlusi[0]);
  486.   }  /* CLOSE SCOPE */
  487. sqlsch(&sqlusi[0]);
  488. sqlscc(&sqlcun[2]);
  489. sqltfl(&SQLTM[0], &SQLBT0);
  490. if ( !SQLTM[0] )
  491.   {  /* OPEN SCOPE */
  492. SQLTM[0] = (int)16384;
  493. sqlopn(&SQLTM[0], &SQLBT3, &sqlvsn);
  494. SQLTM[0] = (int)70;
  495. sqlosq(sq010, &SQLTM[0]);
  496. sq011.sq011V[0] = (unsigned char *)&empno;
  497. sq011.sq011L[0] = (unsigned long)4;
  498. sq011.sq011T[0] = (unsigned short)3;
  499. sq011.sq011I[0] = (unsigned short *)0;
  500. sq011.sq011V[1] = (unsigned char *)&ename.len;
  501. sq011.sq011L[1] = (unsigned long)17;
  502. sq011.sq011T[1] = (unsigned short)9;
  503. sq011.sq011I[1] = (unsigned short *)0;
  504. sq011.sq011V[2] = (unsigned char *)&job.len;
  505. sq011.sq011L[2] = (unsigned long)17;
  506. sq011.sq011T[2] = (unsigned short)9;
  507. sq011.sq011I[2] = (unsigned short *)0;
  508. sq011.sq011V[3] = (unsigned char *)&sal;
  509. sq011.sq011L[3] = (unsigned long)4;
  510. sq011.sq011T[3] = (unsigned short)3;
  511. sq011.sq011I[3] = (unsigned short *)0;
  512. sq011.sq011V[4] = (unsigned char *)&deptno;
  513. sq011.sq011L[4] = (unsigned long)4;
  514. sq011.sq011T[4] = (unsigned short)3;
  515. sq011.sq011I[4] = (unsigned short *)0;
  516. sqlab2(&sq011.sq011N, sq011.sq011V,
  517.   sq011.sq011L, sq011.sq011T, sq011.sq011I);
  518.   }  /* CLOSE SCOPE */
  519. SQLTM[0] = (int)1;
  520. sqlexe(&SQLTM[0]);
  521. if (sqlca.sqlcode < 0)  goto errexit;
  522. }   /* ending of SQL code gen stmt */
  523.  
  524.        printf("\n%s added to the %s department as employee number %d\n",
  525.          ename.arr,dname.arr,empno);
  526.        break;
  527.  
  528.        /* Here if deptno NOT found in dbs */
  529.        nodept:
  530.          printf("\nNo such department\n");
  531.          continue;
  532.        }
  533.      }
  534.  
  535. /* -----------------------------------------------------------------------------
  536.    close the cursors and log off from ORACLE
  537. ----------------------------------------------------------------------------- */
  538.  
  539. /* SQL stmt #11
  540.    EXEC SQL COMMIT WORK RELEASE;
  541. */
  542. {     /* beginning of SQL code gen stmt */
  543. sqlsca(&sqlca);
  544. if ( !sqlusi[0] )
  545.   {  /* OPEN SCOPE */
  546. sq012.sq012T[0] = (unsigned short)10;
  547. SQLTM[0] = (int)4;
  548. sqlbs2(&sq012.sq012N, sq012.sq012V,
  549.   sq012.sq012L, sq012.sq012T, sq012.sq012I,
  550.   &SQLTM[0], &sqlusi[0]);
  551.   }  /* CLOSE SCOPE */
  552. sqlsch(&sqlusi[0]);
  553. SQLTM[0] = (int)1;
  554. sqlcom(&SQLTM[0]);
  555. if (sqlca.sqlcode < 0)  goto errexit;
  556. }   /* ending of SQL code gen stmt */
  557.    printf ("\nEnd of the C/ORACLE example program.\n");
  558.    return(1);
  559.  
  560. errexit:
  561.    errrpt();
  562. /* SQL stmt #12
  563.    EXEC SQL WHENEVER SQLERROR CONTINUE;
  564.    EXEC SQL ROLLBACK WORK RELEASE;
  565. */
  566. {     /* beginning of SQL code gen stmt */
  567. sqlsca(&sqlca);
  568. if ( !sqlusi[0] )
  569.   {  /* OPEN SCOPE */
  570. sq013.sq013T[0] = (unsigned short)10;
  571. SQLTM[0] = (int)4;
  572. sqlbs2(&sq013.sq013N, sq013.sq013V,
  573.   sq013.sq013L, sq013.sq013T, sq013.sq013I,
  574.   &SQLTM[0], &sqlusi[0]);
  575.   }  /* CLOSE SCOPE */
  576. sqlsch(&sqlusi[0]);
  577. SQLTM[0] = (int)1;
  578. sqlrol(&SQLTM[0]);
  579. }   /* ending of SQL code gen stmt */
  580.    return(0);
  581. }
  582.  
  583. /*------------------------------------------------------------------------------
  584. COUNT askn(text,variable)
  585.  
  586.    print the 'text' on STDOUT and read an integer variable from
  587.    SDTIN.
  588.  
  589.    text points to the null terminated string to be printed
  590.    variable points to an integer variable
  591.  
  592.    askn returns a 1 if the variable was read successfully or a
  593.        -1 if -eof- was encountered
  594. ----------------------------------------------------------------------------- */
  595.  
  596. int askn(text,variable)
  597.    char text[];
  598.    int  *variable;
  599.    {
  600.    char s[20];
  601.    printf(text);
  602.    if ( gets(s) == (char *)0 )
  603.      return(EOF);
  604.  
  605.    *variable = atoi(s);
  606.    return(1);
  607.    }
  608.  
  609. /* -----------------------------------------------------------------------------
  610. COUNT asks(text,variable)
  611.  
  612.    print the 'text' on STDOUT and read up to 'len' characters into
  613.    the buffer pointed to by variable from STDIN.
  614.  
  615.    text points to the null terminated string to be printed
  616.    variable points to a buffer of at least 'len'+1 characters
  617.  
  618.    asks returns the number of character read into the string, or a
  619.        -1 if -eof- was encountered
  620. ----------------------------------------------------------------------------- */
  621.  
  622. int asks(text,variable)
  623.    char text[],variable[];
  624.    {
  625.    printf(text);
  626.    return( gets(variable) == (char *)0 ? EOF : strlen(variable) );
  627.    }
  628.  
  629. /* -----------------------------------------------------------------------------
  630. VOID errrpt()
  631.  
  632.    errrpt prints the ORACLE error msg and number.
  633. ----------------------------------------------------------------------------- */
  634.  
  635. errrpt()
  636.    {
  637.    printf("\n%.70s (%d)\n", sqlca.sqlerrm.sqlerrmc, -sqlca.sqlcode);
  638.    return(0);
  639.    }
  640.