]> granicus.if.org Git - postgresql/blob - src/interfaces/ecpg/test/expected/sql-execute.c
pgindent run for 8.2.
[postgresql] / src / interfaces / ecpg / test / expected / sql-execute.c
1 /* Processed by ecpg (4.2.1) */
2 /* These include files are added by the preprocessor */
3 #include <ecpgtype.h>
4 #include <ecpglib.h>
5 #include <ecpgerrno.h>
6 #include <sqlca.h>
7 /* End of automatic include section */
8
9 #line 1 "execute.pgc"
10 #include <stdlib.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <stdio.h>
14
15
16 #line 1 "regression.h"
17
18
19
20
21
22
23 #line 6 "execute.pgc"
24
25
26 /* exec sql whenever sqlerror  sqlprint ; */
27 #line 8 "execute.pgc"
28
29
30 int
31 main(void)
32 {
33 /* exec sql begin declare section */
34
35
36
37
38
39
40 #line 14 "execute.pgc"
41         int                     amount[8];
42
43 #line 15 "execute.pgc"
44         int                     increment = 100;
45
46 #line 16 "execute.pgc"
47         char            name[8][8];
48
49 #line 17 "execute.pgc"
50         char            letter[8][1];
51
52 #line 18 "execute.pgc"
53         char            command[128];
54
55 /* exec sql end declare section */
56 #line 19 "execute.pgc"
57
58         int                     i,
59                                 j;
60
61         ECPGdebug(1, stderr);
62
63         {
64                 ECPGconnect(__LINE__, 0, "regress1", NULL, NULL, "main", 0);
65 #line 24 "execute.pgc"
66
67                 if (sqlca.sqlcode < 0)
68                         sqlprint();
69         }
70 #line 24 "execute.pgc"
71
72         {
73                 ECPGdo(__LINE__, 0, 1, NULL, "create  table test ( name char  ( 8 )    , amount int   , letter char  ( 1 )    )    ", ECPGt_EOIT, ECPGt_EORT);
74 #line 25 "execute.pgc"
75
76                 if (sqlca.sqlcode < 0)
77                         sqlprint();
78         }
79 #line 25 "execute.pgc"
80
81         {
82                 ECPGtrans(__LINE__, NULL, "commit");
83 #line 26 "execute.pgc"
84
85                 if (sqlca.sqlcode < 0)
86                         sqlprint();
87         }
88 #line 26 "execute.pgc"
89
90
91         sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f')");
92         {
93                 ECPGdo(__LINE__, 0, 1, NULL, "?",
94                            ECPGt_char_variable, (command), (long) 1, (long) 1, (1) * sizeof(char),
95                            ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
96 #line 29 "execute.pgc"
97
98                 if (sqlca.sqlcode < 0)
99                         sqlprint();
100         }
101 #line 29 "execute.pgc"
102
103
104         sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 2, 't')");
105         {
106                 ECPGdo(__LINE__, 0, 1, NULL, "?",
107                            ECPGt_char_variable, (command), (long) 1, (long) 1, (1) * sizeof(char),
108                            ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
109 #line 32 "execute.pgc"
110
111                 if (sqlca.sqlcode < 0)
112                         sqlprint();
113         }
114 #line 32 "execute.pgc"
115
116
117         sprintf(command, "insert into test (name, amount, letter) select name, amount+10, letter from test");
118         {
119                 ECPGdo(__LINE__, 0, 1, NULL, "?",
120                            ECPGt_char_variable, (command), (long) 1, (long) 1, (1) * sizeof(char),
121                            ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
122 #line 35 "execute.pgc"
123
124                 if (sqlca.sqlcode < 0)
125                         sqlprint();
126         }
127 #line 35 "execute.pgc"
128
129
130         printf("Inserted %ld tuples via execute immediate\n", sqlca.sqlerrd[2]);
131
132         sprintf(command, "insert into test (name, amount, letter) select name, amount+?, letter from test");
133         {
134                 ECPGprepare(__LINE__, "I", command);
135 #line 40 "execute.pgc"
136
137                 if (sqlca.sqlcode < 0)
138                         sqlprint();
139         }
140 #line 40 "execute.pgc"
141
142         {
143                 ECPGdo(__LINE__, 0, 1, NULL, "?",
144                            ECPGt_char_variable, (ECPGprepared_statement("I")), (long) 1, (long) 1, (1) * sizeof(char),
145                            ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L,
146                            ECPGt_int, &(increment), (long) 1, (long) 1, sizeof(int),
147                            ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
148 #line 41 "execute.pgc"
149
150                 if (sqlca.sqlcode < 0)
151                         sqlprint();
152         }
153 #line 41 "execute.pgc"
154
155
156         printf("Inserted %ld tuples via prepared execute\n", sqlca.sqlerrd[2]);
157
158         {
159                 ECPGtrans(__LINE__, NULL, "commit");
160 #line 45 "execute.pgc"
161
162                 if (sqlca.sqlcode < 0)
163                         sqlprint();
164         }
165 #line 45 "execute.pgc"
166
167
168         sprintf(command, "select * from test");
169
170         {
171                 ECPGprepare(__LINE__, "F", command);
172 #line 49 "execute.pgc"
173
174                 if (sqlca.sqlcode < 0)
175                         sqlprint();
176         }
177 #line 49 "execute.pgc"
178
179         /* declare CUR  cursor  for ? */
180 #line 50 "execute.pgc"
181
182
183         {
184                 ECPGdo(__LINE__, 0, 1, NULL, "declare CUR  cursor  for ?",
185                            ECPGt_char_variable, (ECPGprepared_statement("F")), (long) 1, (long) 1, (1) * sizeof(char),
186                            ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
187 #line 52 "execute.pgc"
188
189                 if (sqlca.sqlcode < 0)
190                         sqlprint();
191         }
192 #line 52 "execute.pgc"
193
194         {
195                 ECPGdo(__LINE__, 0, 1, NULL, "fetch 8 in CUR", ECPGt_EOIT,
196                            ECPGt_char, (name), (long) 8, (long) 8, (8) * sizeof(char),
197                            ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L,
198                            ECPGt_int, (amount), (long) 1, (long) 8, sizeof(int),
199                            ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L,
200                            ECPGt_char, (letter), (long) 1, (long) 8, (1) * sizeof(char),
201                            ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);
202 #line 53 "execute.pgc"
203
204                 if (sqlca.sqlcode < 0)
205                         sqlprint();
206         }
207 #line 53 "execute.pgc"
208
209
210         for (i = 0, j = sqlca.sqlerrd[2]; i < j; i++)
211         {
212                 /* exec sql begin declare section */
213
214
215
216 #line 58 "execute.pgc"
217                 char            n[8],
218                                         l = letter[i][0];
219
220 #line 59 "execute.pgc"
221                 int                     a = amount[i];
222
223 /* exec sql end declare section */
224 #line 60 "execute.pgc"
225
226
227                 strncpy(n, name[i], 8);
228                 printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
229         }
230
231         {
232                 ECPGdo(__LINE__, 0, 1, NULL, "close CUR", ECPGt_EOIT, ECPGt_EORT);
233 #line 66 "execute.pgc"
234
235                 if (sqlca.sqlcode < 0)
236                         sqlprint();
237         }
238 #line 66 "execute.pgc"
239
240
241         sprintf(command, "select * from test where amount = ?");
242
243         {
244                 ECPGprepare(__LINE__, "F", command);
245 #line 70 "execute.pgc"
246
247                 if (sqlca.sqlcode < 0)
248                         sqlprint();
249         }
250 #line 70 "execute.pgc"
251
252         /* declare CUR2  cursor  for ? */
253 #line 71 "execute.pgc"
254
255
256         {
257                 ECPGdo(__LINE__, 0, 1, NULL, "declare CUR2  cursor  for ?",
258                            ECPGt_char_variable, (ECPGprepared_statement("F")), (long) 1, (long) 1, (1) * sizeof(char),
259                            ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L,
260                            ECPGt_const, "1", (long) 1, (long) 1, strlen("1"),
261                            ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
262 #line 73 "execute.pgc"
263
264                 if (sqlca.sqlcode < 0)
265                         sqlprint();
266         }
267 #line 73 "execute.pgc"
268
269         {
270                 ECPGdo(__LINE__, 0, 1, NULL, "fetch in CUR2", ECPGt_EOIT,
271                            ECPGt_char, (name), (long) 8, (long) 8, (8) * sizeof(char),
272                            ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L,
273                            ECPGt_int, (amount), (long) 1, (long) 8, sizeof(int),
274                            ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L,
275                            ECPGt_char, (letter), (long) 1, (long) 8, (1) * sizeof(char),
276                            ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);
277 #line 74 "execute.pgc"
278
279                 if (sqlca.sqlcode < 0)
280                         sqlprint();
281         }
282 #line 74 "execute.pgc"
283
284
285         for (i = 0, j = sqlca.sqlerrd[2]; i < j; i++)
286         {
287                 /* exec sql begin declare section */
288
289
290
291 #line 79 "execute.pgc"
292                 char            n[8],
293                                         l = letter[i][0];
294
295 #line 80 "execute.pgc"
296                 int                     a = amount[i];
297
298 /* exec sql end declare section */
299 #line 81 "execute.pgc"
300
301
302                 strncpy(n, name[i], 8);
303                 printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
304         }
305
306         {
307                 ECPGdo(__LINE__, 0, 1, NULL, "close CUR2", ECPGt_EOIT, ECPGt_EORT);
308 #line 87 "execute.pgc"
309
310                 if (sqlca.sqlcode < 0)
311                         sqlprint();
312         }
313 #line 87 "execute.pgc"
314
315         {
316                 ECPGdo(__LINE__, 0, 1, NULL, "drop table test ", ECPGt_EOIT, ECPGt_EORT);
317 #line 88 "execute.pgc"
318
319                 if (sqlca.sqlcode < 0)
320                         sqlprint();
321         }
322 #line 88 "execute.pgc"
323
324         {
325                 ECPGtrans(__LINE__, NULL, "commit");
326 #line 89 "execute.pgc"
327
328                 if (sqlca.sqlcode < 0)
329                         sqlprint();
330         }
331 #line 89 "execute.pgc"
332
333         {
334                 ECPGdisconnect(__LINE__, "CURRENT");
335 #line 90 "execute.pgc"
336
337                 if (sqlca.sqlcode < 0)
338                         sqlprint();
339         }
340 #line 90 "execute.pgc"
341
342
343         return (0);
344 }