1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
/* Processed by ecpg (regression mode) */
/* These include files are added by the preprocessor */
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
/* End of automatic include section */
#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
#line 1 "bytea.pgc"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#line 1 "regression.h"
#line 6 "bytea.pgc"
/* exec sql whenever sqlerror sqlprint ; */
#line 7 "bytea.pgc"
static void
dump_binary(char *buf, int len, int ind)
{
int i;
printf("len=%d, ind=%d, data=0x", len, ind);
for (i = 0; i < len; ++i)
printf("%02x", 0xff & buf[i]);
printf("\n");
}
#define DATA_SIZE 0x200
#define LACK_SIZE 13
#
int
main(void)
{
/* exec sql begin declare section */
#line 27 "bytea.pgc"
struct bytea_1 { int len; char arr[ 512 ]; } send_buf [ 2 ] ;
#line 28 "bytea.pgc"
struct bytea_2 { int len; char arr[ DATA_SIZE ]; } recv_buf [ 2 ] ;
#line 29 "bytea.pgc"
struct bytea_3 { int len; char arr[ DATA_SIZE ]; } * recv_vlen_buf ;
#line 30 "bytea.pgc"
struct bytea_4 { int len; char arr[ DATA_SIZE - LACK_SIZE ]; } recv_short_buf ;
#line 31 "bytea.pgc"
int ind [ 2 ] ;
/* exec sql end declare section */
#line 32 "bytea.pgc"
int i, j, c;
#define init() { \
for (i = 0; i < 2; ++i) \
{ \
memset(recv_buf[i].arr, 0x0, sizeof(recv_buf[i].arr)); \
recv_buf[i].len = 0; \
ind[i] = 0; \
} \
recv_vlen_buf = NULL, \
memset(recv_short_buf.arr, 0x0, sizeof(recv_short_buf.arr)); \
} \
while (0)
ECPGdebug(1, stderr);
for (i = 0; i < 2; ++i)
{
for (j = 0, c = 0xff; (c == -1 ? c = 0xff : 1), j < DATA_SIZE; ++j, --c)
send_buf[i].arr[j] = c;
send_buf[i].len = DATA_SIZE;
}
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
#line 57 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 57 "bytea.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table if not exists test ( data1 bytea , data2 bytea )", ECPGt_EOIT, ECPGt_EORT);
#line 59 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 59 "bytea.pgc"
{ ECPGprepare(__LINE__, NULL, 0, "ins_stmt", "insert into test values(?,?)");
#line 61 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 61 "bytea.pgc"
{ ECPGprepare(__LINE__, NULL, 0, "sel_stmt", "select data1,data2 from test");
#line 62 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 62 "bytea.pgc"
ECPGallocate_desc(__LINE__, "idesc");
#line 63 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();
#line 63 "bytea.pgc"
ECPGallocate_desc(__LINE__, "odesc");
#line 64 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();
#line 64 "bytea.pgc"
/* Test for static sql statement with normal host variable, indicator */
init();
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "truncate test", ECPGt_EOIT, ECPGt_EORT);
#line 68 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 68 "bytea.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( $1 , $2 )",
ECPGt_bytea,&(send_buf[0]),(long)512,(long)1,sizeof(struct bytea_1),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_bytea,&(send_buf[1]),(long)512,(long)1,sizeof(struct bytea_1),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 69 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 69 "bytea.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select data1 , data2 from test", ECPGt_EOIT,
ECPGt_bytea,&(recv_buf[0]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_2),
ECPGt_int,&(ind[0]),(long)1,(long)1,sizeof(int),
ECPGt_bytea,&(recv_short_buf),(long)DATA_SIZE - LACK_SIZE,(long)1,sizeof(struct bytea_4),
ECPGt_int,&(ind[1]),(long)1,(long)1,sizeof(int), ECPGt_EORT);
#line 70 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 70 "bytea.pgc"
dump_binary(recv_buf[0].arr, recv_buf[0].len, ind[0]);
dump_binary(recv_short_buf.arr, recv_short_buf.len, ind[1]);
/* Test for cursor */
init();
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "truncate test", ECPGt_EOIT, ECPGt_EORT);
#line 76 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 76 "bytea.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( $1 , $2 )",
ECPGt_bytea,&(send_buf[0]),(long)512,(long)1,sizeof(struct bytea_1),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_bytea,&(send_buf[1]),(long)512,(long)1,sizeof(struct bytea_1),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 77 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 77 "bytea.pgc"
ECPGset_var( 0, &( send_buf[0] ), __LINE__);\
/* declare cursor1 cursor for select data1 from test where data1 = $1 */
#line 78 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();
#line 78 "bytea.pgc"
#line 78 "bytea.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cursor1 cursor for select data1 from test where data1 = $1 ",
ECPGt_bytea,&(send_buf[0]),(long)512,(long)1,sizeof(struct bytea_1),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 79 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 79 "bytea.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cursor1", ECPGt_EOIT,
ECPGt_bytea,&(recv_buf[0]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_2),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 80 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 80 "bytea.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cursor1", ECPGt_EOIT, ECPGt_EORT);
#line 81 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 81 "bytea.pgc"
{ ECPGdeallocate(__LINE__, 0, NULL, "cursor1");
#line 82 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 82 "bytea.pgc"
dump_binary(recv_buf[0].arr, recv_buf[0].len, 0);
/* Test for variable length array */
init();
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "truncate test", ECPGt_EOIT, ECPGt_EORT);
#line 87 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 87 "bytea.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( $1 , $2 )",
ECPGt_bytea,&(send_buf[0]),(long)512,(long)1,sizeof(struct bytea_1),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_bytea,&(send_buf[1]),(long)512,(long)1,sizeof(struct bytea_1),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 88 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 88 "bytea.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( $1 , $2 )",
ECPGt_bytea,&(send_buf[0]),(long)512,(long)1,sizeof(struct bytea_1),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_bytea,&(send_buf[1]),(long)512,(long)1,sizeof(struct bytea_1),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 89 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 89 "bytea.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select data1 from test", ECPGt_EOIT,
ECPGt_bytea,&(recv_vlen_buf),(long)DATA_SIZE,(long)0,sizeof(struct bytea_3),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 90 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 90 "bytea.pgc"
dump_binary(recv_vlen_buf[0].arr, recv_vlen_buf[0].len, 0);
dump_binary(recv_vlen_buf[1].arr, recv_vlen_buf[1].len, 0);
free(recv_vlen_buf);
/* Test for dynamic sql statement with normal host variable, indicator */
init();
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "truncate test", ECPGt_EOIT, ECPGt_EORT);
#line 97 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 97 "bytea.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "ins_stmt",
ECPGt_bytea,&(send_buf[0]),(long)512,(long)1,sizeof(struct bytea_1),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_bytea,&(send_buf[1]),(long)512,(long)1,sizeof(struct bytea_1),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 98 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 98 "bytea.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "sel_stmt", ECPGt_EOIT,
ECPGt_bytea,&(recv_buf[0]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_2),
ECPGt_int,&(ind[0]),(long)1,(long)1,sizeof(int),
ECPGt_bytea,&(recv_short_buf),(long)DATA_SIZE - LACK_SIZE,(long)1,sizeof(struct bytea_4),
ECPGt_int,&(ind[1]),(long)1,(long)1,sizeof(int), ECPGt_EORT);
#line 99 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 99 "bytea.pgc"
dump_binary(recv_buf[0].arr, recv_buf[0].len, ind[0]);
dump_binary(recv_short_buf.arr, recv_short_buf.len, ind[1]);
/* Test for dynamic sql statement with sql descriptor */
init();
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "truncate test", ECPGt_EOIT, ECPGt_EORT);
#line 105 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 105 "bytea.pgc"
{ ECPGset_desc(__LINE__, "idesc", 1,ECPGd_data,
ECPGt_bytea,&(send_buf[0]),(long)512,(long)1,sizeof(struct bytea_1), ECPGd_EODT);
#line 106 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 106 "bytea.pgc"
{ ECPGset_desc(__LINE__, "idesc", 2,ECPGd_data,
ECPGt_bytea,&(send_buf[1]),(long)512,(long)1,sizeof(struct bytea_1), ECPGd_EODT);
#line 107 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 107 "bytea.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "ins_stmt",
ECPGt_descriptor, "idesc", 1L, 1L, 1L,
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 108 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 108 "bytea.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "sel_stmt", ECPGt_EOIT,
ECPGt_descriptor, "odesc", 1L, 1L, 1L,
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 109 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 109 "bytea.pgc"
{ ECPGget_desc(__LINE__, "odesc", 1,ECPGd_indicator,
ECPGt_int,&(ind[0]),(long)1,(long)1,sizeof(int), ECPGd_data,
ECPGt_bytea,&(recv_buf[0]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_2), ECPGd_EODT);
#line 110 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 110 "bytea.pgc"
{ ECPGget_desc(__LINE__, "odesc", 2,ECPGd_indicator,
ECPGt_int,&(ind[1]),(long)1,(long)1,sizeof(int), ECPGd_data,
ECPGt_bytea,&(recv_short_buf),(long)DATA_SIZE - LACK_SIZE,(long)1,sizeof(struct bytea_4), ECPGd_EODT);
#line 111 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 111 "bytea.pgc"
dump_binary(recv_buf[0].arr, recv_buf[0].len, ind[0]);
dump_binary(recv_short_buf.arr, recv_short_buf.len, ind[1]);
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
#line 115 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 115 "bytea.pgc"
{ ECPGtrans(__LINE__, NULL, "commit");
#line 116 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 116 "bytea.pgc"
{ ECPGdisconnect(__LINE__, "CURRENT");
#line 117 "bytea.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 117 "bytea.pgc"
return 0;
}
|