#include #include #include static const char _Cn1[] = "mycur"; #line 1 "outofscope.ec" #include #include #include #include /* * exec sql begin declare section; */ #line 6 "outofscope.ec" /* * exec sql include struct.h; */ #line 7 "outofscope.ec" #line 7 "outofscope.ec" #line 127 "struct.h" #line 1 "outofscope.ec" struct mytype { int id; char t[64]; double d1; double d2; char c[30]; } ; typedef struct mytype MYTYPE; struct mynulltype { int id; int t; int d1; int d2; int c; } ; typedef struct mynulltype MYNULLTYPE; /* * exec sql end declare section; */ #line 8 "outofscope.ec" #line 9 "outofscope.ec" /* * exec sql whenever sqlerror stop; */ #line 10 "outofscope.ec" static void get_var1(MYTYPE **myvar0, MYNULLTYPE **mynullvar0) { /* * exec sql begin declare section; */ #line 15 "outofscope.ec" #line 16 "outofscope.ec" MYTYPE *myvar = malloc(sizeof(MYTYPE)); MYNULLTYPE *mynullvar = malloc(sizeof(MYNULLTYPE)); /* * exec sql end declare section; */ #line 18 "outofscope.ec" /* Test DECLARE ... SELECT ... INTO with pointers */ /* * exec sql declare mycur cursor for select * INTO :myvar :mynullvar from a1; */ #line 22 "outofscope.ec" { #line 22 "outofscope.ec" static const char *sqlcmdtxt[] = #line 22 "outofscope.ec" { #line 22 "outofscope.ec" "select * from a1", 0 }; #line 22 "outofscope.ec" static ifx_sqlvar_t _sqobind[] = { { 102, sizeof((myvar)->id), 0, 0, 0, 0, 102, sizeof((mynullvar)->id), 0, 0, 0, 0, 0, 0, 0, 0 }, { 100, 64, 0, 0, 0, 0, 102, sizeof((mynullvar)->t), 0, 0, 0, 0, 0, 0, 0, 0 }, { 105, sizeof((myvar)->d1), 0, 0, 0, 0, 102, sizeof((mynullvar)->d1), 0, 0, 0, 0, 0, 0, 0, 0 }, { 105, sizeof((myvar)->d2), 0, 0, 0, 0, 102, sizeof((mynullvar)->d2), 0, 0, 0, 0, 0, 0, 0, 0 }, { 100, 30, 0, 0, 0, 0, 102, sizeof((mynullvar)->c), 0, 0, 0, 0, 0, 0, 0, 0 }, #line 22 "outofscope.ec" }; static ifx_sqlda_t _SD0 = { 5, _sqobind, {0}, 5, 0 }; #line 22 "outofscope.ec" _sqobind[0].sqldata = (char *) &(myvar)->id; _sqobind[0].sqlidata = (char *) &(mynullvar)->id; #line 22 "outofscope.ec" _sqobind[1].sqldata = (myvar)->t; _sqobind[1].sqlidata = (char *) &(mynullvar)->t; #line 22 "outofscope.ec" _sqobind[2].sqldata = (char *) &(myvar)->d1; _sqobind[2].sqlidata = (char *) &(mynullvar)->d1; #line 22 "outofscope.ec" _sqobind[3].sqldata = (char *) &(myvar)->d2; _sqobind[3].sqlidata = (char *) &(mynullvar)->d2; #line 22 "outofscope.ec" _sqobind[4].sqldata = (myvar)->c; _sqobind[4].sqlidata = (char *) &(mynullvar)->c; #line 22 "outofscope.ec" sqli_curs_decl_stat(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, _Cn1, 512), _Cn1, sqlcmdtxt, (ifx_sqlda_t *)0, &_SD0, 0, (ifx_literal_t *)0, (ifx_namelist_t *)0, 2, 0, 0); #line 22 "outofscope.ec" { if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} } #line 22 "outofscope.ec" } if (sqlca.sqlcode != 0) exit(1); *myvar0 = myvar; *mynullvar0 = mynullvar; } static void open_cur1(void) { /* * exec sql open mycur; */ #line 34 "outofscope.ec" { #line 34 "outofscope.ec" sqli_curs_open(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, _Cn1, 768), (ifx_sqlda_t *)0, (char *)0, (struct value *)0, 0, 0); #line 34 "outofscope.ec" { if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} } #line 34 "outofscope.ec" } if (sqlca.sqlcode != 0) exit(1); } static void get_record1(void) { /* * exec sql fetch mycur; */ #line 43 "outofscope.ec" { #line 43 "outofscope.ec" static _FetchSpec _FS0 = { 0, 1, 0 }; sqli_curs_fetch(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, _Cn1, 768), (ifx_sqlda_t *)0, (ifx_sqlda_t *)0, (char *)0, &_FS0); #line 43 "outofscope.ec" { if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} } #line 43 "outofscope.ec" } if (sqlca.sqlcode != 0 && sqlca.sqlcode != SQLNOTFOUND) exit(1); } static void close_cur1(void) { /* * exec sql close mycur; */ #line 52 "outofscope.ec" { #line 52 "outofscope.ec" sqli_curs_close(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, _Cn1, 768)); #line 52 "outofscope.ec" { if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} } #line 52 "outofscope.ec" } if (sqlca.sqlcode != 0) exit(1); } int main (void) { MYTYPE *myvar; MYNULLTYPE *mynullvar; char msg[128]; ECPGdebug(1, stderr); /* * exec sql connect to "test"; */ #line 68 "outofscope.ec" { #line 68 "outofscope.ec" sqli_connect_open(ESQLINTVERSION, 0, "test", (char *)0, (ifx_conn_t *)0, 0); #line 68 "outofscope.ec" { if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} } #line 68 "outofscope.ec" } /* * exec sql create table a1(id serial primary key, t text, d1 numeric, d2 float8, c character(10)); */ #line 71 "outofscope.ec" { #line 71 "outofscope.ec" static const char *sqlcmdtxt[] = #line 71 "outofscope.ec" { #line 71 "outofscope.ec" "create table a1 ( id serial primary key , t text , d1 numeric , d2 float8 , c character ( 10 ) )", 0 }; #line 71 "outofscope.ec" static ifx_statement_t _SQ0 = {0}; #line 71 "outofscope.ec" sqli_stmt(ESQLINTVERSION, &_SQ0, sqlcmdtxt, 0, (ifx_sqlvar_t *)0, (struct value *)0, (ifx_literal_t *)0, (ifx_namelist_t *)0, (ifx_cursor_t *)0, -1, 0, 0); #line 71 "outofscope.ec" { if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} } #line 71 "outofscope.ec" } /* * exec sql insert into a1(id, t, d1, d2, c) values (default, 'a', 1.0, 2, 'a'); */ #line 73 "outofscope.ec" { #line 73 "outofscope.ec" static const char *sqlcmdtxt[] = #line 73 "outofscope.ec" { #line 73 "outofscope.ec" "insert into a1 ( id , t , d1 , d2 , c ) values ( default , 'a' , 1.0 , 2 , 'a' )", 0 }; #line 73 "outofscope.ec" static ifx_statement_t _SQ0 = {0}; #line 73 "outofscope.ec" sqli_stmt(ESQLINTVERSION, &_SQ0, sqlcmdtxt, 0, (ifx_sqlvar_t *)0, (struct value *)0, (ifx_literal_t *)0, (ifx_namelist_t *)0, (ifx_cursor_t *)0, 6, 0, 0); #line 73 "outofscope.ec" { if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} } #line 73 "outofscope.ec" } /* * exec sql insert into a1(id, t, d1, d2, c) values (default, null, null, null, null); */ #line 74 "outofscope.ec" { #line 74 "outofscope.ec" static const char *sqlcmdtxt[] = #line 74 "outofscope.ec" { #line 74 "outofscope.ec" "insert into a1 ( id , t , d1 , d2 , c ) values ( default , null , null , null , null )", 0 }; #line 74 "outofscope.ec" static ifx_statement_t _SQ0 = {0}; #line 74 "outofscope.ec" sqli_stmt(ESQLINTVERSION, &_SQ0, sqlcmdtxt, 0, (ifx_sqlvar_t *)0, (struct value *)0, (ifx_literal_t *)0, (ifx_namelist_t *)0, (ifx_cursor_t *)0, 6, 0, 0); #line 74 "outofscope.ec" { if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} } #line 74 "outofscope.ec" } /* * exec sql insert into a1(id, t, d1, d2, c) values (default, '"a"', -1.0, 'nan'::float8, 'a'); */ #line 75 "outofscope.ec" { #line 75 "outofscope.ec" static const char *sqlcmdtxt[] = #line 75 "outofscope.ec" { #line 75 "outofscope.ec" "insert into a1 ( id , t , d1 , d2 , c ) values ( default , '"a"' , - 1.0 , 'nan' :: float8 , 'a' )", 0 }; #line 75 "outofscope.ec" static ifx_statement_t _SQ0 = {0}; #line 75 "outofscope.ec" sqli_stmt(ESQLINTVERSION, &_SQ0, sqlcmdtxt, 0, (ifx_sqlvar_t *)0, (struct value *)0, (ifx_literal_t *)0, (ifx_namelist_t *)0, (ifx_cursor_t *)0, 6, 0, 0); #line 75 "outofscope.ec" { if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} } #line 75 "outofscope.ec" } /* * exec sql insert into a1(id, t, d1, d2, c) values (default, 'b', 2.0, 3, 'b'); */ #line 76 "outofscope.ec" { #line 76 "outofscope.ec" static const char *sqlcmdtxt[] = #line 76 "outofscope.ec" { #line 76 "outofscope.ec" "insert into a1 ( id , t , d1 , d2 , c ) values ( default , 'b' , 2.0 , 3 , 'b' )", 0 }; #line 76 "outofscope.ec" static ifx_statement_t _SQ0 = {0}; #line 76 "outofscope.ec" sqli_stmt(ESQLINTVERSION, &_SQ0, sqlcmdtxt, 0, (ifx_sqlvar_t *)0, (struct value *)0, (ifx_literal_t *)0, (ifx_namelist_t *)0, (ifx_cursor_t *)0, 6, 0, 0); #line 76 "outofscope.ec" { if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} } #line 76 "outofscope.ec" } /* * exec sql commit; */ #line 78 "outofscope.ec" { #line 78 "outofscope.ec" sqli_trans_commit(); #line 78 "outofscope.ec" { if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} } #line 78 "outofscope.ec" } /* Test out-of-scope DECLARE/OPEN/FETCH/CLOSE */ get_var1(&myvar, &mynullvar); open_cur1(); while (1) { memset(myvar, 0, sizeof(MYTYPE)); get_record1(); if (sqlca.sqlcode == SQLNOTFOUND) break; printf("id=%d%s t='%s'%s d1=%lf%s d2=%lf%s c = '%s'%s\n", myvar->id, mynullvar->id ? " (NULL)" : "", myvar->t, mynullvar->t ? " (NULL)" : "", myvar->d1, mynullvar->d1 ? " (NULL)" : "", myvar->d2, mynullvar->d2 ? " (NULL)" : "", myvar->c, mynullvar->c ? " (NULL)" : ""); } close_cur1(); /* * exec sql drop table a1; */ #line 101 "outofscope.ec" { #line 101 "outofscope.ec" static const char *sqlcmdtxt[] = #line 101 "outofscope.ec" { #line 101 "outofscope.ec" "drop table a1", 0 }; #line 101 "outofscope.ec" static ifx_statement_t _SQ0 = {0}; #line 101 "outofscope.ec" sqli_stmt(ESQLINTVERSION, &_SQ0, sqlcmdtxt, 0, (ifx_sqlvar_t *)0, (struct value *)0, (ifx_literal_t *)0, (ifx_namelist_t *)0, (ifx_cursor_t *)0, -1, 0, 0); #line 101 "outofscope.ec" { if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} } #line 101 "outofscope.ec" } /* * exec sql commit; */ #line 103 "outofscope.ec" { #line 103 "outofscope.ec" sqli_trans_commit(); #line 103 "outofscope.ec" { if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} } #line 103 "outofscope.ec" } /* * exec sql disconnect all; */ #line 105 "outofscope.ec" { #line 105 "outofscope.ec" sqli_connect_close(2, (char *)0, 0, 0); #line 105 "outofscope.ec" { if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} } #line 105 "outofscope.ec" } return (0); } #line 108 "outofscope.ec"