PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
sqlda.c File Reference
#include "postgres_fe.h"
#include "pg_type.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

#define POSTGRES_ECPG_INTERNAL

Definition at line 9 of file sqlda.c.

Function Documentation

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

Definition at line 202 of file sqlda.c.

References sqlda_compat::desc_occ, ecpg_alloc(), ecpg_log(), i, NULL, 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().

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

Definition at line 409 of file sqlda.c.

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

410 {
411  struct sqlda_struct *sqlda;
412  long size;
413  int i;
414 
415  size = sqlda_native_total_size(res, row, compat);
416  sqlda = (struct sqlda_struct *) ecpg_alloc(size, line);
417  if (!sqlda)
418  return NULL;
419 
420  memset(sqlda, 0, size);
421 
422  sprintf(sqlda->sqldaid, "SQLDA ");
423  sqlda->sqld = sqlda->sqln = PQnfields(res);
424  ecpg_log("ecpg_build_native_sqlda on line %d sqld = %d\n", line, sqlda->sqld);
425  sqlda->sqldabc = sizeof(struct sqlda_struct) + (sqlda->sqld - 1) * sizeof(struct sqlvar_struct);
426 
427  for (i = 0; i < sqlda->sqld; i++)
428  {
429  char *fname;
430 
431  sqlda->sqlvar[i].sqltype = sqlda_dynamic_type(PQftype(res, i), compat);
432  fname = PQfname(res, i);
433  sqlda->sqlvar[i].sqlname.length = strlen(fname);
434  strcpy(sqlda->sqlvar[i].sqlname.data, fname);
435  }
436 
437  return sqlda;
438 }
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2681
static long sqlda_native_total_size(const PGresult *res, int row, enum COMPAT_MODE compat)
Definition: sqlda.c:183
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:2759
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:2911
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
#define NULL
Definition: c.h:229
char data[NAMEDATALEN]
Definition: sqlda-native.h:21
int i
int sqlda_dynamic_type(Oid, enum COMPAT_MODE)
Definition: typename.c:105
struct sqlname sqlname
Definition: sqlda-native.h:30
void ecpg_set_compat_sqlda ( int  lineno,
struct sqlda_compat **  _sqlda,
const PGresult res,
int  row,
enum COMPAT_MODE  compat 
)

Definition at line 252 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, NULL, 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().

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

Definition at line 441 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, NULL, 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().

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

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

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:210
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.

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, NULL, PGTYPESnumeric_free(), PGTYPESnumeric_from_asc(), PQftype(), PQgetisnull(), PQgetvalue(), PQnfields(), sqlda_dynamic_type(), and val.

Referenced by sqlda_compat_total_size(), and sqlda_native_total_size().

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  {
74  enum ECPGttype type = sqlda_dynamic_type(PQftype(res, i), compat);
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:
83  case ECPGt_unsigned_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  * Let's align both the numeric struct and the digits array to
110  * int Unfortunately we need to do double work here to compute
111  * the size of the space needed for the numeric structure.
112  */
113  ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
114  if (!PQgetisnull(res, row, i))
115  {
116  char *val = PQgetvalue(res, row, i);
117  numeric *num;
118 
119  num = PGTYPESnumeric_from_asc(val, NULL);
120  if (!num)
121  break;
122  if (num->ndigits)
123  ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->ndigits + 1, &offset, &next_offset);
124  PGTYPESnumeric_free(num);
125  }
126  break;
127  case ECPGt_date:
128  ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
129  break;
130  case ECPGt_timestamp:
131  ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
132  break;
133  case ECPGt_interval:
134  ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
135  break;
136  case ECPGt_char:
137  case ECPGt_unsigned_char:
138  case ECPGt_string:
139  default:
140  {
141  long datalen = strlen(PQgetvalue(res, row, i)) + 1;
142 
143  ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
144  break;
145  }
146  }
147  offset = next_offset;
148  }
149  return offset;
150 }
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2681
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
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:33
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:2911
int16 NumericDigit
Definition: numeric.c:99
enum COMPAT_MODE compat
Definition: ecpg.c:25
numeric * PGTYPESnumeric_from_asc(char *, char **)
Definition: numeric.c:406
#define NULL
Definition: c.h:229
int i
int sqlda_dynamic_type(Oid, enum COMPAT_MODE)
Definition: typename.c:105
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
long val
Definition: informix.c:689
ECPGttype
Definition: ecpgtype.h:41
static long sqlda_compat_empty_size ( const PGresult res)
static

Definition at line 45 of file sqlda.c.

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

Referenced by ecpg_set_compat_sqlda(), and sqlda_compat_total_size().

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 }
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2681
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:2759
static void ecpg_sqlda_align_add_size(long offset, int alignment, int size, long *current, long *next)
Definition: sqlda.c:33
#define NULL
Definition: c.h:229
int i
static long sqlda_compat_total_size ( const PGresult res,
int  row,
enum COMPAT_MODE  compat 
)
static

Definition at line 154 of file sqlda.c.

References sqlda_common_total_size(), and sqlda_compat_empty_size().

Referenced by ecpg_build_compat_sqlda().

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

Definition at line 168 of file sqlda.c.

References ecpg_sqlda_align_add_size(), NULL, and PQnfields().

Referenced by ecpg_set_native_sqlda(), and sqlda_native_total_size().

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

Definition at line 183 of file sqlda.c.

References sqlda_common_total_size(), and sqlda_native_empty_size().

Referenced by ecpg_build_native_sqlda().

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

Variable Documentation

int16 value_is_not_null = 0
static

Definition at line 249 of file sqlda.c.

Referenced by ecpg_set_compat_sqlda(), and ecpg_set_native_sqlda().

int16 value_is_null = -1
static

Definition at line 248 of file sqlda.c.

Referenced by ecpg_set_compat_sqlda(), and ecpg_set_native_sqlda().