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