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 / INPCLI.SQC < prev    next >
Encoding:
Text File  |  1994-02-28  |  2.0 KB  |  64 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sqlenv.h>
  5. #include <sqlca.h>
  6. #include <sqlda.h>
  7. #include <sqlutil.h>
  8.  
  9. char *table_name    = "Presidents";
  10. char *data_items[3] = { "Washington", "Jefferson", "Lincoln" };
  11. int err( struct sqlca * );
  12.  
  13. int main(void) {
  14.    int retcode = 0;  int cntr = 0;
  15.    struct sqlca    sqlca;
  16.    struct sqlchar *vardata = NULL;
  17.    struct sqlda   *input_sqlda = NULL;
  18.  
  19.   /* ALLOCATE AND INITIALIZE SQLCHAR STRUCTURE */
  20.    vardata = malloc( sizeof(struct sqlchar) + strlen( table_name ));
  21.    strcpy( vardata->data, table_name );  /* :rk.1:erk. */
  22.    vardata->length = strlen( vardata->data ) + 1;
  23.  
  24.   /* ALLOCATE AND INITIALZE SQLDA STRUCTURE */
  25.    input_sqlda = (struct sqlda *)malloc( SQLDASIZE(3) );
  26.    input_sqlda->sqln = 3;  input_sqlda->sqld = 3;
  27.    for ( cntr = 0; cntr < input_sqlda->sqld; cntr++) {
  28.       input_sqlda->sqlvar[cntr].sqltype = SQL_TYP_CSTR;  /* :rk.2:erk. */
  29.       input_sqlda->sqlvar[cntr].sqldata = data_items[cntr];
  30.       input_sqlda->sqlvar[cntr].sqllen  = strlen( data_items[cntr] ) + 1;
  31.       input_sqlda->sqlvar[cntr].sqlind  = NULL;
  32.    }
  33.  
  34.    printf("\nConnect to Remote Database.");
  35.    EXEC SQL CONNECT TO sample IN SHARE MODE;
  36.    retcode = err( &sqlca );
  37.  
  38.    if (retcode == 0) {
  39.      printf("\nCalling the Server Procedure named INPSRV.");
  40.      sqleproc( "INPSRV.DLL\\INPSRV", /* :rk.3:erk. */
  41.                 vardata, input_sqlda,
  42.                 NULL, &sqlca );
  43.      retcode = err( &sqlca );
  44.    } /* END IF */
  45.    free( vardata );  /* FREE ALLOCATED MEMORY */
  46.    free( input_sqlda );
  47.  
  48.    EXEC SQL CONNECT RESET;  /* DISCONNECT */
  49.    return retcode;
  50. }  /* END MAIN */
  51.  
  52. int err( struct sqlca *ca ) {
  53.    char buf[512] = "";
  54.    int  rc       = 0;
  55.    if ( ca ) {
  56.        if ( ca->sqlcode ) {  /* GET AND PRINT ERROR MESSAGE */
  57.          rc = sqlaintp( buf, 512, 78, ca );
  58.          if ( rc != SQLA_ERR_NOMSG )
  59.            printf( "\n%ld %s\n", ca->sqlcode, buf );
  60.        }
  61.      }
  62.    return (rc);
  63. } /* END ERR */
  64.