PostgreSQL Source Code  git master
sql-bytea.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
Include dependency graph for sql-bytea.c:

Go to the source code of this file.

Macros

#define ECPGdebug(X, Y)   ECPGdebug((X)+100,(Y))
 
#define DATA_SIZE   0x200
 
#define LACK_SIZE   13
 
#define init()
 

Functions

static void dump_binary (char *buf, int len, int ind)
 
int main (void)
 

Macro Definition Documentation

◆ DATA_SIZE

#define DATA_SIZE   0x200

Definition at line 40 of file sql-bytea.c.

◆ ECPGdebug

#define ECPGdebug (   X,
 
)    ECPGdebug((X)+100,(Y))

Definition at line 7 of file sql-bytea.c.

◆ init

#define init ( )
Value:
{ \
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)
int i
Definition: isn.c:72

◆ LACK_SIZE

#define LACK_SIZE   13

Definition at line 41 of file sql-bytea.c.

Function Documentation

◆ dump_binary()

static void dump_binary ( char *  buf,
int  len,
int  ind 
)
static

Definition at line 30 of file sql-bytea.c.

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 }
const void size_t len
static char * buf
Definition: pg_test_fsync.c:72
#define printf(...)
Definition: port.h:244

References buf, i, len, and printf.

Referenced by main().

◆ main()

int main ( void  )

