#include <stdio.h> #include <string.h> EXEC SQL BEGIN DECLARE SECTION; int H1; int H2; int H3; VARCHAR LOGON_STR[30]; VARCHAR errmsg[81]; EXEC SQL END DECLARE SECTION; EXEC SQL INCLUDE SQLCA; long errcode; long i; long count; short maxlen = 80; char reqtype[40]; int ch; /**************************************************************/ /* error_check */ /**************************************************************/ void error_check() { if (SQLCODE != 0) { PPRTEXT(&SQL_RDTRTCON, &errcode, &errmsg, &maxlen); errmsg.arr[errmsg.len] = '\0'; printf("\n"); printf("ERROR/WARNING DETECTED IN %s\n", reqtype); printf(" CODE: %d\n", errcode); printf(" MSG : %s\n", errmsg.arr); } } /**************************************************************/ /* exec_request_001 */ /**************************************************************/ void exec_request_001() { strcpy(reqtype, "CALL PROCEDURE"); H1=1; EXEC SQL CALL case1(:H1, :H2, :H3); error_check(); if (SQLCODE == 0) { printf("H1 -%d\n",H1); printf("H2 -%d\n",H2); printf("H3 -%d\n",H3); printf("FINISHED REQUEST001\n"); } return; } /**************************************************************/ /* exec_request_002 */ /**************************************************************/ void exec_request_002() { strcpy(reqtype, "CALL PROCEDURE"); H1=1; H2=2; EXEC SQL CALL case1(:H1, :H2, :H3); error_check(); if (SQLCODE == 0) { printf("H1 -%d\n",H1); printf("H2 -%d\n",H2); printf("H3 -%d\n",H3); printf("FINISHED REQUEST002\n"); } return; } /**************************************************************/ /* exec_request_003 */ /**************************************************************/ void exec_request_003() { strcpy(reqtype, "CALL PROCEDURE"); EXEC SQL CALL case1(1, :H2, :H3); error_check(); if (SQLCODE == 0) { printf("H2 -%d\n",H2); printf("H3 -%d\n",H3); printf("FINISHED REQUEST003\n"); } return; } /**************************************************************/ /* exec_request_004 */ /**************************************************************/ void exec_request_004() { strcpy (reqtype, "CALL PROCEDURE"); H1=2; EXEC SQL CALL case1(:H1*:H1, :H2, :H3); error_check(); if (SQLCODE == 0) { printf("H2 -%d\n",H2); printf("H3 -%d\n",H3); printf("FINISHED REQUEST004\n"); } return; } /**************************************************************/ /* MAIN PROGRAM */ /**************************************************************/ main(argc, argv) int argc; char *argv[]; { int i; if (argc < 2) { printf("You must supply the LOGON STRING.\n"); exit(1); } printf ("Executing stored procedure 'case1'...\n\n"); strcpy(LOGON_STR.arr, argv[1]); LOGON_STR.len = strlen(LOGON_STR.arr); /* LOGON the DBS */ strcpy(reqtype, "LOGON"); EXEC SQL LOGON :LOGON_STR; error_check(); if (SQLCODE != 0) exit(1); printf("LOGON SUCCESSFUL!\n"); /* Execute the 4 stored-procedure calling functions */ exec_request_001(); exec_request_002(); exec_request_003(); exec_request_004(); /* LOGOFF the DBS */ strcpy (reqtype, "LOGOFF"); EXEC SQL LOGOFF; error_check(); if (SQLCODE == 0) printf("LOGOFF SUCCESSFUL!\n"); return; }