PostgreSQL Source Code  git master
data.c File Reference
#include "postgres_fe.h"
#include <float.h>
#include <math.h>
#include "ecpgtype.h"
#include "ecpglib.h"
#include "ecpgerrno.h"
#include "extern.h"
#include "sqlca.h"
#include "pgtypes_numeric.h"
#include "pgtypes_date.h"
#include "pgtypes_timestamp.h"
#include "pgtypes_interval.h"
Include dependency graph for data.c:

Go to the source code of this file.

Macros

#define POSTGRES_ECPG_INTERNAL
 

Functions

static bool array_delimiter (enum ARRAY_TYPE isarray, char c)
 
static bool array_boundary (enum ARRAY_TYPE isarray, char c)
 
static bool garbage_left (enum ARRAY_TYPE isarray, char **scan_length, enum COMPAT_MODE compat)
 
static double get_float8_infinity (void)
 
static double get_float8_nan (void)
 
static bool check_special_value (char *ptr, double *retval, char **endptr)
 
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)
 

Macro Definition Documentation

◆ POSTGRES_ECPG_INTERNAL

#define POSTGRES_ECPG_INTERNAL

Definition at line 3 of file data.c.

Function Documentation

◆ array_boundary()

static bool array_boundary ( enum ARRAY_TYPE  isarray,
char  c 
)
static

Definition at line 34 of file data.c.

References ECPG_ARRAY_ARRAY, and ECPG_ARRAY_VECTOR.

Referenced by ecpg_get_data(), and garbage_left().

35 {
36  if (isarray == ECPG_ARRAY_ARRAY && c == '}')
37  return true;
38 
39  if (isarray == ECPG_ARRAY_VECTOR && c == '\0')
40  return true;
41 
42  return false;
43 }
char * c

◆ array_delimiter()

static bool array_delimiter ( enum ARRAY_TYPE  isarray,
char  c 
)
static

Definition at line 21 of file data.c.

References ECPG_ARRAY_ARRAY, and ECPG_ARRAY_VECTOR.

Referenced by ecpg_get_data(), and garbage_left().

22 {
23  if (isarray == ECPG_ARRAY_ARRAY && c == ',')
24  return true;
25 
26  if (isarray == ECPG_ARRAY_VECTOR && c == ' ')
27  return true;
28 
29  return false;
30 }
char * c

◆ check_special_value()

static bool check_special_value ( char *  ptr,
double *  retval,
char **  endptr 
)
static

Definition at line 101 of file data.c.

References get_float8_infinity(), get_float8_nan(), and pg_strncasecmp().

Referenced by ecpg_get_data().

102 {
103  if (pg_strncasecmp(ptr, "NaN", 3) == 0)
104  {
105  *retval = get_float8_nan();
106  *endptr = ptr + 3;
107  return true;
108  }
109  else if (pg_strncasecmp(ptr, "Infinity", 8) == 0)
110  {
111  *retval = get_float8_infinity();
112  *endptr = ptr + 8;
113  return true;
114  }
115  else if (pg_strncasecmp(ptr, "-Infinity", 9) == 0)
116  {
117  *retval = -get_float8_infinity();
118  *endptr = ptr + 9;
119  return true;
120  }
121 
122  return false;
123 }
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
static double get_float8_infinity(void)
Definition: data.c:80
static double get_float8_nan(void)
Definition: data.c:90

◆ ecpg_get_data()

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 at line 126 of file data.c.

