Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ED-4479:Adding sample code for Database Procedures without registration #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdint.h>

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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdint.h>

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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdint.h>

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;
}