home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sqlenv.h> /* :rk.1:erk. */
- #include <sql.h>
- #include "block.h"
- #include <sqlca.h>
- #include <sqlda.h>
-
- int main(void) {
- struct sqlda sqldaIn;
- struct sqlca sqlca;
- struct persons person;
- int rc = 0;
-
- printf("\nCONNECT TO Database");
- EXEC SQL CONNECT TO sample IN SHARE MODE;
- printf("\nSQLCODE is %d\n", SQLCODE);
-
- if (SQLCODE == 0L) {
- strcpy(person.employees[0].name,"Elmer"); /* :rk.2:erk. */
- person.employees[0].id = 500;
- strcpy(person.employees[1].name,"Astro");
- person.employees[1].id = 510;
- strcpy(person.employees[2].name,"Calvin");
- person.employees[2].id = 520;
- strcpy(person.employees[3].name,"Wilma");
- person.employees[3].id = 530;
-
- person.number_of_records = 4; /* :rk.3:erk. */
-
- person.len = sizeof(person.number_of_records) + /* :rk.4:erk. */
- (sizeof(struct employee) * person.number_of_records);
-
- sqldaIn.sqln = 1;
- sqldaIn.sqld = 1;
- sqldaIn.sqlvar[0].sqltype = SQL_TYP_VARCHAR;
- sqldaIn.sqlvar[0].sqldata = (char*)&person; /* :rk.5:erk. */
- sqldaIn.sqlvar[0].sqllen = person.len;
- sqldaIn.sqlvar[0].sqlind = NULL;
-
- rc = sqleproc("BLKSRV.DLL\\ADD_EMPLOYEES", NULL, &sqldaIn, /* :rk.6:erk. */
- NULL, &sqlca);
- printf ("\n Sqlcode from sqleproc call is %d", sqlca.sqlcode);
-
- if (sqlca.sqlcode != 0) rc = err(&sqlca);
- EXEC SQL CONNECT RESET;
- }
- return(rc);
- }
-
- int err( struct sqlca * ca ) {
- char buf[512] = " ";
- int rc = 0;
- rc = sqlaintp( buf, 512, 78, ca );
- if ( rc != SQLA_ERR_NOMSG )
- printf("\n %ld %s", ca->sqlcode, buf);
- else
- printf("\n Error message for sqlcode %ld not found", ca->sqlcode);
- return rc;
- }