#include #include #include #include /* Include the SQL Communications Area. You can use #include or EXEC SQL INCLUDE. */ #include /* Declare error handling function. */ void sql_error(msg) char *msg; { char err_msg[128]; size_t buf_len, msg_len; EXEC SQL WHENEVER SQLERROR CONTINUE; printf("\n%s\n", msg); buf_len = sizeof (err_msg); sqlglm(err_msg, &buf_len, &msg_len); printf("%.*s\n", msg_len, err_msg); EXEC SQL ROLLBACK RELEASE; exit(EXIT_FAILURE); } void example_proc() { EXEC SQL BEGIN DECLARE SECTION; varchar username[80]; varchar the_nomacc[20]; varchar temp[20]; EXEC SQL END DECLARE SECTION; /* Include the SQL Communications Area. You can use #include or EXEC SQL INCLUDE. */ #include /* Connect to ORACLE-- * Copy the username into the VARCHAR. */ strcpy((char *) username.arr, "hotdb/hotdb@sladb"); /* Set the length component of the VARCHAR. */ username.len = (unsigned short) strlen((char *) username.arr); /* Register sql_error() as the error handler. */ EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--\n"); /* Connect to ORACLE. Program will call sql_error() * if an error occurs when connecting to the database. */ EXEC SQL CONNECT :username; printf("\nConnected to ORACLE as user: %s\n", username.arr); EXEC SQL SELECT to_char(sysdate,'DD-MON-YYYY') into :temp from dual; temp.arr[temp.len] = '\0'; printf("ORACLE date is:%s\n", temp.arr); /* Branch to the notfound label when the * 1403 ("No data found") condition occurs. */ EXEC SQL WHENEVER NOT FOUND GOTO notfound; /* EXEC SQL SELECT nomacc INTO :the_nomacc FROM INTERPRETE WHERE matricule = 510022; */ /* Null-terminate the output string data. */ the_nomacc.arr[the_nomacc.len] = '\0'; printf("%s\n", the_nomacc.arr); //EXEC SQL ROLLBACK WORK RELEASE; return; notfound: printf("\nNomacc not found - try again.\n"); /* Disconnect from ORACLE. */ //EXEC SQL ROLLBACK WORK RELEASE; /* exit(EXIT_SUCCESS); */ } main() { example_proc(); }