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