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