Debian Codegraph @

src/interfaces/ecpg/test/expected/compat_oracle-char_array.c

raw
1 /* Processed by ecpg (regression mode) */
2 /* These include files are added by the preprocessor */
3 #include <ecpglib.h>
4 #include <ecpgerrno.h>
5 #include <sqlca.h>
6 /* End of automatic include section */
7 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
8
9 #line 1 "char_array.pgc"
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13
14 #include <pgtypes_numeric.h>
15
16
17 #line 1 "sqlda.h"
18 #ifndef ECPG_SQLDA_H
19 #define ECPG_SQLDA_H
20
21 #ifdef _ECPG_INFORMIX_H
22
23 #include "sqlda-compat.h"
24 typedef struct sqlvar_compat sqlvar_t;
25 typedef struct sqlda_compat sqlda_t;
26
27 #else
28
29 #include "sqlda-native.h"
30 typedef struct sqlvar_struct sqlvar_t;
31 typedef struct sqlda_struct sqlda_t;
32
33 #endif
34
35 #endif /* ECPG_SQLDA_H */
36
37 #line 7 "char_array.pgc"
38
39
40
41 #line 1 "regression.h"
42
43
44
45
46
47
48 #line 9 "char_array.pgc"
49
50
51 static void warn(void)
52 {
53 fprintf(stderr, "Warning: At least one column was truncated\n");
54 }
55
56 /* Compatible handling of char array to retrieve varchar field to char array
57 should be fixed-length, blank-padded, then null-terminated.
58 Conforms to the ANSI Fixed Character type. */
59
60 int main() {
61
62 /* exec sql whenever sql_warning do warn ( ) ; */
63 #line 22 "char_array.pgc"
64
65 /* exec sql whenever sqlerror stop ; */
66 #line 23 "char_array.pgc"
67
68
69 const char *ppppp = "XXXXX";
70 int loopcount;
71 sqlda_t *sqlda = NULL;
72
73 /* exec sql begin declare section */
74
75
76
77
78
79 #line 30 "char_array.pgc"
80 char shortstr [ 5 ] ;
81
82 #line 31 "char_array.pgc"
83 char bigstr [ 11 ] ;
84
85 #line 32 "char_array.pgc"
86 short shstr_ind = 0 ;
87
88 #line 33 "char_array.pgc"
89 short bigstr_ind = 0 ;
90 /* exec sql end declare section */
91 #line 34 "char_array.pgc"
92
93
94 ECPGdebug(1, stderr);
95 { ECPGconnect(__LINE__, 3, "ecpg1_regression" , NULL, NULL , NULL, 0);
96 #line 37 "char_array.pgc"
97
98 if (sqlca.sqlwarn[0] == 'W') warn ( );
99 #line 37 "char_array.pgc"
100
101 if (sqlca.sqlcode < 0) exit (1);}
102 #line 37 "char_array.pgc"
103
104
105 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "create table strdbase ( strval varchar ( 10 ) )", ECPGt_EOIT, ECPGt_EORT);
106 #line 39 "char_array.pgc"
107
108 if (sqlca.sqlwarn[0] == 'W') warn ( );
109 #line 39 "char_array.pgc"
110
111 if (sqlca.sqlcode < 0) exit (1);}
112 #line 39 "char_array.pgc"
113
114 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( '' )", ECPGt_EOIT, ECPGt_EORT);
115 #line 40 "char_array.pgc"
116
117 if (sqlca.sqlwarn[0] == 'W') warn ( );
118 #line 40 "char_array.pgc"
119
120 if (sqlca.sqlcode < 0) exit (1);}
121 #line 40 "char_array.pgc"
122
123 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'AB' )", ECPGt_EOIT, ECPGt_EORT);
124 #line 41 "char_array.pgc"
125
126 if (sqlca.sqlwarn[0] == 'W') warn ( );
127 #line 41 "char_array.pgc"
128
129 if (sqlca.sqlcode < 0) exit (1);}
130 #line 41 "char_array.pgc"
131
132 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'ABCD' )", ECPGt_EOIT, ECPGt_EORT);
133 #line 42 "char_array.pgc"
134
135 if (sqlca.sqlwarn[0] == 'W') warn ( );
136 #line 42 "char_array.pgc"
137
138 if (sqlca.sqlcode < 0) exit (1);}
139 #line 42 "char_array.pgc"
140
141 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'ABCDE' )", ECPGt_EOIT, ECPGt_EORT);
142 #line 43 "char_array.pgc"
143
144 if (sqlca.sqlwarn[0] == 'W') warn ( );
145 #line 43 "char_array.pgc"
146
147 if (sqlca.sqlcode < 0) exit (1);}
148 #line 43 "char_array.pgc"
149
150 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'ABCDEF' )", ECPGt_EOIT, ECPGt_EORT);
151 #line 44 "char_array.pgc"
152
153 if (sqlca.sqlwarn[0] == 'W') warn ( );
154 #line 44 "char_array.pgc"
155
156 if (sqlca.sqlcode < 0) exit (1);}
157 #line 44 "char_array.pgc"
158
159 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'ABCDEFGHIJ' )", ECPGt_EOIT, ECPGt_EORT);
160 #line 45 "char_array.pgc"
161
162 if (sqlca.sqlwarn[0] == 'W') warn ( );
163 #line 45 "char_array.pgc"
164
165 if (sqlca.sqlcode < 0) exit (1);}
166 #line 45 "char_array.pgc"
167
168
169 /* declare C cursor for select strval , strval from strdbase */
170 #line 47 "char_array.pgc"
171
172 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "declare C cursor for select strval , strval from strdbase", ECPGt_EOIT, ECPGt_EORT);
173 #line 48 "char_array.pgc"
174
175 if (sqlca.sqlwarn[0] == 'W') warn ( );
176 #line 48 "char_array.pgc"
177
178 if (sqlca.sqlcode < 0) exit (1);}
179 #line 48 "char_array.pgc"
180
181
182 /* exec sql whenever not found break ; */
183 #line 50 "char_array.pgc"
184
185
186 printf("Full Str. : Short Ind.\n");
187 for (loopcount = 0; loopcount < 100; loopcount++) {
188 strncpy(shortstr, ppppp, sizeof shortstr);
189 memset(bigstr, 0, sizeof bigstr);
190 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "fetch C", ECPGt_EOIT,
191 ECPGt_char,(bigstr),(long)11,(long)1,(11)*sizeof(char),
192 ECPGt_short,&(bigstr_ind),(long)1,(long)1,sizeof(short),
193 ECPGt_char,(shortstr),(long)5,(long)1,(5)*sizeof(char),
194 ECPGt_short,&(shstr_ind),(long)1,(long)1,sizeof(short), ECPGt_EORT);
195 #line 56 "char_array.pgc"
196
197 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
198 #line 56 "char_array.pgc"
199
200 if (sqlca.sqlwarn[0] == 'W') warn ( );
201 #line 56 "char_array.pgc"
202
203 if (sqlca.sqlcode < 0) exit (1);}
204 #line 56 "char_array.pgc"
205
206 printf("\"%s\": \"%s\" %d\n", bigstr, shortstr, shstr_ind);
207 }
208
209 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "close C", ECPGt_EOIT, ECPGt_EORT);
210 #line 60 "char_array.pgc"
211
212 if (sqlca.sqlwarn[0] == 'W') warn ( );
213 #line 60 "char_array.pgc"
214
215 if (sqlca.sqlcode < 0) exit (1);}
216 #line 60 "char_array.pgc"
217
218 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "drop table strdbase", ECPGt_EOIT, ECPGt_EORT);
219 #line 61 "char_array.pgc"
220
221 if (sqlca.sqlwarn[0] == 'W') warn ( );
222 #line 61 "char_array.pgc"
223
224 if (sqlca.sqlcode < 0) exit (1);}
225 #line 61 "char_array.pgc"
226
227 { ECPGtrans(__LINE__, NULL, "commit work");
228 #line 62 "char_array.pgc"
229
230 if (sqlca.sqlwarn[0] == 'W') warn ( );
231 #line 62 "char_array.pgc"
232
233 if (sqlca.sqlcode < 0) exit (1);}
234 #line 62 "char_array.pgc"
235
236
237 /* SQLDA handling */
238 /* exec sql whenever sql_warning sqlprint ; */
239 #line 65 "char_array.pgc"
240
241 /* exec sql whenever not found stop ; */
242 #line 66 "char_array.pgc"
243
244 { ECPGprepare(__LINE__, NULL, 0, "stmt1", "SELECT 123::numeric(3,0), 't'::varchar(2)");
245 #line 67 "char_array.pgc"
246
247 if (sqlca.sqlwarn[0] == 'W') sqlprint();
248 #line 67 "char_array.pgc"
249
250 if (sqlca.sqlcode < 0) exit (1);}
251 #line 67 "char_array.pgc"
252
253 /* declare cur1 cursor for $1 */
254 #line 68 "char_array.pgc"
255
256 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "declare cur1 cursor for $1",
257 ECPGt_char_variable,(ECPGprepared_statement(NULL, "stmt1", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
258 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
259 #line 69 "char_array.pgc"
260
261 if (sqlca.sqlwarn[0] == 'W') sqlprint();
262 #line 69 "char_array.pgc"
263
264 if (sqlca.sqlcode < 0) exit (1);}
265 #line 69 "char_array.pgc"
266
267 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "fetch next from cur1", ECPGt_EOIT,
268 ECPGt_sqlda, &sqlda, 0L, 0L, 0L,
269 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
270 #line 70 "char_array.pgc"
271
272 if (sqlca.sqlcode == ECPG_NOT_FOUND) exit (1);
273 #line 70 "char_array.pgc"
274
275 if (sqlca.sqlwarn[0] == 'W') sqlprint();
276 #line 70 "char_array.pgc"
277
278 if (sqlca.sqlcode < 0) exit (1);}
279 #line 70 "char_array.pgc"
280
281
282 printf("\n-----------------\ntype : data\n");
283 for (int i = 0 ; i < sqlda->sqld ; i++)
284 {
285 sqlvar_t v = sqlda->sqlvar[i];
286 char *sqldata = v.sqldata;
287
288 if (v.sqltype == ECPGt_numeric)
289 sqldata =
290 PGTYPESnumeric_to_asc((numeric*) sqlda->sqlvar[i].sqldata, -1);
291
292 printf("%-8s: \"%s\"\n", v.sqlname.data, sqldata);
293 }
294
295 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "close cur1", ECPGt_EOIT, ECPGt_EORT);
296 #line 85 "char_array.pgc"
297
298 if (sqlca.sqlwarn[0] == 'W') sqlprint();
299 #line 85 "char_array.pgc"
300
301 if (sqlca.sqlcode < 0) exit (1);}
302 #line 85 "char_array.pgc"
303
304 { ECPGtrans(__LINE__, NULL, "commit work");
305 #line 86 "char_array.pgc"
306
307 if (sqlca.sqlwarn[0] == 'W') sqlprint();
308 #line 86 "char_array.pgc"
309
310 if (sqlca.sqlcode < 0) exit (1);}
311 #line 86 "char_array.pgc"
312
313
314 printf("\nGOOD-BYE!!\n\n");
315
316 { ECPGdisconnect(__LINE__, "ALL");
317 #line 90 "char_array.pgc"
318
319 if (sqlca.sqlwarn[0] == 'W') sqlprint();
320 #line 90 "char_array.pgc"
321
322 if (sqlca.sqlcode < 0) exit (1);}
323 #line 90 "char_array.pgc"
324
325
326 return 0;
327 }