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 / OUTCLI.SQC < prev    next >
Encoding:
Text File  |  1994-02-28  |  1.8 KB  |  60 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sqlenv.h> /* :rk.1:erk. */
  4. #include <sqlca.h>
  5. #include <sqlda.h>
  6.  
  7. int err( struct sqlca * );
  8.  
  9. int main(void) {
  10.  /* DECLARE OUTPUT SQLDA TO RECEIVE DATA FROM SERVER PROCEDURE */
  11.    struct sqlda *outda = (struct sqlda *) malloc(SQLDASIZE(1)); /* :rk.2:erk. */
  12.  
  13.    struct sqlca sqlca;  /* DECLARE SQLCA */
  14.  
  15.    double sal     = 0.0; /* LOCAL VARIABLES */ /* :rk.3:erk. */
  16.    short  salind  = 0;
  17.    int    retcode = 0;
  18.  
  19.  /* INITIALIZE ONE ELEMENT OF OUTPUT SQLDA */  /* :rk.4:erk. */
  20.    outda->sqln = 1;  outda->sqld = 1;
  21.    outda->sqlvar[0].sqltype = SQL_TYP_FLOAT;
  22.    outda->sqlvar[0].sqllen  = sizeof( double );
  23.    outda->sqlvar[0].sqldata = (unsigned char *)&sal;
  24.    outda->sqlvar[0].sqlind  = (short *)&salind;
  25.  
  26.    printf("\nConnect to Remote Database.");
  27.    EXEC SQL CONNECT TO SAMPLE; /* :rk.5:erk. */
  28.    retcode = err( &sqlca );
  29.  
  30.    if (retcode == 0) { /* :rk.6:erk. */
  31.      printf("\nCalling the Server Procedure named OUTSRV.");
  32.      sqleproc( "OUTSRV.DLL\\OUTSRV",
  33.                 (struct sqlchar *)0, (struct sqlda   *)0,
  34.                 outda, &sqlca );
  35.      retcode = err( &sqlca );
  36.  
  37.      if (retcode == 0) {  /* PRINT SALARY RETURNED IN OUTDA */
  38.        printf("\nMedian Salary = %.2f\n", sal ); /* sal CONTAINS VALUE */
  39.      }
  40.    } /* END IF */
  41.    free( outda );  /* FREE ALLOCATED MEMORY */
  42.  
  43.  /* DISCONNECT FROM REMOTE DATABASE */
  44.    EXEC SQL CONNECT RESET; /* :rk.7:erk. */
  45.    return retcode;
  46. }  /* END MAIN */
  47.  
  48. int err( struct sqlca *ca ) {
  49.    char buf[512] = "";
  50.    int  rc       = 0;
  51.    if ( ca ) {
  52.        if ( ca->sqlcode ) {  /* PRINT ERROR MESSAGE */
  53.          rc = sqlaintp( buf, 512, 78, ca );
  54.          if ( rc != SQLA_ERR_NOMSG )
  55.            printf( "\n%ld %s\n", ca->sqlcode, buf );
  56.        }
  57.      }
  58.    return (rc);
  59. } /* END ERR */
  60.