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