PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

#define POSTGRES_ECPG_INTERNAL

Definition at line 3 of file data.c.

Function Documentation

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
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
static bool check_special_value ( char *  ptr,
double *  retval,
char **  endptr 
)
static

Definition at line 96 of file data.c.

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

Referenced by ecpg_get_data().

97 {
98  if (pg_strncasecmp(ptr, "NaN", 3) == 0)
99  {
100  *retval = get_float8_nan();
101  *endptr = ptr + 3;
102  return true;
103  }
104  else if (pg_strncasecmp(ptr, "Infinity", 8) == 0)
105  {
106  *retval = get_float8_infinity();
107  *endptr = ptr + 8;
108  return true;
109  }
110  else if (pg_strncasecmp(ptr, "-Infinity", 9) == 0)
111  {
112  *retval = -get_float8_infinity();
113  *endptr = ptr + 9;
114  return true;
115  }
116 
117  return false;
118 }
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:75
static double get_float8_nan(void)
Definition: data.c:85
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 121 of file data.c.

References ECPGgeneric_varchar::arr, array_boundary(), array_delimiter(), check_special_value(), ecpg_alloc(), ECPG_ARRAY_ARRAY, 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, 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, and sqlca_t::sqlwarn.

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

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

Definition at line 75 of file data.c.

Referenced by check_special_value().

76 {
77 #ifdef INFINITY
78  return (double) INFINITY;
79 #else
80  return (double) (HUGE_VAL * HUGE_VAL);
81 #endif
82 }
static double get_float8_nan ( void  )
static

Definition at line 85 of file data.c.

Referenced by check_special_value().

86 {
87  /* (double) NAN doesn't work on some NetBSD/MIPS releases */
88 #if defined(NAN) && !(defined(__NetBSD__) && defined(__mips__))
89  return (double) NAN;
90 #else
91  return (double) (0.0 / 0.0);
92 #endif
93 }