References ECPGgeneric_varchar::arr, array_boundary(), array_delimiter(), check_special_value(), ecpg_alloc(), ECPG_ARRAY_ARRAY, ECPG_COMPAT_PGSQL, ECPG_CONVERT_BOOL, ECPG_DATA_NOT_ARRAY, ECPG_DATE_FORMAT, ECPG_FLOAT_FORMAT, ECPG_INT_FORMAT, ecpg_internal_regression_mode, ECPG_INTERVAL_FORMAT, ECPG_IS_ARRAY, ecpg_log(), ECPG_MISSING_INDICATOR, ECPG_NOT_FOUND, ECPG_NUMERIC_FORMAT, ECPG_OUT_OF_MEMORY, ecpg_raise(), ECPG_SQLSTATE_DATATYPE_MISMATCH, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_NO_DATA, ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER, ECPG_TIMESTAMP_FORMAT, ecpg_type_name(), ECPG_UINT_FORMAT, ECPG_UNSUPPORTED, ECPGget_sqlca(), 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, ECPGt_varchar, false, free, garbage_left(), INFORMIX_MODE, ECPGgeneric_varchar::len, PGTYPESdate_from_asc(), PGTYPESinterval_copy(), PGTYPESinterval_from_asc(), PGTYPESnumeric_copy(), PGTYPESnumeric_free(), PGTYPESnumeric_from_asc(), PGTYPESnumeric_new(), PGTYPESnumeric_to_decimal(), PGTYPEStimestamp_from_asc(), PQfformat(), PQgetisnull(), PQgetlength(), PQgetvalue(), sqlca, sqlca_t::sqlwarn, and generate_unaccent_rules::str.

Referenced by ecpg_set_compat_sqlda(), ecpg_set_native_sqlda(), and ecpg_store_result().

