home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0210 - 0219 / ibm0210-0219 / ibm0213.tar / ibm0213 / 7025PWA1.ZIP / SAMPLES.ZIP / SQLLIB / SAMPLES / C / BLKCLI.SQC < prev    next >
Encoding:
Text File  |  1994-02-28  |  1.8 KB  |  62 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sqlenv.h> /* :rk.1:erk. */
  5. #include <sql.h>
  6. #include "block.h"
  7. #include <sqlca.h>
  8. #include <sqlda.h>
  9.  
  10. int main(void) {
  11.   struct sqlda sqldaIn;
  12.   struct sqlca sqlca;
  13.   struct persons person;
  14.   int rc = 0;
  15.  
  16.   printf("\nCONNECT TO Database");
  17.   EXEC SQL CONNECT TO sample IN SHARE MODE;
  18.   printf("\nSQLCODE is %d\n", SQLCODE);
  19.  
  20.   if (SQLCODE == 0L) {
  21.       strcpy(person.employees[0].name,"Elmer"); /* :rk.2:erk. */
  22.       person.employees[0].id = 500;
  23.       strcpy(person.employees[1].name,"Astro");
  24.       person.employees[1].id = 510;
  25.       strcpy(person.employees[2].name,"Calvin");
  26.       person.employees[2].id = 520;
  27.       strcpy(person.employees[3].name,"Wilma");
  28.       person.employees[3].id = 530;
  29.  
  30.       person.number_of_records = 4; /* :rk.3:erk. */
  31.  
  32.       person.len = sizeof(person.number_of_records) + /* :rk.4:erk. */
  33.                   (sizeof(struct employee) * person.number_of_records);
  34.  
  35.       sqldaIn.sqln = 1;
  36.       sqldaIn.sqld = 1;
  37.       sqldaIn.sqlvar[0].sqltype = SQL_TYP_VARCHAR;
  38.       sqldaIn.sqlvar[0].sqldata = (char*)&person; /* :rk.5:erk. */
  39.       sqldaIn.sqlvar[0].sqllen = person.len;
  40.       sqldaIn.sqlvar[0].sqlind = NULL;
  41.  
  42.       rc = sqleproc("BLKSRV.DLL\\ADD_EMPLOYEES", NULL, &sqldaIn, /* :rk.6:erk. */
  43.                                              NULL, &sqlca);
  44.       printf ("\n Sqlcode from sqleproc call is %d", sqlca.sqlcode);
  45.  
  46.       if (sqlca.sqlcode != 0) rc = err(&sqlca);
  47.       EXEC SQL CONNECT RESET;
  48.   }
  49.   return(rc);
  50. }
  51.  
  52. int err( struct sqlca * ca ) {
  53.    char buf[512] = " ";
  54.    int rc = 0;
  55.    rc = sqlaintp( buf, 512, 78, ca );
  56.    if ( rc != SQLA_ERR_NOMSG )
  57.       printf("\n %ld %s", ca->sqlcode, buf);
  58.    else
  59.       printf("\n Error message for sqlcode %ld not found", ca->sqlcode);
  60.    return rc;
  61. }
  62.