home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <sqlenv.h> /* :rk.1:erk. */
- #include <sqlca.h>
- #include <sqlda.h>
-
- int err( struct sqlca * );
-
- int main(void) {
- /* DECLARE OUTPUT SQLDA TO RECEIVE DATA FROM SERVER PROCEDURE */
- struct sqlda *outda = (struct sqlda *) malloc(SQLDASIZE(1)); /* :rk.2:erk. */
-
- struct sqlca sqlca; /* DECLARE SQLCA */
-
- double sal = 0.0; /* LOCAL VARIABLES */ /* :rk.3:erk. */
- short salind = 0;
- int retcode = 0;
-
- /* INITIALIZE ONE ELEMENT OF OUTPUT SQLDA */ /* :rk.4:erk. */
- outda->sqln = 1; outda->sqld = 1;
- outda->sqlvar[0].sqltype = SQL_TYP_FLOAT;
- outda->sqlvar[0].sqllen = sizeof( double );
- outda->sqlvar[0].sqldata = (unsigned char *)&sal;
- outda->sqlvar[0].sqlind = (short *)&salind;
-
- printf("\nConnect to Remote Database.");
- EXEC SQL CONNECT TO SAMPLE; /* :rk.5:erk. */
- retcode = err( &sqlca );
-
- if (retcode == 0) { /* :rk.6:erk. */
- printf("\nCalling the Server Procedure named OUTSRV.");
- sqleproc( "OUTSRV.DLL\\OUTSRV",
- (struct sqlchar *)0, (struct sqlda *)0,
- outda, &sqlca );
- retcode = err( &sqlca );
-
- if (retcode == 0) { /* PRINT SALARY RETURNED IN OUTDA */
- printf("\nMedian Salary = %.2f\n", sal ); /* sal CONTAINS VALUE */
- }
- } /* END IF */
- free( outda ); /* FREE ALLOCATED MEMORY */
-
- /* DISCONNECT FROM REMOTE DATABASE */
- EXEC SQL CONNECT RESET; /* :rk.7:erk. */
- return retcode;
- } /* END MAIN */
-
- int err( struct sqlca *ca ) {
- char buf[512] = "";
- int rc = 0;
- if ( ca ) {
- if ( ca->sqlcode ) { /* PRINT ERROR MESSAGE */
- rc = sqlaintp( buf, 512, 78, ca );
- if ( rc != SQLA_ERR_NOMSG )
- printf( "\n%ld %s\n", ca->sqlcode, buf );
- }
- }
- return (rc);
- } /* END ERR */