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