PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sqlda.c File Reference
#include "postgres_fe.h"
#include "catalog/pg_type_d.h"
#include "decimal.h"
#include "ecpg-pthread-win32.h"
#include "ecpgerrno.h"
#include "ecpglib.h"
#include "ecpglib_extern.h"
#include "ecpgtype.h"
#include "sqlca.h"
#include "sqlda-compat.h"
#include "sqlda-native.h"
Include dependency graph for sqlda.c:

Go to the source code of this file.

Macros

#define POSTGRES_ECPG_INTERNAL
 

Functions

static void ecpg_sqlda_align_add_size (long offset, int alignment, int size, long *current, long *next)
 
static long sqlda_compat_empty_size (const PGresult *res)
 
static long sqlda_common_total_size (const PGresult *res, int row, enum COMPAT_MODE compat, long offset)
 
static long sqlda_compat_total_size (const PGresult *res, int row, enum COMPAT_MODE compat)
 
static long sqlda_native_empty_size (const PGresult *res)
 
static long sqlda_native_total_size (const PGresult *res, int row, enum COMPAT_MODE compat)
 
struct sqlda_compatecpg_build_compat_sqlda (int line, PGresult *res, int row, enum COMPAT_MODE compat)
 
void ecpg_set_compat_sqlda (int lineno, struct sqlda_compat **_sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)
 
struct sqlda_structecpg_build_native_sqlda (int line, PGresult *res, int row, enum COMPAT_MODE compat)
 
void ecpg_set_native_sqlda (int lineno, struct sqlda_struct **_sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)
 

Variables

static int16 value_is_null = -1
 
static int16 value_is_not_null = 0
 

Macro Definition Documentation

◆ POSTGRES_ECPG_INTERNAL

#define POSTGRES_ECPG_INTERNAL

Definition at line 9 of file sqlda.c.

Function Documentation

◆ ecpg_build_compat_sqlda()

struct sqlda_compat * ecpg_build_compat_sqlda ( int  line,
PGresult res,
int  row,
enum COMPAT_MODE  compat 
)

Definition at line 205 of file sqlda.c.

