PostgreSQL Source Code  git master
sql-bytea.c
Go to the documentation of this file.
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 "bytea.pgc"
10 #include <stdlib.h>
11 #include <string.h>
12 #include <stdio.h>
13 #include <time.h>
14 
15 
16 #line 1 "regression.h"
17 
18 
19 
20 
21 
22 
23 #line 6 "bytea.pgc"
24 
25 /* exec sql whenever sqlerror sqlprint ; */
26 #line 7 "bytea.pgc"
27 
28 
29 static void
30 dump_binary(char *buf, int len, int ind)
31 {
32  int i;
33 
34  printf("len=%d, ind=%d, data=0x", len, ind);
35  for (i = 0; i < len; ++i)
36  printf("%02x", 0xff & buf[i]);
37  printf("\n");
38 }
39 
40 #define DATA_SIZE 0x200
41 #define LACK_SIZE 13
42 #
43 int
44 main(void)
45 {
46 /* exec sql begin declare section */
47 
48 
49 
50 
51 
52 
53 #line 27 "bytea.pgc"
54  struct bytea_1 { int len; char arr[ DATA_SIZE ]; } send_buf [ 2 ] ;
55 
56 #line 28 "bytea.pgc"
57  struct bytea_2 { int len; char arr[ DATA_SIZE ]; } recv_buf [ 2 ] ;
58 
59 #line 29 "bytea.pgc"
60  struct bytea_3 { int len; char arr[ DATA_SIZE ]; } * recv_vlen_buf ;
61 
62 #line 30 "bytea.pgc"
63  struct bytea_4 { int len; char arr[ DATA_SIZE - LACK_SIZE ]; } recv_short_buf ;
64 
65 #line 31 "bytea.pgc"
66  int ind [ 2 ] ;
67 /* exec sql end declare section */
68 #line 32 "bytea.pgc"
69 
70  int i, j, c;
71 
72 #define init() { \
73  for (i = 0; i < 2; ++i) \
74  { \
75  memset(recv_buf[i].arr, 0x0, sizeof(recv_buf[i].arr)); \
76  recv_buf[i].len = 0; \
77  ind[i] = 0; \
78  } \
79  recv_vlen_buf = NULL, \
80  memset(recv_short_buf.arr, 0x0, sizeof(recv_short_buf.arr)); \
81 } \
82 while (0)
83 
84  ECPGdebug(1, stderr);
85 
86  for (i = 0; i < 2; ++i)
87  {
88  for (j = 0, c = 0xff; (c == -1 ? c = 0xff : 1), j < DATA_SIZE; ++j, --c)
89  send_buf[i].arr[j] = c;
90 
91  send_buf[i].len = DATA_SIZE;
92  }
93 
94  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
95 #line 57 "bytea.pgc"
96 
97 if (sqlca.sqlcode < 0) sqlprint();}
98 #line 57 "bytea.pgc"
99 
100 
101  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table if not exists test ( data1 bytea , data2 bytea )", ECPGt_EOIT, ECPGt_EORT);
102 #line 59 "bytea.pgc"
103 
104 if (sqlca.sqlcode < 0) sqlprint();}
105 #line 59 "bytea.pgc"
106 
107 
108  { ECPGprepare(__LINE__, NULL, 0, "ins_stmt", "insert into test values(?,?)");
109 #line 61 "bytea.pgc"
110 
111 if (sqlca.sqlcode < 0) sqlprint();}
112 #line 61 "bytea.pgc"
113 
114  { ECPGprepare(__LINE__, NULL, 0, "sel_stmt", "select data1,data2 from test");
115 #line 62 "bytea.pgc"
116 
117 if (sqlca.sqlcode < 0) sqlprint();}
118 #line 62 "bytea.pgc"
119 
120  ECPGallocate_desc(__LINE__, "idesc");
121 #line 63 "bytea.pgc"
122 
123 if (sqlca.sqlcode < 0) sqlprint();
124 #line 63 "bytea.pgc"
125 
126  ECPGallocate_desc(__LINE__, "odesc");
127 #line 64 "bytea.pgc"
128 
129 if (sqlca.sqlcode < 0) sqlprint();
130 #line 64 "bytea.pgc"
131 
132 
133  /* Test for static sql statement with normal host variable, indicator */
134  init();
135  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "truncate test", ECPGt_EOIT, ECPGt_EORT);
136 #line 68 "bytea.pgc"
137 
138 if (sqlca.sqlcode < 0) sqlprint();}
139 #line 68 "bytea.pgc"
140 
141  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( $1 , $2 )",
142  ECPGt_bytea,&(send_buf[0]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_1),
143  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
144  ECPGt_bytea,&(send_buf[1]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_1),
145  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
146 #line 69 "bytea.pgc"
147 
148 if (sqlca.sqlcode < 0) sqlprint();}
149 #line 69 "bytea.pgc"
150 
151  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select data1 , data2 from test", ECPGt_EOIT,
152  ECPGt_bytea,&(recv_buf[0]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_2),
153  ECPGt_int,&(ind[0]),(long)1,(long)1,sizeof(int),
154  ECPGt_bytea,&(recv_short_buf),(long)DATA_SIZE - LACK_SIZE,(long)1,sizeof(struct bytea_4),
155  ECPGt_int,&(ind[1]),(long)1,(long)1,sizeof(int), ECPGt_EORT);
156 #line 70 "bytea.pgc"
157 
158 if (sqlca.sqlcode < 0) sqlprint();}
159 #line 70 "bytea.pgc"
160 
161  dump_binary(recv_buf[0].arr, recv_buf[0].len, ind[0]);
162  dump_binary(recv_short_buf.arr, recv_short_buf.len, ind[1]);
163 
164  /* Test for variable length array */
165  init();
166  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "truncate test", ECPGt_EOIT, ECPGt_EORT);
167 #line 76 "bytea.pgc"
168 
169 if (sqlca.sqlcode < 0) sqlprint();}
170 #line 76 "bytea.pgc"
171 
172  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( $1 , $2 )",
173  ECPGt_bytea,&(send_buf[0]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_1),
174  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
175  ECPGt_bytea,&(send_buf[1]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_1),
176  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
177 #line 77 "bytea.pgc"
178 
179 if (sqlca.sqlcode < 0) sqlprint();}
180 #line 77 "bytea.pgc"
181 
182  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( $1 , $2 )",
183  ECPGt_bytea,&(send_buf[0]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_1),
184  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
185  ECPGt_bytea,&(send_buf[1]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_1),
186  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
187 #line 78 "bytea.pgc"
188 
189 if (sqlca.sqlcode < 0) sqlprint();}
190 #line 78 "bytea.pgc"
191 
192  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select data1 from test", ECPGt_EOIT,
193  ECPGt_bytea,&(recv_vlen_buf),(long)DATA_SIZE,(long)0,sizeof(struct bytea_3),
194  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
195 #line 79 "bytea.pgc"
196 
197 if (sqlca.sqlcode < 0) sqlprint();}
198 #line 79 "bytea.pgc"
199 
200  dump_binary(recv_vlen_buf[0].arr, recv_vlen_buf[0].len, 0);
201  dump_binary(recv_vlen_buf[1].arr, recv_vlen_buf[1].len, 0);
202  free(recv_vlen_buf);
203 
204  /* Test for dynamic sql statement with normal host variable, indicator */
205  init();
206  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "truncate test", ECPGt_EOIT, ECPGt_EORT);
207 #line 86 "bytea.pgc"
208 
209 if (sqlca.sqlcode < 0) sqlprint();}
210 #line 86 "bytea.pgc"
211 
212  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "ins_stmt",
213  ECPGt_bytea,&(send_buf[0]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_1),
214  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
215  ECPGt_bytea,&(send_buf[1]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_1),
216  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
217 #line 87 "bytea.pgc"
218 
219 if (sqlca.sqlcode < 0) sqlprint();}
220 #line 87 "bytea.pgc"
221 
222  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "sel_stmt", ECPGt_EOIT,
223  ECPGt_bytea,&(recv_buf[0]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_2),
224  ECPGt_int,&(ind[0]),(long)1,(long)1,sizeof(int),
225  ECPGt_bytea,&(recv_short_buf),(long)DATA_SIZE - LACK_SIZE,(long)1,sizeof(struct bytea_4),
226  ECPGt_int,&(ind[1]),(long)1,(long)1,sizeof(int), ECPGt_EORT);
227 #line 88 "bytea.pgc"
228 
229 if (sqlca.sqlcode < 0) sqlprint();}
230 #line 88 "bytea.pgc"
231 
232  dump_binary(recv_buf[0].arr, recv_buf[0].len, ind[0]);
233  dump_binary(recv_short_buf.arr, recv_short_buf.len, ind[1]);
234 
235  /* Test for dynamic sql statement with sql descriptor */
236  init();
237  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "truncate test", ECPGt_EOIT, ECPGt_EORT);
238 #line 94 "bytea.pgc"
239 
240 if (sqlca.sqlcode < 0) sqlprint();}
241 #line 94 "bytea.pgc"
242 
243  { ECPGset_desc(__LINE__, "idesc", 1,ECPGd_data,
244  ECPGt_bytea,&(send_buf[0]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_1), ECPGd_EODT);
245 
246 #line 95 "bytea.pgc"
247 
248 if (sqlca.sqlcode < 0) sqlprint();}
249 #line 95 "bytea.pgc"
250 
251  { ECPGset_desc(__LINE__, "idesc", 2,ECPGd_data,
252  ECPGt_bytea,&(send_buf[1]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_1), ECPGd_EODT);
253 
254 #line 96 "bytea.pgc"
255 
256 if (sqlca.sqlcode < 0) sqlprint();}
257 #line 96 "bytea.pgc"
258 
259  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "ins_stmt",
260  ECPGt_descriptor, "idesc", 1L, 1L, 1L,
261  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
262 #line 97 "bytea.pgc"
263 
264 if (sqlca.sqlcode < 0) sqlprint();}
265 #line 97 "bytea.pgc"
266 
267  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "sel_stmt", ECPGt_EOIT,
268  ECPGt_descriptor, "odesc", 1L, 1L, 1L,
269  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
270 #line 98 "bytea.pgc"
271 
272 if (sqlca.sqlcode < 0) sqlprint();}
273 #line 98 "bytea.pgc"
274 
275  { ECPGget_desc(__LINE__, "odesc", 1,ECPGd_indicator,
276  ECPGt_int,&(ind[0]),(long)1,(long)1,sizeof(int), ECPGd_data,
277  ECPGt_bytea,&(recv_buf[0]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_2), ECPGd_EODT);
278 
279 #line 99 "bytea.pgc"
280 
281 if (sqlca.sqlcode < 0) sqlprint();}
282 #line 99 "bytea.pgc"
283 
284  { ECPGget_desc(__LINE__, "odesc", 2,ECPGd_indicator,
285  ECPGt_int,&(ind[1]),(long)1,(long)1,sizeof(int), ECPGd_data,
286  ECPGt_bytea,&(recv_short_buf),(long)DATA_SIZE - LACK_SIZE,(long)1,sizeof(struct bytea_4), ECPGd_EODT);
287 
288 #line 100 "bytea.pgc"
289 
290 if (sqlca.sqlcode < 0) sqlprint();}
291 #line 100 "bytea.pgc"
292 
293  dump_binary(recv_buf[0].arr, recv_buf[0].len, ind[0]);
294  dump_binary(recv_short_buf.arr, recv_short_buf.len, ind[1]);
295 
296  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
297 #line 104 "bytea.pgc"
298 
299 if (sqlca.sqlcode < 0) sqlprint();}
300 #line 104 "bytea.pgc"
301 
302  { ECPGtrans(__LINE__, NULL, "commit");
303 #line 105 "bytea.pgc"
304 
305 if (sqlca.sqlcode < 0) sqlprint();}
306 #line 105 "bytea.pgc"
307 
308  { ECPGdisconnect(__LINE__, "CURRENT");
309 #line 106 "bytea.pgc"
310 
311 if (sqlca.sqlcode < 0) sqlprint();}
312 #line 106 "bytea.pgc"
313 
314 
315  return 0;
316 }
#define ECPGdebug(X, Y)
Definition: sql-bytea.c:7
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:684
bool ECPGallocate_desc(int line, const char *name)
Definition: descriptor.c:802
#define sqlca
Definition: sqlca.h:59
bool ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query,...)
Definition: execute.c:2279
bool ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
Definition: prepare.c:217
#define printf(...)
Definition: port.h:198
#define DATA_SIZE
Definition: sql-bytea.c:40
#define LACK_SIZE
Definition: sql-bytea.c:41
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition: connect.c:271
char * c
static char * buf
Definition: pg_test_fsync.c:68
#define init()
bool ECPGget_desc(int lineno, const char *desc_name, int index,...)
Definition: descriptor.c:246
void sqlprint(void)
Definition: error.c:336
#define free(a)
Definition: header.h:65
int main(void)
Definition: sql-bytea.c:44
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:199
bool ECPGset_desc(int lineno, const char *desc_name, int index,...)
Definition: descriptor.c:612
int i
static void dump_binary(char *buf, int len, int ind)
Definition: sql-bytea.c:30