/*-------------------------------------------------------------------- * Example Pro*C program to describe a database procedure and print * its arguments. * Frank Naude - Sep 2000 *-------------------------------------------------------------------- */ #define MAX_PLSQL_PARAMETERS 30 #include #include #define SQLCA_INIT EXEC SQL INCLUDE sqlca; typedef char strz[31]; EXEC SQL TYPE strz IS STRING(31) REFERENCE; /* Declare functions */ int ora_logon(); int ora_logoff(); int ora_error(); int plsql_desc(char *procname); /*--------------------------------------------------------------------*/ int main() { ora_logon(); printf("About to describe procedure DBMS_OUTPUT.PUT_LINE...\n"); plsql_desc("DBMS_OUTPUT.PUT_LINE"); ora_logoff(); return 0; } /*-------------------------------------------------------------------- * Login to the Oracle database *--------------------------------------------------------------------*/ int ora_logon() { EXEC SQL BEGIN DECLARE SECTION; char *oracleid = "monitor/monitor"; EXEC SQL END DECLARE SECTION; EXEC SQL WHENEVER SQLERROR CONTINUE; EXEC SQL CONNECT :oracleid; if (sqlca.sqlcode != 0) { printf("ERROR: Unable to login to Oracle\n%.*s", sqlca.sqlerrm.sqlerrml, sqlca.sqlerrm.sqlerrmc); } } /*-------------------------------------------------------------------- * Logoff from the Oracle database *--------------------------------------------------------------------*/ int ora_logoff() { EXEC SQL WHENEVER SQLERROR CONTINUE; EXEC SQL ALTER SESSION SET SQL_TRACE FALSE; EXEC SQL COMMIT WORK RELEASE; } /*-------------------------------------------------------------------- * Handle Oracle errors *--------------------------------------------------------------------*/ int ora_error() { char errmsg[2000]; unsigned int buf_len, msg_len; EXEC SQL WHENEVER SQLERROR CONTINUE; buf_len = sizeof(errmsg); sqlglm(errmsg, &buf_len, &msg_len); printf("Oracle Error: %.*s\n", msg_len, errmsg); exit(8); } /*-------------------------------------------------------------------- * Describe PL/SQL parameters *--------------------------------------------------------------------*/ int plsql_desc(char *procname) { int overload [MAX_PLSQL_PARAMETERS]; int position [MAX_PLSQL_PARAMETERS]; int level [MAX_PLSQL_PARAMETERS]; static strz argument_name [MAX_PLSQL_PARAMETERS]; static short arg_name_ind [MAX_PLSQL_PARAMETERS]; static int datatype [MAX_PLSQL_PARAMETERS]; int default_value [MAX_PLSQL_PARAMETERS]; int in_out [MAX_PLSQL_PARAMETERS]; int length [MAX_PLSQL_PARAMETERS]; int precision [MAX_PLSQL_PARAMETERS]; int scale [MAX_PLSQL_PARAMETERS]; int radix [MAX_PLSQL_PARAMETERS]; int spare [MAX_PLSQL_PARAMETERS]; int i = 0; int t = -1; /* Default return type is -1 */ for (i=0; i