| 1 |
#include <stdlib.h> |
| 2 |
#include <string.h> |
| 3 |
|
| 4 |
exec sql include ../regression; |
| 5 |
|
| 6 |
exec sql whenever sqlerror stop; |
| 7 |
|
| 8 |
exec sql type c is char reference; |
| 9 |
typedef char* c; |
| 10 |
|
| 11 |
exec sql type ind is union { int integer; short smallint; }; |
| 12 |
typedef union { int integer; short smallint; } ind; |
| 13 |
|
| 14 |
#define BUFFERSIZ 8 |
| 15 |
exec sql type str is varchar[BUFFERSIZ]; |
| 16 |
|
| 17 |
#define CURNAME "mycur" |
| 18 |
|
| 19 |
int |
| 20 |
main (void) |
| 21 |
{ |
| 22 |
exec sql begin declare section; |
| 23 |
char *stmt1 = "SELECT id, t FROM t1"; |
| 24 |
char *curname1 = CURNAME; |
| 25 |
char *curname2 = CURNAME; |
| 26 |
char *curname3 = CURNAME; |
| 27 |
varchar curname4[50]; |
| 28 |
char *curname5 = CURNAME; |
| 29 |
int count; |
| 30 |
int id; |
| 31 |
char t[64]; |
| 32 |
exec sql end declare section; |
| 33 |
|
| 34 |
char msg[128]; |
| 35 |
|
| 36 |
ECPGdebug(1, stderr); |
| 37 |
|
| 38 |
strcpy(msg, "connect"); |
| 39 |
exec sql connect to REGRESSDB1 as test1; |
| 40 |
exec sql connect to REGRESSDB2 as test2; |
| 41 |
|
| 42 |
strcpy(msg, "set"); |
| 43 |
exec sql at test1 set datestyle to iso; |
| 44 |
|
| 45 |
strcpy(msg, "create"); |
| 46 |
exec sql at test1 create table t1(id serial primary key, t text); |
| 47 |
exec sql at test2 create table t1(id serial primary key, t text); |
| 48 |
|
| 49 |
strcpy(msg, "insert"); |
| 50 |
exec sql at test1 insert into t1(id, t) values (default, 'a'); |
| 51 |
exec sql at test1 insert into t1(id, t) values (default, 'b'); |
| 52 |
exec sql at test1 insert into t1(id, t) values (default, 'c'); |
| 53 |
exec sql at test1 insert into t1(id, t) values (default, 'd'); |
| 54 |
exec sql at test2 insert into t1(id, t) values (default, 'e'); |
| 55 |
|
| 56 |
strcpy(msg, "commit"); |
| 57 |
exec sql at test1 commit; |
| 58 |
exec sql at test2 commit; |
| 59 |
|
| 60 |
/* Dynamic cursorname test with INTO list in FETCH stmts */ |
| 61 |
|
| 62 |
strcpy(msg, "declare"); |
| 63 |
exec sql at test1 declare :curname1 cursor for |
| 64 |
select id, t from t1; |
| 65 |
|
| 66 |
strcpy(msg, "open"); |
| 67 |
exec sql at test1 open :curname1; |
| 68 |
|
| 69 |
strcpy(msg, "fetch from"); |
| 70 |
exec sql at test1 fetch forward from :curname1 into :id, :t; |
| 71 |
printf("%d %s\n", id, t); |
| 72 |
|
| 73 |
strcpy(msg, "fetch"); |
| 74 |
exec sql at test1 fetch forward :curname1 into :id, :t; |
| 75 |
printf("%d %s\n", id, t); |
| 76 |
|
| 77 |
strcpy(msg, "fetch 1 from"); |
| 78 |
exec sql at test1 fetch 1 from :curname1 into :id, :t; |
| 79 |
printf("%d %s\n", id, t); |
| 80 |
|
| 81 |
strcpy(msg, "fetch :count from"); |
| 82 |
count = 1; |
| 83 |
exec sql at test1 fetch :count from :curname1 into :id, :t; |
| 84 |
printf("%d %s\n", id, t); |
| 85 |
|
| 86 |
strcpy(msg, "move in"); |
| 87 |
exec sql at test1 move absolute 0 in :curname1; |
| 88 |
|
| 89 |
strcpy(msg, "fetch 1"); |
| 90 |
exec sql at test1 fetch 1 :curname1 into :id, :t; |
| 91 |
printf("%d %s\n", id, t); |
| 92 |
|
| 93 |
strcpy(msg, "fetch :count"); |
| 94 |
count = 1; |
| 95 |
exec sql at test1 fetch :count :curname1 into :id, :t; |
| 96 |
printf("%d %s\n", id, t); |
| 97 |
|
| 98 |
strcpy(msg, "close"); |
| 99 |
exec sql at test1 close :curname1; |
| 100 |
|
| 101 |
/* Dynamic cursorname test with INTO list in DECLARE stmt */ |
| 102 |
|
| 103 |
strcpy(msg, "declare"); |
| 104 |
exec sql at test1 declare :curname2 cursor for |
| 105 |
select id, t into :id, :t from t1; |
| 106 |
|
| 107 |
strcpy(msg, "open"); |
| 108 |
exec sql at test1 open :curname2; |
| 109 |
|
| 110 |
strcpy(msg, "fetch from"); |
| 111 |
exec sql at test1 fetch from :curname2; |
| 112 |
printf("%d %s\n", id, t); |
| 113 |
|
| 114 |
strcpy(msg, "fetch"); |
| 115 |
exec sql at test1 fetch :curname2; |
| 116 |
printf("%d %s\n", id, t); |
| 117 |
|
| 118 |
strcpy(msg, "fetch 1 from"); |
| 119 |
exec sql at test1 fetch 1 from :curname2; |
| 120 |
printf("%d %s\n", id, t); |
| 121 |
|
| 122 |
strcpy(msg, "fetch :count from"); |
| 123 |
count = 1; |
| 124 |
exec sql at test1 fetch :count from :curname2; |
| 125 |
printf("%d %s\n", id, t); |
| 126 |
|
| 127 |
strcpy(msg, "move"); |
| 128 |
exec sql at test1 move absolute 0 :curname2; |
| 129 |
|
| 130 |
strcpy(msg, "fetch 1"); |
| 131 |
exec sql at test1 fetch 1 :curname2; |
| 132 |
printf("%d %s\n", id, t); |
| 133 |
|
| 134 |
strcpy(msg, "fetch :count"); |
| 135 |
count = 1; |
| 136 |
exec sql at test1 fetch :count :curname2; |
| 137 |
printf("%d %s\n", id, t); |
| 138 |
|
| 139 |
strcpy(msg, "close"); |
| 140 |
exec sql at test1 close :curname2; |
| 141 |
|
| 142 |
/* Dynamic cursorname test with PREPARED stmt */ |
| 143 |
|
| 144 |
strcpy(msg, "prepare"); |
| 145 |
exec sql at test1 prepare st_id1 from :stmt1; |
| 146 |
exec sql at test2 prepare st_id1 from :stmt1; |
| 147 |
|
| 148 |
strcpy(msg, "declare"); |
| 149 |
exec sql at test1 declare :curname3 cursor for st_id1; |
| 150 |
exec sql at test2 declare :curname5 cursor for st_id1; |
| 151 |
|
| 152 |
strcpy(msg, "open"); |
| 153 |
exec sql at test1 open :curname3; |
| 154 |
exec sql at test2 open :curname5; |
| 155 |
|
| 156 |
strcpy(msg, "fetch"); |
| 157 |
exec sql at test2 fetch :curname5 into :id, :t; |
| 158 |
printf("%d %s\n", id, t); |
| 159 |
|
| 160 |
strcpy(msg, "fetch from"); |
| 161 |
exec sql at test1 fetch from :curname3 into :id, :t; |
| 162 |
printf("%d %s\n", id, t); |
| 163 |
|
| 164 |
strcpy(msg, "fetch 1 from"); |
| 165 |
exec sql at test1 fetch 1 from :curname3 into :id, :t; |
| 166 |
printf("%d %s\n", id, t); |
| 167 |
|
| 168 |
strcpy(msg, "fetch :count from"); |
| 169 |
count = 1; |
| 170 |
exec sql at test1 fetch :count from :curname3 into :id, :t; |
| 171 |
printf("%d %s\n", id, t); |
| 172 |
|
| 173 |
strcpy(msg, "move"); |
| 174 |
exec sql at test1 move absolute 0 :curname3; |
| 175 |
|
| 176 |
strcpy(msg, "fetch 1"); |
| 177 |
exec sql at test1 fetch 1 :curname3 into :id, :t; |
| 178 |
printf("%d %s\n", id, t); |
| 179 |
|
| 180 |
strcpy(msg, "fetch :count"); |
| 181 |
count = 1; |
| 182 |
exec sql at test1 fetch :count :curname3 into :id, :t; |
| 183 |
printf("%d %s\n", id, t); |
| 184 |
|
| 185 |
strcpy(msg, "close"); |
| 186 |
exec sql at test1 close :curname3; |
| 187 |
exec sql at test2 close :curname5; |
| 188 |
|
| 189 |
strcpy(msg, "deallocate prepare"); |
| 190 |
exec sql at test1 deallocate prepare st_id1; |
| 191 |
exec sql at test2 deallocate prepare st_id1; |
| 192 |
|
| 193 |
/* Dynamic cursorname test with PREPARED stmt, |
| 194 |
cursor name in varchar */ |
| 195 |
|
| 196 |
curname4.len = strlen(CURNAME); |
| 197 |
strcpy(curname4.arr, CURNAME); |
| 198 |
|
| 199 |
strcpy(msg, "prepare"); |
| 200 |
exec sql at test1 prepare st_id2 from :stmt1; |
| 201 |
|
| 202 |
strcpy(msg, "declare"); |
| 203 |
exec sql at test1 declare :curname4 cursor for st_id2; |
| 204 |
|
| 205 |
strcpy(msg, "open"); |
| 206 |
exec sql at test1 open :curname4; |
| 207 |
|
| 208 |
strcpy(msg, "fetch from"); |
| 209 |
exec sql at test1 fetch from :curname4 into :id, :t; |
| 210 |
printf("%d %s\n", id, t); |
| 211 |
|
| 212 |
strcpy(msg, "fetch"); |
| 213 |
exec sql at test1 fetch :curname4 into :id, :t; |
| 214 |
printf("%d %s\n", id, t); |
| 215 |
|
| 216 |
strcpy(msg, "fetch 1 from"); |
| 217 |
exec sql at test1 fetch 1 from :curname4 into :id, :t; |
| 218 |
printf("%d %s\n", id, t); |
| 219 |
|
| 220 |
strcpy(msg, "fetch :count from"); |
| 221 |
count = 1; |
| 222 |
exec sql at test1 fetch :count from :curname4 into :id, :t; |
| 223 |
printf("%d %s\n", id, t); |
| 224 |
|
| 225 |
strcpy(msg, "move"); |
| 226 |
exec sql at test1 move absolute 0 :curname4; |
| 227 |
|
| 228 |
strcpy(msg, "fetch 1"); |
| 229 |
exec sql at test1 fetch 1 :curname4 into :id, :t; |
| 230 |
printf("%d %s\n", id, t); |
| 231 |
|
| 232 |
strcpy(msg, "fetch :count"); |
| 233 |
count = 1; |
| 234 |
exec sql at test1 fetch :count :curname4 into :id, :t; |
| 235 |
printf("%d %s\n", id, t); |
| 236 |
|
| 237 |
strcpy(msg, "close"); |
| 238 |
exec sql at test1 close :curname4; |
| 239 |
|
| 240 |
strcpy(msg, "deallocate prepare"); |
| 241 |
exec sql at test1 deallocate prepare st_id2; |
| 242 |
|
| 243 |
/* End test */ |
| 244 |
|
| 245 |
strcpy(msg, "drop"); |
| 246 |
exec sql at test1 drop table t1; |
| 247 |
exec sql at test2 drop table t1; |
| 248 |
|
| 249 |
strcpy(msg, "commit"); |
| 250 |
exec sql at test1 commit; |
| 251 |
|
| 252 |
strcpy(msg, "disconnect"); |
| 253 |
exec sql disconnect all; |
| 254 |
|
| 255 |
return 0; |
| 256 |
} |