206{
207 struct sqlda_compat *sqlda;
208 struct sqlvar_compat *sqlvar;
209 char *fname;
210 long size;
211 int sqld;
212 int i;
213
215 sqlda = (struct sqlda_compat *) ecpg_alloc(size, line);
216 if (!sqlda)
217 return NULL;
218
219 memset(sqlda, 0, size);
220 sqlvar = (struct sqlvar_compat *) (sqlda + 1);
221 sqld = PQnfields(res);
222 fname = (char *) (sqlvar + sqld);
223
224 sqlda->sqld = sqld;
225 ecpg_log("ecpg_build_compat_sqlda on line %d sqld = %d\n", line, sqld);
226 sqlda->desc_occ = size; /* cheat here, keep the full allocated size */
227 sqlda->sqlvar = sqlvar;
228
229 for (i = 0; i < sqlda->sqld; i++)
230 {
232 strcpy(fname, PQfname(res, i));
233 sqlda->sqlvar[i].sqlname = fname;
234 fname += strlen(sqlda->sqlvar[i].sqlname) + 1;
235
236 /*
237 * this is reserved for future use, so we leave it empty for the time
238 * being
239 */
240 /* sqlda->sqlvar[i].sqlformat = (char *) (long) PQfformat(res, i); */
241 sqlda->sqlvar[i].sqlxid = PQftype(res, i);
242 sqlda->sqlvar[i].sqltypelen = PQfsize(res, i);
243 }
244
245 return sqlda;
246}
enum COMPAT_MODE compat
Definition: ecpg.c:26
char * ecpg_alloc(long size, int lineno)
Definition: memory.c:19
void ecpg_log(const char *format,...) pg_attribute_printf(1
int sqlda_dynamic_type(Oid type, enum COMPAT_MODE compat)
Definition: typename.c:107
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:3719
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:3567
int PQnfields(const PGresult *res)
Definition: fe-exec.c:3489
int PQfsize(const PGresult *res, int field_num)
Definition: fe-exec.c:3730
int i
Definition: isn.c:72
static pg_noinline void Size size
Definition: slab.c:607
static long sqlda_compat_total_size(const PGresult *res, int row, enum COMPAT_MODE compat)
Definition: sqlda.c:157
struct sqlvar_compat * sqlvar
Definition: sqlda-compat.h:40
short desc_occ
Definition: sqlda-compat.h:42
short sqltypelen
Definition: sqlda-compat.h:21
char * sqlname
Definition: sqlda-compat.h:14

References compat, sqlda_compat::desc_occ, ecpg_alloc(), ecpg_log(), i, PQfname(), PQfsize(), PQftype(), PQnfields(), res, size, sqlda_compat::sqld, sqlda_compat_total_size(), sqlda_dynamic_type(), sqlvar_compat::sqlname, sqlvar_compat::sqltype, sqlvar_compat::sqltypelen, sqlda_compat::sqlvar, and sqlvar_compat::sqlxid.

Referenced by ecpg_process_output(), and ECPGdescribe().

◆ ecpg_build_native_sqlda()

struct sqlda_struct * ecpg_build_native_sqlda ( int  line,
PGresult res,
int  row,
enum COMPAT_MODE  compat 
)

Definition at line 412 of file sqlda.c.

413{
414 struct sqlda_struct *sqlda;
415 long size;
416 int i;
417
419 sqlda = (struct sqlda_struct *) ecpg_alloc(size, line);
420 if (!sqlda)
421 return NULL;
422
423 memset(sqlda, 0, size);
424
425 sprintf(sqlda->sqldaid, "SQLDA ");
426 sqlda->sqld = sqlda->sqln = PQnfields(res);
427 ecpg_log("ecpg_build_native_sqlda on line %d sqld = %d\n", line, sqlda->sqld);
428 sqlda->sqldabc = sizeof(struct sqlda_struct) + (sqlda->sqld - 1) * sizeof(struct sqlvar_struct);
429
430 for (i = 0; i < sqlda->sqld; i++)
431 {
432 char *fname;
433
435 fname = PQfname(res, i);
436 sqlda->sqlvar[i].sqlname.length = strlen(fname);
437 strcpy(sqlda->sqlvar[i].sqlname.data, fname);
438 }
439
440 return sqlda;
441}
#define sprintf
Definition: port.h:240
static long sqlda_native_total_size(const PGresult *res, int row, enum COMPAT_MODE compat)
Definition: sqlda.c:186
struct sqlvar_struct sqlvar[1]
Definition: sqlda-native.h:40
char sqldaid[8]
Definition: sqlda-native.h:35
char data[NAMEDATALEN]
Definition: sqlda-native.h:21
short length
Definition: sqlda-native.h:20
struct sqlname sqlname
Definition: sqlda-native.h:30

References compat, sqlname::data, ecpg_alloc(), ecpg_log(), i, sqlname::length, PQfname(), PQftype(), PQnfields(), res, size, sprintf, sqlda_struct::sqld, sqlda_dynamic_type(), sqlda_native_total_size(), sqlda_struct::sqldabc, sqlda_struct::sqldaid, sqlda_struct::sqln, sqlvar_struct::sqlname, sqlvar_struct::sqltype, and sqlda_struct::sqlvar.

Referenced by ecpg_process_output(), and ECPGdescribe().

◆ ecpg_set_compat_sqlda()

void ecpg_set_compat_sqlda ( int  lineno,
struct sqlda_compat **  _sqlda,
const PGresult res,
int  row,
enum COMPAT_MODE  compat 
)

Definition at line 255 of file sqlda.c.

256{
257 struct sqlda_compat *sqlda = (*_sqlda);
258 int i;
259 long offset,
260 next_offset;
261
262 if (row < 0)
263 return;
264
265 /* Offset for the first field value */
267
268 /*
269 * Set sqlvar[i]->sqldata pointers and convert values to correct format
270 */
271 for (i = 0; i < sqlda->sqld; i++)
272 {
273 int isnull;
274 int datalen;
275 bool set_data = true;
276
277 switch (sqlda->sqlvar[i].sqltype)
278 {
279 case ECPGt_short:
281 ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
282 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
283 sqlda->sqlvar[i].sqllen = sizeof(short);
284 break;
285 case ECPGt_int:
287 ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
288 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
289 sqlda->sqlvar[i].sqllen = sizeof(int);
290 break;
291 case ECPGt_long:
293 ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
294 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
295 sqlda->sqlvar[i].sqllen = sizeof(long);
296 break;
297 case ECPGt_long_long:
299 ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
300 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
301 sqlda->sqlvar[i].sqllen = sizeof(long long);
302 break;
303 case ECPGt_bool:
304 ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
305 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
306 sqlda->sqlvar[i].sqllen = sizeof(bool);
307 break;
308 case ECPGt_float:
309 ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
310 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
311 sqlda->sqlvar[i].sqllen = sizeof(float);
312 break;
313 case ECPGt_double:
314 ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
315 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
316 sqlda->sqlvar[i].sqllen = sizeof(double);
317 break;
318 case ECPGt_decimal:
319 ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
320 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
321 sqlda->sqlvar[i].sqllen = sizeof(decimal);
322 break;
323 case ECPGt_numeric:
324 {
325 numeric *num;
326 char *val;
327
328 set_data = false;
329
330 ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
331 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
332 sqlda->sqlvar[i].sqllen = sizeof(numeric);
333
334 if (PQgetisnull(res, row, i))
335 {
337 break;
338 }
339
340 val = PQgetvalue(res, row, i);
341 num = PGTYPESnumeric_from_asc(val, NULL);
342 if (!num)
343 {
345 break;
346 }
347
348 memcpy(sqlda->sqlvar[i].sqldata, num, sizeof(numeric));
349
350 if (num->buf)
351 {
352 ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->digits - num->buf + num->ndigits, &offset, &next_offset);
353 memcpy((char *) sqlda + offset, num->buf, num->digits - num->buf + num->ndigits);
354
355 ((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
356 ((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
357 }
358
360
361 break;
362 }
363 case ECPGt_date:
364 ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
365 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
366 sqlda->sqlvar[i].sqllen = sizeof(date);
367 break;
368 case ECPGt_timestamp:
369 ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
370 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
371 sqlda->sqlvar[i].sqllen = sizeof(timestamp);
372 break;
373 case ECPGt_interval:
374 ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
375 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
376 sqlda->sqlvar[i].sqllen = sizeof(interval);
377 break;
378 case ECPGt_char:
380 case ECPGt_string:
381 default:
382 datalen = strlen(PQgetvalue(res, row, i)) + 1;
383 ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
384 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
385 sqlda->sqlvar[i].sqllen = datalen;
386 if (datalen > 32768)
387 sqlda->sqlvar[i].sqlilongdata = sqlda->sqlvar[i].sqldata;
388 break;
389 }
390
391 isnull = PQgetisnull(res, row, i);
392 ecpg_log("ecpg_set_compat_sqlda on line %d row %d col %d %s\n", lineno, row, i, isnull ? "IS NULL" : "IS NOT NULL");
393 sqlda->sqlvar[i].sqlind = isnull ? &value_is_null : &value_is_not_null;
394 sqlda->sqlvar[i].sqlitype = ECPGt_short;
395 sqlda->sqlvar[i].sqlilen = sizeof(short);
396 if (!isnull)
397 {
398 if (set_data)
399 ecpg_get_data(res, row, i, lineno,
401 sqlda->sqlvar[i].sqldata, NULL, 0, 0, 0,
402 ECPG_ARRAY_NONE, compat, false);
403 }
404 else
406
407 offset = next_offset;
408 }
409}
int16 NumericDigit
Definition: numeric.c:102
Datum numeric(PG_FUNCTION_ARGS)
Definition: numeric.c:1246
int64_t int64
Definition: c.h:485
bool ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, enum ECPGttype type, enum ECPGttype ind_type, char *var, char *ind, long varcharsize, long offset, long ind_offset, enum ARRAY_TYPE isarray, enum COMPAT_MODE compat, bool force_indicator)
Definition: data.c:206
@ ECPG_ARRAY_NONE
@ ECPGt_float
Definition: ecpgtype.h:47
@ ECPGt_long_long
Definition: ecpgtype.h:45
@ ECPGt_short
Definition: ecpgtype.h:43
@ ECPGt_decimal
Definition: ecpgtype.h:51
@ ECPGt_numeric
Definition: ecpgtype.h:49
@ ECPGt_timestamp
Definition: ecpgtype.h:54
@ ECPGt_unsigned_short
Definition: ecpgtype.h:43
@ ECPGt_int
Definition: ecpgtype.h:44
@ ECPGt_long
Definition: ecpgtype.h:44
@ ECPGt_unsigned_char
Definition: ecpgtype.h:43
@ ECPGt_double
Definition: ecpgtype.h:47
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_date
Definition: ecpgtype.h:53
@ ECPGt_interval
Definition: ecpgtype.h:55
@ ECPGt_unsigned_long
Definition: ecpgtype.h:44
@ ECPGt_bool
Definition: ecpgtype.h:46
@ ECPGt_unsigned_long_long
Definition: ecpgtype.h:45
@ ECPGt_unsigned_int
Definition: ecpgtype.h:44
@ ECPGt_char
Definition: ecpgtype.h:43
@ ECPGt_string
Definition: ecpgtype.h:65
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3876
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3901
long val
Definition: informix.c:689
void ECPGset_noind_null(enum ECPGttype type, void *ptr)
Definition: misc.c:292
long date
Definition: pgtypes_date.h:9
void PGTYPESnumeric_free(numeric *var)
Definition: numeric.c:385
numeric * PGTYPESnumeric_from_asc(char *str, char **endptr)
Definition: numeric.c:321
int64 timestamp
static void ecpg_sqlda_align_add_size(long offset, int alignment, int size, long *current, long *next)
Definition: sqlda.c:33
static long sqlda_compat_empty_size(const PGresult *res)
Definition: sqlda.c:45
static int16 value_is_null
Definition: sqlda.c:251
static int16 value_is_not_null
Definition: sqlda.c:252
NumericDigit * digits
NumericDigit * buf
short * sqlind
Definition: sqlda-compat.h:13
char * sqldata
Definition: sqlda-compat.h:12
char * sqlilongdata
Definition: sqlda-compat.h:32

References numeric::buf, compat, numeric::digits, ECPG_ARRAY_NONE, ecpg_get_data(), ecpg_log(), ecpg_sqlda_align_add_size(), ECPGset_noind_null(), ECPGt_bool, ECPGt_char, ECPGt_date, ECPGt_decimal, ECPGt_double, ECPGt_float, ECPGt_int, ECPGt_interval, ECPGt_long, ECPGt_long_long, ECPGt_NO_INDICATOR, ECPGt_numeric, ECPGt_short, ECPGt_string, ECPGt_timestamp, ECPGt_unsigned_char, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, i, numeric::ndigits, numeric(), PGTYPESnumeric_free(), PGTYPESnumeric_from_asc(), PQgetisnull(), PQgetvalue(), res, sqlda_compat::sqld, sqlda_compat_empty_size(), sqlvar_compat::sqldata, sqlvar_compat::sqlilen, sqlvar_compat::sqlilongdata, sqlvar_compat::sqlind, sqlvar_compat::sqlitype, sqlvar_compat::sqllen, sqlvar_compat::sqltype, sqlda_compat::sqlvar, val, value_is_not_null, and value_is_null.

Referenced by ecpg_process_output().

◆ ecpg_set_native_sqlda()

void ecpg_set_native_sqlda ( int  lineno,
struct sqlda_struct **  _sqlda,
const PGresult res,
int  row,
enum COMPAT_MODE  compat 
)

Definition at line 444 of file sqlda.c.

445{
446 struct sqlda_struct *sqlda = (*_sqlda);
447 int i;
448 long offset,
449 next_offset;
450
451 if (row < 0)
452 return;
453
454 /* Offset for the first field value */
456
457 /*
458 * Set sqlvar[i]->sqldata pointers and convert values to correct format
459 */
460 for (i = 0; i < sqlda->sqld; i++)
461 {
462 int isnull;
463 int datalen;
464 bool set_data = true;
465
466 switch (sqlda->sqlvar[i].sqltype)
467 {
468 case ECPGt_short:
470 ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
471 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
472 sqlda->sqlvar[i].sqllen = sizeof(short);
473 break;
474 case ECPGt_int:
476 ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
477 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
478 sqlda->sqlvar[i].sqllen = sizeof(int);
479 break;
480 case ECPGt_long:
482 ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
483 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
484 sqlda->sqlvar[i].sqllen = sizeof(long);
485 break;
486 case ECPGt_long_long:
488 ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
489 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
490 sqlda->sqlvar[i].sqllen = sizeof(long long);
491 break;
492 case ECPGt_bool:
493 ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
494 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
495 sqlda->sqlvar[i].sqllen = sizeof(bool);
496 break;
497 case ECPGt_float:
498 ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
499 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
500 sqlda->sqlvar[i].sqllen = sizeof(float);
501 break;
502 case ECPGt_double:
503 ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
504 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
505 sqlda->sqlvar[i].sqllen = sizeof(double);
506 break;
507 case ECPGt_decimal:
508 ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
509 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
510 sqlda->sqlvar[i].sqllen = sizeof(decimal);
511 break;
512 case ECPGt_numeric:
513 {
514 numeric *num;
515 char *val;
516
517 set_data = false;
518
519 ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
520 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
521 sqlda->sqlvar[i].sqllen = sizeof(numeric);
522
523 if (PQgetisnull(res, row, i))
524 {
526 break;
527 }
528
529 val = PQgetvalue(res, row, i);
530 num = PGTYPESnumeric_from_asc(val, NULL);
531 if (!num)
532 {
534 break;
535 }
536
537 memcpy(sqlda->sqlvar[i].sqldata, num, sizeof(numeric));
538
539 if (num->buf)
540 {
541 ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->digits - num->buf + num->ndigits, &offset, &next_offset);
542 memcpy((char *) sqlda + offset, num->buf, num->digits - num->buf + num->ndigits);
543
544 ((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
545 ((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
546 }
547
549
550 break;
551 }
552 case ECPGt_date:
553 ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
554 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
555 sqlda->sqlvar[i].sqllen = sizeof(date);
556 break;
557 case ECPGt_timestamp:
558 ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
559 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
560 sqlda->sqlvar[i].sqllen = sizeof(timestamp);
561 break;
562 case ECPGt_interval:
563 ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
564 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
565 sqlda->sqlvar[i].sqllen = sizeof(interval);
566 break;
567 case ECPGt_char:
569 case ECPGt_string:
570 default:
571 datalen = strlen(PQgetvalue(res, row, i)) + 1;
572 ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
573 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
574 sqlda->sqlvar[i].sqllen = datalen;
575 break;
576 }
577
578 isnull = PQgetisnull(res, row, i);
579 ecpg_log("ecpg_set_native_sqlda on line %d row %d col %d %s\n", lineno, row, i, isnull ? "IS NULL" : "IS NOT NULL");
580 sqlda->sqlvar[i].sqlind = isnull ? &value_is_null : &value_is_not_null;
581 if (!isnull)
582 {
583 if (set_data)
584 ecpg_get_data(res, row, i, lineno,
586 sqlda->sqlvar[i].sqldata, NULL, 0, 0, 0,
587 ECPG_ARRAY_NONE, compat, false);
588 }
589
590 offset = next_offset;
591 }
592}
static long sqlda_native_empty_size(const PGresult *res)
Definition: sqlda.c:171
char * sqldata
Definition: sqlda-native.h:28
short * sqlind
Definition: sqlda-native.h:29

References numeric::buf, compat, numeric::digits, ECPG_ARRAY_NONE, ecpg_get_data(), ecpg_log(), ecpg_sqlda_align_add_size(), ECPGset_noind_null(), ECPGt_bool, ECPGt_char, ECPGt_date, ECPGt_decimal, ECPGt_double, ECPGt_float, ECPGt_int, ECPGt_interval, ECPGt_long, ECPGt_long_long, ECPGt_NO_INDICATOR, ECPGt_numeric, ECPGt_short, ECPGt_string, ECPGt_timestamp, ECPGt_unsigned_char, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, i, numeric::ndigits, numeric(), PGTYPESnumeric_free(), PGTYPESnumeric_from_asc(), PQgetisnull(), PQgetvalue(), res, sqlda_struct::sqld, sqlda_native_empty_size(), sqlvar_struct::sqldata, sqlvar_struct::sqlind, sqlvar_struct::sqllen, sqlvar_struct::sqltype, sqlda_struct::sqlvar, val, value_is_not_null, and value_is_null.

Referenced by ecpg_process_output().

◆ ecpg_sqlda_align_add_size()

static void ecpg_sqlda_align_add_size ( long  offset,
int  alignment,
int  size,
long *  current,
long *  next 
)
static

Definition at line 33 of file sqlda.c.

34{
35 if (offset % alignment)
36 offset += alignment - (offset % alignment);
37 if (current)
38 *current = offset;
39 offset += size;
40 if (next)
41 *next = offset;
42}
static int32 next
Definition: blutils.c:219

References next, and size.

Referenced by ecpg_set_compat_sqlda(), ecpg_set_native_sqlda(), sqlda_common_total_size(), sqlda_compat_empty_size(), and sqlda_native_empty_size().

◆ sqlda_common_total_size()

static long sqlda_common_total_size ( const PGresult res,
int  row,
enum COMPAT_MODE  compat,
long  offset 
)
static

Definition at line 65 of file sqlda.c.

66{
67 int sqld = PQnfields(res);
68 int i;
69 long next_offset;
70
71 /* Add space for the field values */
72 for (i = 0; i < sqld; i++)
73 {
75
76 switch (type)
77 {
78 case ECPGt_short:
80 ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
81 break;
82 case ECPGt_int:
84 ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
85 break;
86 case ECPGt_long:
88 ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
89 break;
90 case ECPGt_long_long:
92 ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
93 break;
94 case ECPGt_bool:
95 ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
96 break;
97 case ECPGt_float:
98 ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
99 break;
100 case ECPGt_double:
101 ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
102 break;
103 case ECPGt_decimal:
104 ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
105 break;
106 case ECPGt_numeric:
107
108 /*
109 * We align the numeric struct to allow it to store a pointer,
110 * while the digits array is aligned to int (which seems like
111 * overkill, but let's keep compatibility here).
112 *
113 * Unfortunately we need to deconstruct the value twice to
114 * find out the digits array's size and then later fill it.
115 */
116 ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
117 if (!PQgetisnull(res, row, i))
118 {
119 char *val = PQgetvalue(res, row, i);
120 numeric *num;
121
122 num = PGTYPESnumeric_from_asc(val, NULL);
123 if (!num)
124 break;
125 if (num->buf)
126 ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->digits - num->buf + num->ndigits, &offset, &next_offset);
128 }
129 break;
130 case ECPGt_date:
131 ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
132 break;
133 case ECPGt_timestamp:
134 ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
135 break;
136 case ECPGt_interval:
137 ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
138 break;
139 case ECPGt_char:
141 case ECPGt_string:
142 default:
143 {
144 long datalen = strlen(PQgetvalue(res, row, i)) + 1;
145
146 ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
147 break;
148 }
149 }
150 offset = next_offset;
151 }
152 return offset;
153}
ECPGttype
Definition: ecpgtype.h:42
const char * type

References numeric::buf, compat, numeric::digits, ecpg_sqlda_align_add_size(), ECPGt_bool, ECPGt_char, ECPGt_date, ECPGt_decimal, ECPGt_double, ECPGt_float, ECPGt_int, ECPGt_interval, ECPGt_long, ECPGt_long_long, ECPGt_numeric, ECPGt_short, ECPGt_string, ECPGt_timestamp, ECPGt_unsigned_char, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, i, numeric::ndigits, PGTYPESnumeric_free(), PGTYPESnumeric_from_asc(), PQftype(), PQgetisnull(), PQgetvalue(), PQnfields(), res, sqlda_dynamic_type(), type, and val.

Referenced by sqlda_compat_total_size(), and sqlda_native_total_size().

◆ sqlda_compat_empty_size()

static long sqlda_compat_empty_size ( const PGresult res)
static

Definition at line 45 of file sqlda.c.

46{
47 long offset;
48 int i;
49 int sqld = PQnfields(res);
50
51 /* Initial size to store main structure and field structures */
52 offset = sizeof(struct sqlda_compat) + sqld * sizeof(struct sqlvar_compat);
53
54 /* Add space for field names */
55 for (i = 0; i < sqld; i++)
56 offset += strlen(PQfname(res, i)) + 1;
57
58 /* Add padding to the first field value */
59 ecpg_sqlda_align_add_size(offset, sizeof(int), 0, &offset, NULL);
60
61 return offset;
62}

References ecpg_sqlda_align_add_size(), i, PQfname(), PQnfields(), res, and sqlda_compat::sqld.

Referenced by ecpg_set_compat_sqlda(), and sqlda_compat_total_size().

◆ sqlda_compat_total_size()

static long sqlda_compat_total_size ( const PGresult res,
int  row,
enum COMPAT_MODE  compat 
)
static

Definition at line 157 of file sqlda.c.

158{
159 long offset;
160
162
163 if (row < 0)
164 return offset;
165
166 offset = sqlda_common_total_size(res, row, compat, offset);
167 return offset;
168}
static long sqlda_common_total_size(const PGresult *res, int row, enum COMPAT_MODE compat, long offset)
Definition: sqlda.c:65

References compat, res, sqlda_common_total_size(), and sqlda_compat_empty_size().

Referenced by ecpg_build_compat_sqlda().

◆ sqlda_native_empty_size()

static long sqlda_native_empty_size ( const PGresult res)
static

Definition at line 171 of file sqlda.c.

172{
173 long offset;
174 int sqld = PQnfields(res);
175
176 /* Initial size to store main structure and field structures */
177 offset = sizeof(struct sqlda_struct) + (sqld - 1) * sizeof(struct sqlvar_struct);
178
179 /* Add padding to the first field value */
180 ecpg_sqlda_align_add_size(offset, sizeof(int), 0, &offset, NULL);
181
182 return offset;
183}

References ecpg_sqlda_align_add_size(), PQnfields(), res, and sqlda_struct::sqld.

Referenced by ecpg_set_native_sqlda(), and sqlda_native_total_size().

◆ sqlda_native_total_size()

static long sqlda_native_total_size ( const PGresult res,
int  row,
enum COMPAT_MODE  compat 
)
static

Definition at line 186 of file sqlda.c.

187{
188 long offset;
189
191
192 if (row < 0)
193 return offset;
194
195 offset = sqlda_common_total_size(res, row, compat, offset);
196 return offset;
197}

References compat, res, sqlda_common_total_size(), and sqlda_native_empty_size().

Referenced by ecpg_build_native_sqlda().

Variable Documentation

◆ value_is_not_null

int16 value_is_not_null = 0
static

Definition at line 252 of file sqlda.c.

Referenced by ecpg_set_compat_sqlda(), and ecpg_set_native_sqlda().

◆ value_is_null

int16 value_is_null = -1
static

Definition at line 251 of file sqlda.c.

Referenced by ecpg_set_compat_sqlda(), and ecpg_set_native_sqlda().