diff --git a/EnterpriseAccess/database_procedures_without_registering/src/demo_exec_dbprocs_with_reg.sc b/EnterpriseAccess/database_procedures_without_registering/src/demo_exec_dbprocs_with_reg.sc new file mode 100644 index 0000000..305b6bc --- /dev/null +++ b/EnterpriseAccess/database_procedures_without_registering/src/demo_exec_dbprocs_with_reg.sc @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include +#include +#include + +exec sql include sqlca; +exec sql include sqlda; + +#define dbg(...) do { \ + fprintf(stderr, "[DBG ] : "); \ + fprintf(stderr, "\n********************** \n"); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr,"\n********************** \n"); \ + fprintf(stderr, "\n"); \ + } while(0) + + +static void demo_dbproc_with_reg(void) +{ + EXEC SQL BEGIN DECLARE SECTION; + char register_procedure[] = { + "register procedure dbproc1 (a1 char(25)) " + "as import from dbproc1" + }; + char c1[] = {"Col1"}; + EXEC SQL END DECLARE SECTION; + EXEC SQL WHENEVER SQLERROR STOP; + EXEC SQL EXECUTE IMMEDIATE :register_procedure; + EXEC SQL EXECUTE PROCEDURE dbproc1(a1=:c1); + + EXEC SQL COMMIT; +} + + +int main(int argc, char **argv) +{ + EXEC SQL BEGIN DECLARE SECTION; + char *dbname = NULL; + EXEC SQL END DECLARE SECTION; + + if (argc < 1 || argv[0] == NULL) { + fprintf(stderr, "Connection String not provided!! Please provide connection string as argument"); + return -1; + } + dbname = argv[1]; + + EXEC SQL WHENEVER SQLERROR STOP; + dbg("connecting to %s...\n", dbname); + EXEC SQL CONNECT :dbname; + + demo_dbproc_with_reg(); + + EXEC SQL DISCONNECT; +} diff --git a/EnterpriseAccess/database_procedures_without_registering/src/demo_exec_dbprocs_without_reg.sc b/EnterpriseAccess/database_procedures_without_registering/src/demo_exec_dbprocs_without_reg.sc new file mode 100644 index 0000000..6b592bd --- /dev/null +++ b/EnterpriseAccess/database_procedures_without_registering/src/demo_exec_dbprocs_without_reg.sc @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include +#include +#include + +exec sql include sqlca; +exec sql include sqlda; + +#define dbg(...) do { \ + fprintf(stderr, "[DBG ] : "); \ + fprintf(stderr, "\n********************** \n"); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr,"\n********************** \n"); \ + fprintf(stderr, "\n"); \ + } while(0) + + +/* + * No registration of the procedure with EA is performed here. + */ +static void demo_dbproc_with_out_reg(void) +{ + EXEC SQL BEGIN DECLARE SECTION; + char enable_procedures_without_registration[] = {"set NOREGPROC"}; + char disable_procedures_without_registration[] = {"set REGPROC"}; + char c1[] = {"DBPROC_NO_REG"}; + EXEC SQL END DECLARE SECTION; + EXEC SQL WHENEVER SQLERROR STOP; + EXEC SQL EXECUTE IMMEDIATE :enable_procedures_without_registration; + EXEC SQL EXECUTE PROCEDURE dbproc1(a1=:c1); + EXEC SQL EXECUTE IMMEDIATE :disable_procedures_without_registration; + + EXEC SQL COMMIT; +} + +int main(int argc, char **argv) +{ + EXEC SQL BEGIN DECLARE SECTION; + char *dbname = NULL; + EXEC SQL END DECLARE SECTION; + + if (argc < 1 || argv[0] == NULL) { + fprintf(stderr, "Connection String not provided!! Please provide connection string as argument"); + return -1; + } + dbname = argv[1]; + + EXEC SQL WHENEVER SQLERROR STOP; + dbg("connecting to %s...\n", dbname); + EXEC SQL CONNECT :dbname; + + demo_dbproc_with_out_reg(); + + EXEC SQL DISCONNECT; +} diff --git a/EnterpriseAccess/database_procedures_without_registering/src/demo_setup_dbprocs.sc b/EnterpriseAccess/database_procedures_without_registering/src/demo_setup_dbprocs.sc new file mode 100644 index 0000000..d1031f3 --- /dev/null +++ b/EnterpriseAccess/database_procedures_without_registering/src/demo_setup_dbprocs.sc @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include +#include + +exec sql include sqlca; +exec sql include sqlda; + +#define dbg(...) do { \ + fprintf(stderr, "[DBG ] : "); \ + fprintf(stderr, "\n********************** \n"); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr,"\n********************** \n"); \ + fprintf(stderr, "\n"); \ + } while(0) + + +static void setup_demo_dbproc(void) +{ + EXEC SQL BEGIN DECLARE SECTION; + char drop_procedure [] = {"drop procedure dbproc1"}; + char drop_table [] = {"drop table table1"}; + char remove_procedure[] = {"remove procedure dbproc1"}; + + char create_proc_cmd[] = { + "create or replace procedure dbproc1(a1 in char) " + "as begin " + "insert into table1 values(a1);" + "end;" + }; + EXEC SQL END DECLARE SECTION; + + EXEC SQL WHENEVER SQLERROR CONTINUE; + EXEC SQL EXECUTE IMMEDIATE :remove_procedure; + EXEC SQL EXECUTE IMMEDIATE :drop_table; + EXEC SQL DIRECT EXECUTE IMMEDIATE :drop_procedure; + EXEC SQL WHENEVER SQLERROR STOP; + EXEC SQL CREATE TABLE table1 (col1 char(100)); + EXEC SQL DIRECT EXECUTE IMMEDIATE :create_proc_cmd; + EXEC SQL COMMIT; +} + +int main(int argc, char **argv) +{ + EXEC SQL BEGIN DECLARE SECTION; + char *dbname = NULL; + EXEC SQL END DECLARE SECTION; + + if (argc < 1 || argv[0] == NULL) { + fprintf(stderr, "Connection String not provided!! Please provide connection string as argument"); + return -1; + } + dbname = argv[1]; + EXEC SQL WHENEVER SQLERROR STOP; + dbg("connecting to %s...\n", dbname); + EXEC SQL CONNECT :dbname; + + setup_demo_dbproc(); + + EXEC SQL DISCONNECT; +}