Definition at line 44 of file sql-bytea.c.

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[ 512 ]; } 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)512,(long)1,sizeof(struct bytea_1),
143  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
144  ECPGt_bytea,&(send_buf[1]),(long)512,(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 cursor */
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)512,(long)1,sizeof(struct bytea_1),
174  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
175  ECPGt_bytea,&(send_buf[1]),(long)512,(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  ECPGset_var( 0, &( send_buf[0] ), __LINE__);\
183  /* declare cursor1 cursor for select data1 from test where data1 = $1 */
184 #line 78 "bytea.pgc"
185 
186 if (sqlca.sqlcode < 0) sqlprint();
187 #line 78 "bytea.pgc"
188 
189 #line 78 "bytea.pgc"
190 
191  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cursor1 cursor for select data1 from test where data1 = $1 ",
192  ECPGt_bytea,&(send_buf[0]),(long)512,(long)1,sizeof(struct bytea_1),
193  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
194 #line 79 "bytea.pgc"
195 
196 if (sqlca.sqlcode < 0) sqlprint();}
197 #line 79 "bytea.pgc"
198 
199  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cursor1", ECPGt_EOIT,
200  ECPGt_bytea,&(recv_buf[0]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_2),
201  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
202 #line 80 "bytea.pgc"
203 
204 if (sqlca.sqlcode < 0) sqlprint();}
205 #line 80 "bytea.pgc"
206 
207  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cursor1", ECPGt_EOIT, ECPGt_EORT);
208 #line 81 "bytea.pgc"
209 
210 if (sqlca.sqlcode < 0) sqlprint();}
211 #line 81 "bytea.pgc"
212 
213  { ECPGdeallocate(__LINE__, 0, NULL, "cursor1");
214 #line 82 "bytea.pgc"
215 
216 if (sqlca.sqlcode < 0) sqlprint();}
217 #line 82 "bytea.pgc"
218 
219  dump_binary(recv_buf[0].arr, recv_buf[0].len, 0);
220 
221  /* Test for variable length array */
222  init();
223  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "truncate test", ECPGt_EOIT, ECPGt_EORT);
224 #line 87 "bytea.pgc"
225 
226 if (sqlca.sqlcode < 0) sqlprint();}
227 #line 87 "bytea.pgc"
228 
229  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( $1 , $2 )",
230  ECPGt_bytea,&(send_buf[0]),(long)512,(long)1,sizeof(struct bytea_1),
231  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
232  ECPGt_bytea,&(send_buf[1]),(long)512,(long)1,sizeof(struct bytea_1),
233  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
234 #line 88 "bytea.pgc"
235 
236 if (sqlca.sqlcode < 0) sqlprint();}
237 #line 88 "bytea.pgc"
238 
239  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( $1 , $2 )",
240  ECPGt_bytea,&(send_buf[0]),(long)512,(long)1,sizeof(struct bytea_1),
241  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
242  ECPGt_bytea,&(send_buf[1]),(long)512,(long)1,sizeof(struct bytea_1),
243  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
244 #line 89 "bytea.pgc"
245 
246 if (sqlca.sqlcode < 0) sqlprint();}
247 #line 89 "bytea.pgc"
248 
249  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select data1 from test", ECPGt_EOIT,
250  ECPGt_bytea,&(recv_vlen_buf),(long)DATA_SIZE,(long)0,sizeof(struct bytea_3),
251  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
252 #line 90 "bytea.pgc"
253 
254 if (sqlca.sqlcode < 0) sqlprint();}
255 #line 90 "bytea.pgc"
256 
257  dump_binary(recv_vlen_buf[0].arr, recv_vlen_buf[0].len, 0);
258  dump_binary(recv_vlen_buf[1].arr, recv_vlen_buf[1].len, 0);
259  free(recv_vlen_buf);
260 
261  /* Test for dynamic sql statement with normal host variable, indicator */
262  init();
263  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "truncate test", ECPGt_EOIT, ECPGt_EORT);
264 #line 97 "bytea.pgc"
265 
266 if (sqlca.sqlcode < 0) sqlprint();}
267 #line 97 "bytea.pgc"
268 
269  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "ins_stmt",
270  ECPGt_bytea,&(send_buf[0]),(long)512,(long)1,sizeof(struct bytea_1),
271  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
272  ECPGt_bytea,&(send_buf[1]),(long)512,(long)1,sizeof(struct bytea_1),
273  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
274 #line 98 "bytea.pgc"
275 
276 if (sqlca.sqlcode < 0) sqlprint();}
277 #line 98 "bytea.pgc"
278 
279  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "sel_stmt", ECPGt_EOIT,
280  ECPGt_bytea,&(recv_buf[0]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_2),
281  ECPGt_int,&(ind[0]),(long)1,(long)1,sizeof(int),
282  ECPGt_bytea,&(recv_short_buf),(long)DATA_SIZE - LACK_SIZE,(long)1,sizeof(struct bytea_4),
283  ECPGt_int,&(ind[1]),(long)1,(long)1,sizeof(int), ECPGt_EORT);
284 #line 99 "bytea.pgc"
285 
286 if (sqlca.sqlcode < 0) sqlprint();}
287 #line 99 "bytea.pgc"
288 
289  dump_binary(recv_buf[0].arr, recv_buf[0].len, ind[0]);
290  dump_binary(recv_short_buf.arr, recv_short_buf.len, ind[1]);
291 
292  /* Test for dynamic sql statement with sql descriptor */
293  init();
294  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "truncate test", ECPGt_EOIT, ECPGt_EORT);
295 #line 105 "bytea.pgc"
296 
297 if (sqlca.sqlcode < 0) sqlprint();}
298 #line 105 "bytea.pgc"
299 
300  { ECPGset_desc(__LINE__, "idesc", 1,ECPGd_data,
301  ECPGt_bytea,&(send_buf[0]),(long)512,(long)1,sizeof(struct bytea_1), ECPGd_EODT);
302 
303 #line 106 "bytea.pgc"
304 
305 if (sqlca.sqlcode < 0) sqlprint();}
306 #line 106 "bytea.pgc"
307 
308  { ECPGset_desc(__LINE__, "idesc", 2,ECPGd_data,
309  ECPGt_bytea,&(send_buf[1]),(long)512,(long)1,sizeof(struct bytea_1), ECPGd_EODT);
310 
311 #line 107 "bytea.pgc"
312 
313 if (sqlca.sqlcode < 0) sqlprint();}
314 #line 107 "bytea.pgc"
315 
316  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "ins_stmt",
317  ECPGt_descriptor, "idesc", 1L, 1L, 1L,
318  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
319 #line 108 "bytea.pgc"
320 
321 if (sqlca.sqlcode < 0) sqlprint();}
322 #line 108 "bytea.pgc"
323 
324  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "sel_stmt", ECPGt_EOIT,
325  ECPGt_descriptor, "odesc", 1L, 1L, 1L,
326  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
327 #line 109 "bytea.pgc"
328 
329 if (sqlca.sqlcode < 0) sqlprint();}
330 #line 109 "bytea.pgc"
331 
332  { ECPGget_desc(__LINE__, "odesc", 1,ECPGd_indicator,
333  ECPGt_int,&(ind[0]),(long)1,(long)1,sizeof(int), ECPGd_data,
334  ECPGt_bytea,&(recv_buf[0]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_2), ECPGd_EODT);
335 
336 #line 110 "bytea.pgc"
337 
338 if (sqlca.sqlcode < 0) sqlprint();}
339 #line 110 "bytea.pgc"
340 
341  { ECPGget_desc(__LINE__, "odesc", 2,ECPGd_indicator,
342  ECPGt_int,&(ind[1]),(long)1,(long)1,sizeof(int), ECPGd_data,
343  ECPGt_bytea,&(recv_short_buf),(long)DATA_SIZE - LACK_SIZE,(long)1,sizeof(struct bytea_4), ECPGd_EODT);
344 
345 #line 111 "bytea.pgc"
346 
347 if (sqlca.sqlcode < 0) sqlprint();}
348 #line 111 "bytea.pgc"
349 
350  dump_binary(recv_buf[0].arr, recv_buf[0].len, ind[0]);
351  dump_binary(recv_short_buf.arr, recv_short_buf.len, ind[1]);
352 
353  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
354 #line 115 "bytea.pgc"
355 
356 if (sqlca.sqlcode < 0) sqlprint();}
357 #line 115 "bytea.pgc"
358 
359  { ECPGtrans(__LINE__, NULL, "commit");
360 #line 116 "bytea.pgc"
361 
362 if (sqlca.sqlcode < 0) sqlprint();}
363 #line 116 "bytea.pgc"
364 
365  { ECPGdisconnect(__LINE__, "CURRENT");
366 #line 117 "bytea.pgc"
367 
368 if (sqlca.sqlcode < 0) sqlprint();}
369 #line 117 "bytea.pgc"
370 
371 
372  return 0;
373 }
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:676
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition: connect.c:255
bool ECPGget_desc(int lineno, const char *desc_name, int index,...)
Definition: descriptor.c:234
bool ECPGallocate_desc(int line, const char *name)
Definition: descriptor.c:792
bool ECPGset_desc(int lineno, const char *desc_name, int index,...)
Definition: descriptor.c:605
@ ECPGst_normal
Definition: ecpgtype.h:97
@ ECPGst_execute
Definition: ecpgtype.h:98
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_bytea
Definition: ecpgtype.h:67
@ ECPGt_int
Definition: ecpgtype.h:44
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_EORT
Definition: ecpgtype.h:63
@ ECPGt_descriptor
Definition: ecpgtype.h:59
@ ECPGd_indicator
Definition: ecpgtype.h:77
@ ECPGd_EODT
Definition: ecpgtype.h:88
@ ECPGd_data
Definition: ecpgtype.h:74
void sqlprint(void)
Definition: error.c:334
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:2275
#define free(a)
Definition: header.h:65
void ECPGset_var(int number, void *pointer, int lineno)
Definition: misc.c:538
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:160
bool ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
Definition: prepare.c:217
bool ECPGdeallocate(int lineno, int c, const char *connection_name, const char *name)
Definition: prepare.c:315
int j
Definition: isn.c:73
char * c
static void dump_binary(char *buf, int len, int ind)
Definition: sql-bytea.c:30
#define LACK_SIZE
Definition: sql-bytea.c:41
#define init()
#define ECPGdebug(X, Y)
Definition: sql-bytea.c:7
#define DATA_SIZE
Definition: sql-bytea.c:40
#define sqlca
Definition: sqlca.h:59

References DATA_SIZE, dump_binary(), ECPGallocate_desc(), ECPGconnect(), ECPGd_data, ECPGd_EODT, ECPGd_indicator, ECPGdeallocate(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGget_desc(), ECPGprepare(), ECPGset_desc(), ECPGset_var(), ECPGst_execute, ECPGst_normal, ECPGt_bytea, ECPGt_descriptor, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_NO_INDICATOR, ECPGtrans(), free, i, init, j, LACK_SIZE, len, sqlca, and sqlprint().