| 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[ 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 |
|
| 360 |
/* Test for invalid bytea format */ |
| 361 |
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select '' :: text", ECPGt_EOIT, |
| 362 |
ECPGt_bytea,&(recv_buf[0]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_2), |
| 363 |
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); |
| 364 |
#line 118 "bytea.pgc" |
| 365 |
|
| 366 |
if (sqlca.sqlcode < 0) sqlprint();} |
| 367 |
#line 118 "bytea.pgc" |
| 368 |
|
| 369 |
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select '\\\\a1234' :: text", ECPGt_EOIT, |
| 370 |
ECPGt_bytea,&(recv_buf[0]),(long)DATA_SIZE,(long)1,sizeof(struct bytea_2), |
| 371 |
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); |
| 372 |
#line 119 "bytea.pgc" |
| 373 |
|
| 374 |
if (sqlca.sqlcode < 0) sqlprint();} |
| 375 |
#line 119 "bytea.pgc" |
| 376 |
|
| 377 |
|
| 378 |
{ ECPGtrans(__LINE__, NULL, "commit"); |
| 379 |
#line 121 "bytea.pgc" |
| 380 |
|
| 381 |
if (sqlca.sqlcode < 0) sqlprint();} |
| 382 |
#line 121 "bytea.pgc" |
| 383 |
|
| 384 |
{ ECPGdisconnect(__LINE__, "CURRENT"); |
| 385 |
#line 122 "bytea.pgc" |
| 386 |
|
| 387 |
if (sqlca.sqlcode < 0) sqlprint();} |
| 388 |
#line 122 "bytea.pgc" |
| 389 |
|
| 390 |
|
| 391 |
return 0; |
| 392 |
} |