PostgreSQL Source Code  git master
sqlda.c File Reference
#include "postgres_fe.h"
#include "catalog/pg_type_d.h"
#include "ecpg-pthread-win32.h"
#include "decimal.h"
#include "ecpgtype.h"
#include "ecpglib.h"
#include "ecpgerrno.h"
#include "extern.h"
#include "sqlca.h"
#include "sqlda-native.h"
#include "sqlda-compat.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 203 of file sqlda.c.

References sqlda_compat::desc_occ, ecpg_alloc(), ecpg_log(), i, PQfname(), PQfsize(), PQftype(), PQnfields(), 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().

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

◆ ecpg_build_native_sqlda()

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

Definition at line 410 of file sqlda.c.

References sqlname::data, ecpg_alloc(), ecpg_log(), i, sqlname::length, PQfname(), PQftype(), PQnfields(), 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().

411 {
412  struct sqlda_struct *sqlda;
413  long size;
414  int i;
415 
416  size = sqlda_native_total_size(res, row, compat);
417  sqlda = (struct sqlda_struct *) ecpg_alloc(size, line);
418  if (!sqlda)
419  return NULL;
420 
421  memset(sqlda, 0, size);
422 
423  sprintf(sqlda->sqldaid, "SQLDA ");
424  sqlda->sqld = sqlda->sqln = PQnfields(res);
425  ecpg_log("ecpg_build_native_sqlda on line %d sqld = %d\n", line, sqlda->sqld);
426  sqlda->sqldabc = sizeof(struct sqlda_struct) + (sqlda->sqld - 1) * sizeof(struct sqlvar_struct);
427 
428  for (i = 0; i < sqlda->sqld; i++)
429  {
430  char *fname;
431 
432  sqlda->sqlvar[i].sqltype = sqlda_dynamic_type(PQftype(res, i), compat);
433  fname = PQfname(res, i);
434  sqlda->sqlvar[i].sqlname.length = strlen(fname);
435  strcpy(sqlda->sqlvar[i].sqlname.data, fname);
436  }
437 
438  return sqlda;
439 }
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2732
static long sqlda_native_total_size(const PGresult *res, int row, enum COMPAT_MODE compat)
Definition: sqlda.c:184
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:2810
short length
Definition: sqlda-native.h:20
struct sqlvar_struct sqlvar[1]
Definition: sqlda-native.h:40
void ecpg_log(const char *format,...) pg_attribute_printf(1
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:2962
char sqldaid[8]
Definition: sqlda-native.h:35
char * ecpg_alloc(long, int)
Definition: memory.c:19
enum COMPAT_MODE compat
Definition: ecpg.c:25
char data[NAMEDATALEN]
Definition: sqlda-native.h:21
int i
int sqlda_dynamic_type(Oid, enum COMPAT_MODE)
Definition: typename.c:106
struct sqlname sqlname
Definition: sqlda-native.h:30

◆ 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 253 of file sqlda.c.

References numeric::buf, 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(), 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().

254 {
255  struct sqlda_compat *sqlda = (*_sqlda);
256  int i;
257  long offset,
258  next_offset;
259 
260  if (row < 0)
261  return;
262 
263  /* Offset for the first field value */
264  offset = sqlda_compat_empty_size(res);
265 
266  /*
267  * Set sqlvar[i]->sqldata pointers and convert values to correct format
268  */
269  for (i = 0; i < sqlda->sqld; i++)
270  {
271  int isnull;
272  int datalen;
273  bool set_data = true;
274 
275  switch (sqlda->sqlvar[i].sqltype)
276  {
277  case ECPGt_short:
279  ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
280  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
281  sqlda->sqlvar[i].sqllen = sizeof(short);
282  break;
283  case ECPGt_int:
284  case ECPGt_unsigned_int:
285  ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
286  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
287  sqlda->sqlvar[i].sqllen = sizeof(int);
288  break;
289  case ECPGt_long:
290  case ECPGt_unsigned_long:
291  ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
292  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
293  sqlda->sqlvar[i].sqllen = sizeof(long);
294  break;
295  case ECPGt_long_long:
297  ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
298  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
299  sqlda->sqlvar[i].sqllen = sizeof(long long);
300  break;
301  case ECPGt_bool:
302  ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
303  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
304  sqlda->sqlvar[i].sqllen = sizeof(bool);
305  break;
306  case ECPGt_float:
307  ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
308  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
309  sqlda->sqlvar[i].sqllen = sizeof(float);
310  break;
311  case ECPGt_double:
312  ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
313  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
314  sqlda->sqlvar[i].sqllen = sizeof(double);
315  break;
316  case ECPGt_decimal:
317  ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
318  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
319  sqlda->sqlvar[i].sqllen = sizeof(decimal);
320  break;
321  case ECPGt_numeric:
322  {
323  numeric *num;
324  char *val;
325 
326  set_data = false;
327 
328  ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
329  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
330  sqlda->sqlvar[i].sqllen = sizeof(numeric);
331 
332  if (PQgetisnull(res, row, i))
333  {
335  break;
336  }
337 
338  val = PQgetvalue(res, row, i);
339  num = PGTYPESnumeric_from_asc(val, NULL);
340  if (!num)
341  {
343  break;
344  }
345 
346  memcpy(sqlda->sqlvar[i].sqldata, num, sizeof(numeric));
347 
348  if (num->ndigits)
349  {
350  ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->ndigits + 1, &offset, &next_offset);
351  memcpy((char *) sqlda + offset, num->buf, num->ndigits + 1);
352 
353  ((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
354  ((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
355  }
356 
357  PGTYPESnumeric_free(num);
358 
359  break;
360  }
361  case ECPGt_date:
362  ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
363  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
364  sqlda->sqlvar[i].sqllen = sizeof(date);
365  break;
366  case ECPGt_timestamp:
367  ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
368  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
369  sqlda->sqlvar[i].sqllen = sizeof(timestamp);
370  break;
371  case ECPGt_interval:
372  ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
373  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
374  sqlda->sqlvar[i].sqllen = sizeof(interval);
375  break;
376  case ECPGt_char:
377  case ECPGt_unsigned_char:
378  case ECPGt_string:
379  default:
380  datalen = strlen(PQgetvalue(res, row, i)) + 1;
381  ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
382  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
383  sqlda->sqlvar[i].sqllen = datalen;
384  if (datalen > 32768)
385  sqlda->sqlvar[i].sqlilongdata = sqlda->sqlvar[i].sqldata;
386  break;
387  }
388 
389  isnull = PQgetisnull(res, row, i);
390  ecpg_log("ecpg_set_compat_sqlda on line %d row %d col %d %s\n", lineno, row, i, isnull ? "IS NULL" : "IS NOT NULL");
391  sqlda->sqlvar[i].sqlind = isnull ? &value_is_null : &value_is_not_null;
392  sqlda->sqlvar[i].sqlitype = ECPGt_short;
393  sqlda->sqlvar[i].sqlilen = sizeof(short);
394  if (!isnull)
395  {
396  if (set_data)
397  ecpg_get_data(res, row, i, lineno,
398  sqlda->sqlvar[i].sqltype, ECPGt_NO_INDICATOR,
399  sqlda->sqlvar[i].sqldata, NULL, 0, 0, 0,
400  ECPG_ARRAY_NONE, compat, false);
401  }
402  else
403  ECPGset_noind_null(sqlda->sqlvar[i].sqltype, sqlda->sqlvar[i].sqldata);
404 
405  offset = next_offset;
406  }
407 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
int64 timestamp
NumericDigit * buf
static int16 value_is_not_null
Definition: sqlda.c:250
long date
Definition: pgtypes_date.h:8
char bool
Definition: c.h:275
void PGTYPESnumeric_free(numeric *)
Definition: numeric.c:470
void ecpg_log(const char *format,...) pg_attribute_printf(1
char * sqldata
Definition: sqlda-compat.h:12
static void ecpg_sqlda_align_add_size(long offset, int alignment, int size, long *current, long *next)
Definition: sqlda.c:34
NumericDigit * digits
Datum numeric(PG_FUNCTION_ARGS)
Definition: numeric.c:944
int16 NumericDigit
Definition: numeric.c:100
static int16 value_is_null
Definition: sqlda.c:249
enum COMPAT_MODE compat
Definition: ecpg.c:25
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:127
numeric * PGTYPESnumeric_from_asc(char *, char **)
Definition: numeric.c:406
void ECPGset_noind_null(enum ECPGttype type, void *ptr)
Definition: misc.c:320
int i
static long sqlda_compat_empty_size(const PGresult *res)
Definition: sqlda.c:46
short * sqlind
Definition: sqlda-compat.h:13
char * sqlilongdata
Definition: sqlda-compat.h:32
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
long val
Definition: informix.c:689
struct sqlvar_compat * sqlvar
Definition: sqlda-compat.h:40

◆ 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 442 of file sqlda.c.

References numeric::buf, 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(), 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().

443 {
444  struct sqlda_struct *sqlda = (*_sqlda);
445  int i;
446  long offset,
447  next_offset;
448 
449  if (row < 0)
450  return;
451 
452  /* Offset for the first field value */
453  offset = sqlda_native_empty_size(res);
454 
455  /*
456  * Set sqlvar[i]->sqldata pointers and convert values to correct format
457  */
458  for (i = 0; i < sqlda->sqld; i++)
459  {
460  int isnull;
461  int datalen;
462  bool set_data = true;
463 
464  switch (sqlda->sqlvar[i].sqltype)
465  {
466  case ECPGt_short:
468  ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
469  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
470  sqlda->sqlvar[i].sqllen = sizeof(short);
471  break;
472  case ECPGt_int:
473  case ECPGt_unsigned_int:
474  ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
475  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
476  sqlda->sqlvar[i].sqllen = sizeof(int);
477  break;
478  case ECPGt_long:
479  case ECPGt_unsigned_long:
480  ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
481  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
482  sqlda->sqlvar[i].sqllen = sizeof(long);
483  break;
484  case ECPGt_long_long:
486  ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
487  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
488  sqlda->sqlvar[i].sqllen = sizeof(long long);
489  break;
490  case ECPGt_bool:
491  ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
492  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
493  sqlda->sqlvar[i].sqllen = sizeof(bool);
494  break;
495  case ECPGt_float:
496  ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
497  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
498  sqlda->sqlvar[i].sqllen = sizeof(float);
499  break;
500  case ECPGt_double:
501  ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
502  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
503  sqlda->sqlvar[i].sqllen = sizeof(double);
504  break;
505  case ECPGt_decimal:
506  ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
507  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
508  sqlda->sqlvar[i].sqllen = sizeof(decimal);
509  break;
510  case ECPGt_numeric:
511  {
512  numeric *num;
513  char *val;
514 
515  set_data = false;
516 
517  ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
518  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
519  sqlda->sqlvar[i].sqllen = sizeof(numeric);
520 
521  if (PQgetisnull(res, row, i))
522  {
524  break;
525  }
526 
527  val = PQgetvalue(res, row, i);
528  num = PGTYPESnumeric_from_asc(val, NULL);
529  if (!num)
530  {
532  break;
533  }
534 
535  memcpy(sqlda->sqlvar[i].sqldata, num, sizeof(numeric));
536 
537  if (num->ndigits)
538  {
539  ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->ndigits + 1, &offset, &next_offset);
540  memcpy((char *) sqlda + offset, num->buf, num->ndigits + 1);
541 
542  ((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
543  ((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
544  }
545 
546  PGTYPESnumeric_free(num);
547 
548  break;
549  }
550  case ECPGt_date:
551  ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
552  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
553  sqlda->sqlvar[i].sqllen = sizeof(date);
554  break;
555  case ECPGt_timestamp:
556  ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
557  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
558  sqlda->sqlvar[i].sqllen = sizeof(timestamp);
559  break;
560  case ECPGt_interval:
561  ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
562  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
563  sqlda->sqlvar[i].sqllen = sizeof(interval);
564  break;
565  case ECPGt_char:
566  case ECPGt_unsigned_char:
567  case ECPGt_string:
568  default:
569  datalen = strlen(PQgetvalue(res, row, i)) + 1;
570  ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
571  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
572  sqlda->sqlvar[i].sqllen = datalen;
573  break;
574  }
575 
576  isnull = PQgetisnull(res, row, i);
577  ecpg_log("ecpg_set_native_sqlda on line %d row %d col %d %s\n", lineno, row, i, isnull ? "IS NULL" : "IS NOT NULL");
578  sqlda->sqlvar[i].sqlind = isnull ? &value_is_null : &value_is_not_null;
579  if (!isnull)
580  {
581  if (set_data)
582  ecpg_get_data(res, row, i, lineno,
583  sqlda->sqlvar[i].sqltype, ECPGt_NO_INDICATOR,
584  sqlda->sqlvar[i].sqldata, NULL, 0, 0, 0,
585  ECPG_ARRAY_NONE, compat, false);
586  }
587 
588  offset = next_offset;
589  }
590 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
int64 timestamp
struct sqlvar_struct sqlvar[1]
Definition: sqlda-native.h:40
NumericDigit * buf
static int16 value_is_not_null
Definition: sqlda.c:250
long date
Definition: pgtypes_date.h:8
char * sqldata
Definition: sqlda-native.h:28
char bool
Definition: c.h:275
void PGTYPESnumeric_free(numeric *)
Definition: numeric.c:470
void ecpg_log(const char *format,...) pg_attribute_printf(1
static void ecpg_sqlda_align_add_size(long offset, int alignment, int size, long *current, long *next)
Definition: sqlda.c:34
NumericDigit * digits
Datum numeric(PG_FUNCTION_ARGS)
Definition: numeric.c:944
int16 NumericDigit
Definition: numeric.c:100
static int16 value_is_null
Definition: sqlda.c:249
enum COMPAT_MODE compat
Definition: ecpg.c:25
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:127
numeric * PGTYPESnumeric_from_asc(char *, char **)
Definition: numeric.c:406
void ECPGset_noind_null(enum ECPGttype type, void *ptr)
Definition: misc.c:320
short * sqlind
Definition: sqlda-native.h:29
int i
static long sqlda_native_empty_size(const PGresult *res)
Definition: sqlda.c:169
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
long val
Definition: informix.c:689

◆ 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 34 of file sqlda.c.

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

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

◆ 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 66 of file sqlda.c.

References 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(), sqlda_dynamic_type(), generate_unaccent_rules::type, and val.

Referenced by sqlda_compat_total_size(), and sqlda_native_total_size().

67 {
68  int sqld = PQnfields(res);
69  int i;
70  long next_offset;
71 
72  /* Add space for the field values */
73  for (i = 0; i < sqld; i++)
74  {
76 
77  switch (type)
78  {
79  case ECPGt_short:
81  ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
82  break;
83  case ECPGt_int:
84  case ECPGt_unsigned_int:
85  ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
86  break;
87  case ECPGt_long:
89  ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
90  break;
91  case ECPGt_long_long:
93  ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
94  break;
95  case ECPGt_bool:
96  ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
97  break;
98  case ECPGt_float:
99  ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
100  break;
101  case ECPGt_double:
102  ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
103  break;
104  case ECPGt_decimal:
105  ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
106  break;
107  case ECPGt_numeric:
108 
109  /*
110  * Let's align both the numeric struct and the digits array to
111  * int Unfortunately we need to do double work here to compute
112  * the size of the space needed for the numeric structure.
113  */
114  ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
115  if (!PQgetisnull(res, row, i))
116  {
117  char *val = PQgetvalue(res, row, i);
118  numeric *num;
119 
120  num = PGTYPESnumeric_from_asc(val, NULL);
121  if (!num)
122  break;
123  if (num->ndigits)
124  ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->ndigits + 1, &offset, &next_offset);
125  PGTYPESnumeric_free(num);
126  }
127  break;
128  case ECPGt_date:
129  ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
130  break;
131  case ECPGt_timestamp:
132  ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
133  break;
134  case ECPGt_interval:
135  ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
136  break;
137  case ECPGt_char:
138  case ECPGt_unsigned_char:
139  case ECPGt_string:
140  default:
141  {
142  long datalen = strlen(PQgetvalue(res, row, i)) + 1;
143 
144  ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
145  break;
146  }
147  }
148  offset = next_offset;
149  }
150  return offset;
151 }
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2732
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
int64 timestamp
long date
Definition: pgtypes_date.h:8
void PGTYPESnumeric_free(numeric *)
Definition: numeric.c:470
static void ecpg_sqlda_align_add_size(long offset, int alignment, int size, long *current, long *next)
Definition: sqlda.c:34
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:2962
int16 NumericDigit
Definition: numeric.c:100
enum COMPAT_MODE compat
Definition: ecpg.c:25
numeric * PGTYPESnumeric_from_asc(char *, char **)
Definition: numeric.c:406
int i
int sqlda_dynamic_type(Oid, enum COMPAT_MODE)
Definition: typename.c:106
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
long val
Definition: informix.c:689
ECPGttype
Definition: ecpgtype.h:41

◆ sqlda_compat_empty_size()

static long sqlda_compat_empty_size ( const PGresult res)
static

Definition at line 46 of file sqlda.c.

References ecpg_sqlda_align_add_size(), i, PQfname(), and PQnfields().

Referenced by ecpg_set_compat_sqlda(), and sqlda_compat_total_size().

47 {
48  long offset;
49  int i;
50  int sqld = PQnfields(res);
51 
52  /* Initial size to store main structure and field structures */
53  offset = sizeof(struct sqlda_compat) + sqld * sizeof(struct sqlvar_compat);
54 
55  /* Add space for field names */
56  for (i = 0; i < sqld; i++)
57  offset += strlen(PQfname(res, i)) + 1;
58 
59  /* Add padding to the first field value */
60  ecpg_sqlda_align_add_size(offset, sizeof(int), 0, &offset, NULL);
61 
62  return offset;
63 }
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2732
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:2810
static void ecpg_sqlda_align_add_size(long offset, int alignment, int size, long *current, long *next)
Definition: sqlda.c:34
int i

◆ sqlda_compat_total_size()

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

Definition at line 155 of file sqlda.c.

References sqlda_common_total_size(), and sqlda_compat_empty_size().

Referenced by ecpg_build_compat_sqlda().

156 {
157  long offset;
158 
159  offset = sqlda_compat_empty_size(res);
160 
161  if (row < 0)
162  return offset;
163 
164  offset = sqlda_common_total_size(res, row, compat, offset);
165  return offset;
166 }
static long sqlda_common_total_size(const PGresult *res, int row, enum COMPAT_MODE compat, long offset)
Definition: sqlda.c:66
enum COMPAT_MODE compat
Definition: ecpg.c:25
static long sqlda_compat_empty_size(const PGresult *res)
Definition: sqlda.c:46

◆ sqlda_native_empty_size()

static long sqlda_native_empty_size ( const PGresult res)
static

Definition at line 169 of file sqlda.c.

References ecpg_sqlda_align_add_size(), and PQnfields().

Referenced by ecpg_set_native_sqlda(), and sqlda_native_total_size().

170 {
171  long offset;
172  int sqld = PQnfields(res);
173 
174  /* Initial size to store main structure and field structures */
175  offset = sizeof(struct sqlda_struct) + (sqld - 1) * sizeof(struct sqlvar_struct);
176 
177  /* Add padding to the first field value */
178  ecpg_sqlda_align_add_size(offset, sizeof(int), 0, &offset, NULL);
179 
180  return offset;
181 }
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2732
static void ecpg_sqlda_align_add_size(long offset, int alignment, int size, long *current, long *next)
Definition: sqlda.c:34

◆ sqlda_native_total_size()

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

Definition at line 184 of file sqlda.c.

References sqlda_common_total_size(), and sqlda_native_empty_size().

Referenced by ecpg_build_native_sqlda().

185 {
186  long offset;
187 
188  offset = sqlda_native_empty_size(res);
189 
190  if (row < 0)
191  return offset;
192 
193  offset = sqlda_common_total_size(res, row, compat, offset);
194  return offset;
195 }
static long sqlda_common_total_size(const PGresult *res, int row, enum COMPAT_MODE compat, long offset)
Definition: sqlda.c:66
enum COMPAT_MODE compat
Definition: ecpg.c:25
static long sqlda_native_empty_size(const PGresult *res)
Definition: sqlda.c:169

Variable Documentation

◆ value_is_not_null

int16 value_is_not_null = 0
static

Definition at line 250 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 249 of file sqlda.c.

Referenced by ecpg_set_compat_sqlda(), and ecpg_set_native_sqlda().