home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sqlenv.h>
- #include <sqlca.h>
- #include <sqlda.h>
- #include <sqlutil.h>
-
- char *table_name = "Presidents";
- char *data_items[3] = { "Washington", "Jefferson", "Lincoln" };
- int err( struct sqlca * );
-
- int main(void) {
- int retcode = 0; int cntr = 0;
- struct sqlca sqlca;
- struct sqlchar *vardata = NULL;
- struct sqlda *input_sqlda = NULL;
-
- /* ALLOCATE AND INITIALIZE SQLCHAR STRUCTURE */
- vardata = malloc( sizeof(struct sqlchar) + strlen( table_name ));
- strcpy( vardata->data, table_name ); /* :rk.1:erk. */
- vardata->length = strlen( vardata->data ) + 1;
-
- /* ALLOCATE AND INITIALZE SQLDA STRUCTURE */
- input_sqlda = (struct sqlda *)malloc( SQLDASIZE(3) );
- input_sqlda->sqln = 3; input_sqlda->sqld = 3;
- for ( cntr = 0; cntr < input_sqlda->sqld; cntr++) {
- input_sqlda->sqlvar[cntr].sqltype = SQL_TYP_CSTR; /* :rk.2:erk. */
- input_sqlda->sqlvar[cntr].sqldata = data_items[cntr];
- input_sqlda->sqlvar[cntr].sqllen = strlen( data_items[cntr] ) + 1;
- input_sqlda->sqlvar[cntr].sqlind = NULL;
- }
-
- printf("\nConnect to Remote Database.");
- EXEC SQL CONNECT TO sample IN SHARE MODE;
- retcode = err( &sqlca );
-
- if (retcode == 0) {
- printf("\nCalling the Server Procedure named INPSRV.");
- sqleproc( "INPSRV.DLL\\INPSRV", /* :rk.3:erk. */
- vardata, input_sqlda,
- NULL, &sqlca );
- retcode = err( &sqlca );
- } /* END IF */
- free( vardata ); /* FREE ALLOCATED MEMORY */
- free( input_sqlda );
-
- EXEC SQL CONNECT RESET; /* DISCONNECT */
- return retcode;
- } /* END MAIN */
-
- int err( struct sqlca *ca ) {
- char buf[512] = "";
- int rc = 0;
- if ( ca ) {
- if ( ca->sqlcode ) { /* GET AND 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 */