130 {
131  struct sqlca_t *sqlca = ECPGget_sqlca();
132  char *pval = (char *) PQgetvalue(results, act_tuple, act_field);
133  int binary = PQfformat(results, act_field);
134  int size = PQgetlength(results, act_tuple, act_field);
135  int value_for_indicator = 0;
136  long log_offset;
137 
138  if (sqlca == NULL)
139  {
142  return false;
143  }
144 
145  /*
146  * If we are running in a regression test, do not log the offset variable,
147  * it depends on the machine's alignment.
148  */
150  log_offset = -1;
151  else
152  log_offset = offset;
153 
154  ecpg_log("ecpg_get_data on line %d: RESULT: %s offset: %ld; array: %s\n", lineno, pval ? (binary ? "BINARY" : pval) : "EMPTY", log_offset, ECPG_IS_ARRAY(isarray) ? "yes" : "no");
155 
156  /* pval is a pointer to the value */
157  if (!pval)
158  {
159  /*
160  * This should never happen because we already checked that we found
161  * at least one tuple, but let's play it safe.
162  */
164  return false;
165  }
166 
167  /* We will have to decode the value */
168 
169  /*
170  * check for null value and set indicator accordingly, i.e. -1 if NULL and
171  * 0 if not
172  */
173  if (PQgetisnull(results, act_tuple, act_field))
174  value_for_indicator = -1;
175 
176  switch (ind_type)
177  {
178  case ECPGt_short:
180  *((short *) (ind + ind_offset * act_tuple)) = value_for_indicator;
181  break;
182  case ECPGt_int:
183  case ECPGt_unsigned_int:
184  *((int *) (ind + ind_offset * act_tuple)) = value_for_indicator;
185  break;
186  case ECPGt_long:
187  case ECPGt_unsigned_long:
188  *((long *) (ind + ind_offset * act_tuple)) = value_for_indicator;
189  break;
190 #ifdef HAVE_LONG_LONG_INT
191  case ECPGt_long_long:
193  *((long long int *) (ind + ind_offset * act_tuple)) = value_for_indicator;
194  break;
195 #endif /* HAVE_LONG_LONG_INT */
196  case ECPGt_NO_INDICATOR:
197  if (value_for_indicator == -1)
198  {
199  if (force_indicator == false)
200  {
201  /*
202  * Informix has an additional way to specify NULLs note
203  * that this uses special values to denote NULL
204  */
205  ECPGset_noind_null(type, var + offset * act_tuple);
206  }
207  else
208  {
211  NULL);
212  return false;
213  }
214  }
215  break;
216  default:
219  ecpg_type_name(ind_type));
220  return false;
221  break;
222  }
223 
224  if (value_for_indicator == -1)
225  return true;
226 
227  /* let's check if it really is an array if it should be one */
228  if (isarray == ECPG_ARRAY_ARRAY)
229  {
230  if (*pval != '{')
231  {
234  return false;
235  }
236 
237  switch (type)
238  {
239  case ECPGt_char:
240  case ECPGt_unsigned_char:
241  case ECPGt_varchar:
242  case ECPGt_string:
243  break;
244 
245  default:
246  pval++;
247  break;
248  }
249  }
250 
251  do
252  {
253  if (binary)
254  {
255  if (varcharsize == 0 || varcharsize * offset >= size)
256  memcpy(var + offset * act_tuple, pval, size);
257  else
258  {
259  memcpy(var + offset * act_tuple, pval, varcharsize * offset);
260 
261  if (varcharsize * offset < size)
262  {
263  /* truncation */
264  switch (ind_type)
265  {
266  case ECPGt_short:
268  *((short *) (ind + ind_offset * act_tuple)) = size;
269  break;
270  case ECPGt_int:
271  case ECPGt_unsigned_int:
272  *((int *) (ind + ind_offset * act_tuple)) = size;
273  break;
274  case ECPGt_long:
275  case ECPGt_unsigned_long:
276  *((long *) (ind + ind_offset * act_tuple)) = size;
277  break;
278 #ifdef HAVE_LONG_LONG_INT
279  case ECPGt_long_long:
281  *((long long int *) (ind + ind_offset * act_tuple)) = size;
282  break;
283 #endif /* HAVE_LONG_LONG_INT */
284  default:
285  break;
286  }
287  sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
288  }
289  }
290  pval += size;
291  }
292  else
293  {
294  switch (type)
295  {
296  long res;
297  unsigned long ures;
298  double dres;
299  char *scan_length;
300  numeric *nres;
301  date ddres;
302  timestamp tres;
303  interval *ires;
304  char *endptr,
305  endchar;
306 
307  case ECPGt_short:
308  case ECPGt_int:
309  case ECPGt_long:
310  res = strtol(pval, &scan_length, 10);
311  if (garbage_left(isarray, &scan_length, compat))
312  {
313  ecpg_raise(lineno, ECPG_INT_FORMAT,
315  return false;
316  }
317  pval = scan_length;
318 
319  switch (type)
320  {
321  case ECPGt_short:
322  *((short *) (var + offset * act_tuple)) = (short) res;
323  break;
324  case ECPGt_int:
325  *((int *) (var + offset * act_tuple)) = (int) res;
326  break;
327  case ECPGt_long:
328  *((long *) (var + offset * act_tuple)) = (long) res;
329  break;
330  default:
331  /* Cannot happen */
332  break;
333  }
334  break;
335 
337  case ECPGt_unsigned_int:
338  case ECPGt_unsigned_long:
339  ures = strtoul(pval, &scan_length, 10);
340  if (garbage_left(isarray, &scan_length, compat))
341  {
344  return false;
345  }
346  pval = scan_length;
347 
348  switch (type)
349  {
351  *((unsigned short *) (var + offset * act_tuple)) = (unsigned short) ures;
352  break;
353  case ECPGt_unsigned_int:
354  *((unsigned int *) (var + offset * act_tuple)) = (unsigned int) ures;
355  break;
356  case ECPGt_unsigned_long:
357  *((unsigned long *) (var + offset * act_tuple)) = (unsigned long) ures;
358  break;
359  default:
360  /* Cannot happen */
361  break;
362  }
363  break;
364 
365 #ifdef HAVE_LONG_LONG_INT
366 #ifdef HAVE_STRTOLL
367  case ECPGt_long_long:
368  *((long long int *) (var + offset * act_tuple)) = strtoll(pval, &scan_length, 10);
369  if (garbage_left(isarray, &scan_length, compat))
370  {
372  return false;
373  }
374  pval = scan_length;
375 
376  break;
377 #endif /* HAVE_STRTOLL */
378 #ifdef HAVE_STRTOULL
380  *((unsigned long long int *) (var + offset * act_tuple)) = strtoull(pval, &scan_length, 10);
381  if (garbage_left(isarray, &scan_length, compat))
382  {
384  return false;
385  }
386  pval = scan_length;
387 
388  break;
389 #endif /* HAVE_STRTOULL */
390 #endif /* HAVE_LONG_LONG_INT */
391 
392  case ECPGt_float:
393  case ECPGt_double:
394  if (isarray && *pval == '"')
395  pval++;
396 
397  if (!check_special_value(pval, &dres, &scan_length))
398  dres = strtod(pval, &scan_length);
399 
400  if (isarray && *scan_length == '"')
401  scan_length++;
402 
403  /* no special INFORMIX treatment for floats */
404  if (garbage_left(isarray, &scan_length, ECPG_COMPAT_PGSQL))
405  {
408  return false;
409  }
410  pval = scan_length;
411 
412  switch (type)
413  {
414  case ECPGt_float:
415  *((float *) (var + offset * act_tuple)) = dres;
416  break;
417  case ECPGt_double:
418  *((double *) (var + offset * act_tuple)) = dres;
419  break;
420  default:
421  /* Cannot happen */
422  break;
423  }
424  break;
425 
426  case ECPGt_bool:
427  if (pval[0] == 'f' && pval[1] == '\0')
428  {
429  *((bool *) (var + offset * act_tuple)) = false;
430  pval++;
431  break;
432  }
433  else if (pval[0] == 't' && pval[1] == '\0')
434  {
435  *((bool *) (var + offset * act_tuple)) = true;
436  pval++;
437  break;
438  }
439  else if (pval[0] == '\0' && PQgetisnull(results, act_tuple, act_field))
440  {
441  /* NULL is valid */
442  break;
443  }
444 
447  return false;
448  break;
449 
450  case ECPGt_char:
451  case ECPGt_unsigned_char:
452  case ECPGt_string:
453  {
454  char *str = (char *) (var + offset * act_tuple);
455 
456  /*
457  * If varcharsize is unknown and the offset is that of
458  * char *, then this variable represents the array of
459  * character pointers. So, use extra indirection.
460  */
461  if (varcharsize == 0 && offset == sizeof(char *))
462  str = *(char **) str;
463 
464  if (varcharsize == 0 || varcharsize > size)
465  {
466  strncpy(str, pval, size + 1);
467  /* do the rtrim() */
468  if (type == ECPGt_string)
469  {
470  char *last = str + size;
471 
472  while (last > str && (*last == ' ' || *last == '\0'))
473  {
474  *last = '\0';
475  last--;
476  }
477  }
478  }
479  else
480  {
481  strncpy(str, pval, varcharsize);
482 
483  if (varcharsize < size)
484  {
485  /* truncation */
486  switch (ind_type)
487  {
488  case ECPGt_short:
490  *((short *) (ind + ind_offset * act_tuple)) = size;
491  break;
492  case ECPGt_int:
493  case ECPGt_unsigned_int:
494  *((int *) (ind + ind_offset * act_tuple)) = size;
495  break;
496  case ECPGt_long:
497  case ECPGt_unsigned_long:
498  *((long *) (ind + ind_offset * act_tuple)) = size;
499  break;
500 #ifdef HAVE_LONG_LONG_INT
501  case ECPGt_long_long:
503  *((long long int *) (ind + ind_offset * act_tuple)) = size;
504  break;
505 #endif /* HAVE_LONG_LONG_INT */
506  default:
507  break;
508  }
509  sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
510  }
511  }
512  pval += size;
513  }
514  break;
515 
516  case ECPGt_varchar:
517  {
518  struct ECPGgeneric_varchar *variable =
519  (struct ECPGgeneric_varchar *) (var + offset * act_tuple);
520 
521  variable->len = size;
522  if (varcharsize == 0)
523  strncpy(variable->arr, pval, variable->len);
524  else
525  {
526  strncpy(variable->arr, pval, varcharsize);
527 
528  if (variable->len > varcharsize)
529  {
530  /* truncation */
531  switch (ind_type)
532  {
533  case ECPGt_short:
535  *((short *) (ind + ind_offset * act_tuple)) = variable->len;
536  break;
537  case ECPGt_int:
538  case ECPGt_unsigned_int:
539  *((int *) (ind + ind_offset * act_tuple)) = variable->len;
540  break;
541  case ECPGt_long:
542  case ECPGt_unsigned_long:
543  *((long *) (ind + ind_offset * act_tuple)) = variable->len;
544  break;
545 #ifdef HAVE_LONG_LONG_INT
546  case ECPGt_long_long:
548  *((long long int *) (ind + ind_offset * act_tuple)) = variable->len;
549  break;
550 #endif /* HAVE_LONG_LONG_INT */
551  default:
552  break;
553  }
554  sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
555 
556  variable->len = varcharsize;
557  }
558  }
559  pval += size;
560  }
561  break;
562 
563  case ECPGt_decimal:
564  case ECPGt_numeric:
565  for (endptr = pval; *endptr && *endptr != ',' && *endptr != '}'; endptr++);
566  endchar = *endptr;
567  *endptr = '\0';
568  nres = PGTYPESnumeric_from_asc(pval, &scan_length);
569  *endptr = endchar;
570 
571  /* did we get an error? */
572  if (nres == NULL)
573  {
574  ecpg_log("ecpg_get_data on line %d: RESULT %s; errno %d\n",
575  lineno, pval, errno);
576 
577  if (INFORMIX_MODE(compat))
578  {
579  /*
580  * Informix wants its own NULL value here instead
581  * of an error
582  */
583  nres = PGTYPESnumeric_new();
584  if (nres)
586  else
587  {
590  return false;
591  }
592  }
593  else
594  {
597  return false;
598  }
599  }
600  else
601  {
602  if (!isarray && garbage_left(isarray, &scan_length, compat))
603  {
604  free(nres);
607  return false;
608  }
609  }
610  pval = scan_length;
611 
612  if (type == ECPGt_numeric)
613  PGTYPESnumeric_copy(nres, (numeric *) (var + offset * act_tuple));
614  else
615  PGTYPESnumeric_to_decimal(nres, (decimal *) (var + offset * act_tuple));
616 
617  PGTYPESnumeric_free(nres);
618  break;
619 
620  case ECPGt_interval:
621  if (*pval == '"')
622  pval++;
623 
624  for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
625  endchar = *endptr;
626  *endptr = '\0';
627  ires = PGTYPESinterval_from_asc(pval, &scan_length);
628  *endptr = endchar;
629 
630  /* did we get an error? */
631  if (ires == NULL)
632  {
633  ecpg_log("ecpg_get_data on line %d: RESULT %s; errno %d\n",
634  lineno, pval, errno);
635 
636  if (INFORMIX_MODE(compat))
637  {
638  /*
639  * Informix wants its own NULL value here instead
640  * of an error
641  */
642  ires = (interval *) ecpg_alloc(sizeof(interval), lineno);
643  if (!ires)
644  return false;
645 
647  }
648  else
649  {
652  return false;
653  }
654  }
655  else
656  {
657  if (*scan_length == '"')
658  scan_length++;
659 
660  if (!isarray && garbage_left(isarray, &scan_length, compat))
661  {
662  free(ires);
665  return false;
666  }
667  }
668  pval = scan_length;
669 
670  PGTYPESinterval_copy(ires, (interval *) (var + offset * act_tuple));
671  free(ires);
672  break;
673 
674  case ECPGt_date:
675  if (*pval == '"')
676  pval++;
677 
678  for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
679  endchar = *endptr;
680  *endptr = '\0';
681  ddres = PGTYPESdate_from_asc(pval, &scan_length);
682  *endptr = endchar;
683 
684  /* did we get an error? */
685  if (errno != 0)
686  {
687  ecpg_log("ecpg_get_data on line %d: RESULT %s; errno %d\n",
688  lineno, pval, errno);
689 
690  if (INFORMIX_MODE(compat))
691  {
692  /*
693  * Informix wants its own NULL value here instead
694  * of an error
695  */
697  }
698  else
699  {
702  return false;
703  }
704  }
705  else
706  {
707  if (*scan_length == '"')
708  scan_length++;
709 
710  if (!isarray && garbage_left(isarray, &scan_length, compat))
711  {
714  return false;
715  }
716  }
717 
718  *((date *) (var + offset * act_tuple)) = ddres;
719  pval = scan_length;
720  break;
721 
722  case ECPGt_timestamp:
723  if (*pval == '"')
724  pval++;
725 
726  for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
727  endchar = *endptr;
728  *endptr = '\0';
729  tres = PGTYPEStimestamp_from_asc(pval, &scan_length);
730  *endptr = endchar;
731 
732  /* did we get an error? */
733  if (errno != 0)
734  {
735  ecpg_log("ecpg_get_data on line %d: RESULT %s; errno %d\n",
736  lineno, pval, errno);
737 
738  if (INFORMIX_MODE(compat))
739  {
740  /*
741  * Informix wants its own NULL value here instead
742  * of an error
743  */
745  }
746  else
747  {
750  return false;
751  }
752  }
753  else
754  {
755  if (*scan_length == '"')
756  scan_length++;
757 
758  if (!isarray && garbage_left(isarray, &scan_length, compat))
759  {
762  return false;
763  }
764  }
765 
766  *((timestamp *) (var + offset * act_tuple)) = tres;
767  pval = scan_length;
768  break;
769 
770  default:
774  return false;
775  break;
776  }
777  if (ECPG_IS_ARRAY(isarray))
778  {
779  bool string = false;
780 
781  /* set array to next entry */
782  ++act_tuple;
783 
784  /* set pval to the next entry */
785 
786  /*
787  * *pval != '\0' should not be needed, but is used as a safety
788  * guard
789  */
790  for (; *pval != '\0' && (string || (!array_delimiter(isarray, *pval) && !array_boundary(isarray, *pval))); ++pval)
791  if (*pval == '"')
792  string = string ? false : true;
793 
794  if (array_delimiter(isarray, *pval))
795  ++pval;
796  }
797  }
798  } while (*pval != '\0' && !array_boundary(isarray, *pval));
799 
800  return true;
801 }
#define ECPG_DATA_NOT_ARRAY
Definition: ecpgerrno.h:33
int PQgetlength(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3129
date PGTYPESdate_from_asc(char *, char **)
Definition: datetime.c:48
#define ECPG_SQLSTATE_DATATYPE_MISMATCH
Definition: extern.h:216
int PGTYPESnumeric_copy(numeric *, numeric *)
Definition: numeric.c:1475
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
Definition: extern.h:220
char arr[FLEXIBLE_ARRAY_MEMBER]
Definition: extern.h:36
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
#define INFORMIX_MODE(X)
Definition: extern.h:23
int PGTYPESinterval_copy(interval *, interval *)
Definition: interval.c:1096
#define ECPG_NUMERIC_FORMAT
Definition: ecpgerrno.h:25
#define sqlca
Definition: sqlca.h:59
int64 timestamp
#define ECPG_INTERVAL_FORMAT
Definition: ecpgerrno.h:26
char sqlwarn[8]
Definition: sqlca.h:39
static bool array_delimiter(enum ARRAY_TYPE isarray, char c)
Definition: data.c:21
#define ECPG_CONVERT_BOOL
Definition: ecpgerrno.h:29
int PGTYPESnumeric_to_decimal(numeric *, decimal *)
Definition: numeric.c:1629
static bool array_boundary(enum ARRAY_TYPE isarray, char c)
Definition: data.c:34
long date
Definition: pgtypes_date.h:8
#define false
Definition: c.h:255
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
Definition: extern.h:221
#define ECPG_UINT_FORMAT
Definition: ecpgerrno.h:23
#define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER
Definition: extern.h:209
#define ECPG_SQLSTATE_NO_DATA
Definition: extern.h:200
void PGTYPESnumeric_free(numeric *)
Definition: numeric.c:470
numeric * PGTYPESnumeric_new(void)
Definition: numeric.c:127
void ecpg_log(const char *format,...) pg_attribute_printf(1
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:142
#define ECPG_DATE_FORMAT
Definition: ecpgerrno.h:27
const char * ecpg_type_name(enum ECPGttype)
Definition: typename.c:17
Definition: sqlca.h:19
interval * PGTYPESinterval_from_asc(char *, char **)
Definition: interval.c:1017
char * ecpg_alloc(long, int)
Definition: memory.c:19
#define ECPG_FLOAT_FORMAT
Definition: ecpgerrno.h:24
#define ECPG_UNSUPPORTED
Definition: ecpgerrno.h:18
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
enum COMPAT_MODE compat
Definition: ecpg.c:25
bool ecpg_internal_regression_mode
Definition: misc.c:30
#define ECPG_MISSING_INDICATOR
Definition: ecpgerrno.h:31
#define ECPG_NOT_FOUND
Definition: ecpgerrno.h:10
#define ECPG_IS_ARRAY(X)
Definition: extern.h:30
static bool check_special_value(char *ptr, double *retval, char **endptr)
Definition: data.c:101
numeric * PGTYPESnumeric_from_asc(char *, char **)
Definition: numeric.c:406
#define free(a)
Definition: header.h:65
void ECPGset_noind_null(enum ECPGttype type, void *ptr)
Definition: misc.c:320
#define ECPG_TIMESTAMP_FORMAT
Definition: ecpgerrno.h:28
static bool garbage_left(enum ARRAY_TYPE isarray, char **scan_length, enum COMPAT_MODE compat)
Definition: data.c:47
bool force_indicator
Definition: ecpg.c:18
#define ECPG_INT_FORMAT
Definition: ecpgerrno.h:22
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
int PQfformat(const PGresult *res, int field_num)
Definition: fe-exec.c:2951
timestamp PGTYPEStimestamp_from_asc(char *, char **)
Definition: timestamp.c:207

◆ garbage_left()

static bool garbage_left ( enum ARRAY_TYPE  isarray,
char **  scan_length,
enum COMPAT_MODE  compat 
)
static

Definition at line 47 of file data.c.

References array_boundary(), array_delimiter(), ECPG_ARRAY_NONE, ECPG_IS_ARRAY, and INFORMIX_MODE.

Referenced by ecpg_get_data().

48 {
49  /*
50  * INFORMIX allows for selecting a numeric into an int, the result is
51  * truncated
52  */
53  if (isarray == ECPG_ARRAY_NONE)
54  {
55  if (INFORMIX_MODE(compat) && **scan_length == '.')
56  {
57  /* skip invalid characters */
58  do {
59  (*scan_length)++;
60  } while (isdigit((unsigned char) **scan_length));
61  }
62 
63  if (**scan_length != ' ' && **scan_length != '\0')
64  return true;
65  }
66  else if (ECPG_IS_ARRAY(isarray) && !array_delimiter(isarray, **scan_length) && !array_boundary(isarray, **scan_length))
67  return true;
68 
69  return false;
70 }
#define INFORMIX_MODE(X)
Definition: extern.h:23
static bool array_delimiter(enum ARRAY_TYPE isarray, char c)
Definition: data.c:21
static bool array_boundary(enum ARRAY_TYPE isarray, char c)
Definition: data.c:34
enum COMPAT_MODE compat
Definition: ecpg.c:25
#define ECPG_IS_ARRAY(X)
Definition: extern.h:30

◆ get_float8_infinity()

static double get_float8_infinity ( void  )
static

Definition at line 80 of file data.c.

Referenced by check_special_value().

81 {
82 #ifdef INFINITY
83  return (double) INFINITY;
84 #else
85  return (double) (HUGE_VAL * HUGE_VAL);
86 #endif
87 }

◆ get_float8_nan()

static double get_float8_nan ( void  )
static

Definition at line 90 of file data.c.

Referenced by check_special_value().

91 {
92  /* (double) NAN doesn't work on some NetBSD/MIPS releases */
93 #if defined(NAN) && !(defined(__NetBSD__) && defined(__mips__))
94  return (double) NAN;
95 #else
96  return (double) (0.0 / 0.0);
97 #endif
98 }