PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
data.c File Reference
#include "postgres_fe.h"
#include <math.h>
#include "ecpgerrno.h"
#include "ecpglib.h"
#include "ecpglib_extern.h"
#include "ecpgtype.h"
#include "pgtypes_date.h"
#include "pgtypes_interval.h"
#include "pgtypes_numeric.h"
#include "pgtypes_timestamp.h"
#include "sqlca.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)
 
unsigned ecpg_hex_enc_len (unsigned srclen)
 
unsigned ecpg_hex_dec_len (unsigned srclen)
 
static char get_hex (char c)
 
static unsigned hex_decode (const char *src, unsigned len, char *dst)
 
unsigned ecpg_hex_encode (const char *src, unsigned len, char *dst)
 
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 33 of file data.c.

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

References ECPG_ARRAY_ARRAY, and ECPG_ARRAY_VECTOR.

Referenced by ecpg_get_data(), and garbage_left().

◆ array_delimiter()

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

Definition at line 20 of file data.c.

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

References ECPG_ARRAY_ARRAY, and ECPG_ARRAY_VECTOR.

Referenced by ecpg_get_data(), and garbage_left().

◆ check_special_value()

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

Definition at line 101 of file data.c.

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}
static double get_float8_nan(void)
Definition: data.c:90
static double get_float8_infinity(void)
Definition: data.c:80
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69

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

Referenced by ecpg_get_data().

◆ 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 206 of file data.c.

210{
211 struct sqlca_t *sqlca = ECPGget_sqlca();
212 char *pval = (char *) PQgetvalue(results, act_tuple, act_field);
213 int binary = PQfformat(results, act_field);
214 int size = PQgetlength(results, act_tuple, act_field);
215 int value_for_indicator = 0;
216 long log_offset;
217
218 if (sqlca == NULL)
219 {
222 return false;
223 }
224
225 /*
226 * If we are running in a regression test, do not log the offset variable,
227 * it depends on the machine's alignment.
228 */
230 log_offset = -1;
231 else
232 log_offset = offset;
233
234 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");
235
236 /* pval is a pointer to the value */
237 if (!pval)
238 {
239 /*
240 * This should never happen because we already checked that we found
241 * at least one tuple, but let's play it safe.
242 */
244 return false;
245 }
246
247 /* We will have to decode the value */
248
249 /*
250 * check for null value and set indicator accordingly, i.e. -1 if NULL and
251 * 0 if not
252 */
253 if (PQgetisnull(results, act_tuple, act_field))
254 value_for_indicator = -1;
255
256 switch (ind_type)
257 {
258 case ECPGt_short:
260 *((short *) (ind + ind_offset * act_tuple)) = value_for_indicator;
261 break;
262 case ECPGt_int:
264 *((int *) (ind + ind_offset * act_tuple)) = value_for_indicator;
265 break;
266 case ECPGt_long:
268 *((long *) (ind + ind_offset * act_tuple)) = value_for_indicator;
269 break;
270 case ECPGt_long_long:
272 *((long long int *) (ind + ind_offset * act_tuple)) = value_for_indicator;
273 break;
275 if (value_for_indicator == -1)
276 {
277 if (force_indicator == false)
278 {
279 /*
280 * Informix has an additional way to specify NULLs note
281 * that this uses special values to denote NULL
282 */
283 ECPGset_noind_null(type, var + offset * act_tuple);
284 }
285 else
286 {
289 NULL);
290 return false;
291 }
292 }
293 break;
294 default:
297 ecpg_type_name(ind_type));
298 return false;
299 break;
300 }
301
302 if (value_for_indicator == -1)
303 return true;
304
305 /* let's check if it really is an array if it should be one */
306 if (isarray == ECPG_ARRAY_ARRAY)
307 {
308 if (*pval != '{')
309 {
312 return false;
313 }
314
315 switch (type)
316 {
317 case ECPGt_char:
319 case ECPGt_varchar:
320 case ECPGt_string:
321 break;
322
323 default:
324 pval++;
325 break;
326 }
327 }
328
329 do
330 {
331 if (binary)
332 {
333 if (varcharsize == 0 || varcharsize * offset >= size)
334 memcpy(var + offset * act_tuple, pval, size);
335 else
336 {
337 memcpy(var + offset * act_tuple, pval, varcharsize * offset);
338
339 if (varcharsize * offset < size)
340 {
341 /* truncation */
342 switch (ind_type)
343 {
344 case ECPGt_short:
346 *((short *) (ind + ind_offset * act_tuple)) = size;
347 break;
348 case ECPGt_int:
350 *((int *) (ind + ind_offset * act_tuple)) = size;
351 break;
352 case ECPGt_long:
354 *((long *) (ind + ind_offset * act_tuple)) = size;
355 break;
356 case ECPGt_long_long:
358 *((long long int *) (ind + ind_offset * act_tuple)) = size;
359 break;
360 default:
361 break;
362 }
363 sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
364 }
365 }
366 pval += size;
367 }
368 else
369 {
370 switch (type)
371 {
372 long res;
373 unsigned long ures;
374 double dres;
375 char *scan_length;
376 numeric *nres;
377 date ddres;
378 timestamp tres;
379 interval *ires;
380 char *endptr,
381 endchar;
382
383 case ECPGt_short:
384 case ECPGt_int:
385 case ECPGt_long:
386 res = strtol(pval, &scan_length, 10);
387 if (garbage_left(isarray, &scan_length, compat))
388 {
391 return false;
392 }
393 pval = scan_length;
394
395 switch (type)
396 {
397 case ECPGt_short:
398 *((short *) (var + offset * act_tuple)) = (short) res;
399 break;
400 case ECPGt_int:
401 *((int *) (var + offset * act_tuple)) = (int) res;
402 break;
403 case ECPGt_long:
404 *((long *) (var + offset * act_tuple)) = (long) res;
405 break;
406 default:
407 /* Cannot happen */
408 break;
409 }
410 break;
411
415 ures = strtoul(pval, &scan_length, 10);
416 if (garbage_left(isarray, &scan_length, compat))
417 {
420 return false;
421 }
422 pval = scan_length;
423
424 switch (type)
425 {
427 *((unsigned short *) (var + offset * act_tuple)) = (unsigned short) ures;
428 break;
430 *((unsigned int *) (var + offset * act_tuple)) = (unsigned int) ures;
431 break;
433 *((unsigned long *) (var + offset * act_tuple)) = (unsigned long) ures;
434 break;
435 default:
436 /* Cannot happen */
437 break;
438 }
439 break;
440
441 case ECPGt_long_long:
442 *((long long int *) (var + offset * act_tuple)) = strtoll(pval, &scan_length, 10);
443 if (garbage_left(isarray, &scan_length, compat))
444 {
446 return false;
447 }
448 pval = scan_length;
449
450 break;
451
453 *((unsigned long long int *) (var + offset * act_tuple)) = strtoull(pval, &scan_length, 10);
454 if (garbage_left(isarray, &scan_length, compat))
455 {
457 return false;
458 }
459 pval = scan_length;
460
461 break;
462
463 case ECPGt_float:
464 case ECPGt_double:
465 if (isarray && *pval == '"')
466 pval++;
467
468 if (!check_special_value(pval, &dres, &scan_length))
469 dres = strtod(pval, &scan_length);
470
471 if (isarray && *scan_length == '"')
472 scan_length++;
473
474 /* no special INFORMIX treatment for floats */
475 if (garbage_left(isarray, &scan_length, ECPG_COMPAT_PGSQL))
476 {
479 return false;
480 }
481 pval = scan_length;
482
483 switch (type)
484 {
485 case ECPGt_float:
486 *((float *) (var + offset * act_tuple)) = dres;
487 break;
488 case ECPGt_double:
489 *((double *) (var + offset * act_tuple)) = dres;
490 break;
491 default:
492 /* Cannot happen */
493 break;
494 }
495 break;
496
497 case ECPGt_bool:
498 if (pval[0] == 'f' && pval[1] == '\0')
499 {
500 *((bool *) (var + offset * act_tuple)) = false;
501 pval++;
502 break;
503 }
504 else if (pval[0] == 't' && pval[1] == '\0')
505 {
506 *((bool *) (var + offset * act_tuple)) = true;
507 pval++;
508 break;
509 }
510 else if (pval[0] == '\0' && PQgetisnull(results, act_tuple, act_field))
511 {
512 /* NULL is valid */
513 break;
514 }
515
518 return false;
519 break;
520
521 case ECPGt_bytea:
522 {
524 (struct ECPGgeneric_bytea *) (var + offset * act_tuple);
525 long dst_size,
526 src_size,
527 dec_size;
528
529 dst_size = ecpg_hex_enc_len(varcharsize);
530 src_size = size - 2; /* exclude backslash + 'x' */
531 dec_size = src_size < dst_size ? src_size : dst_size;
532 variable->len = hex_decode(pval + 2, dec_size, variable->arr);
533
534 if (dst_size < src_size)
535 {
536 long rcv_size = ecpg_hex_dec_len(size - 2);
537
538 /* truncation */
539 switch (ind_type)
540 {
541 case ECPGt_short:
543 *((short *) (ind + ind_offset * act_tuple)) = rcv_size;
544 break;
545 case ECPGt_int:
547 *((int *) (ind + ind_offset * act_tuple)) = rcv_size;
548 break;
549 case ECPGt_long:
551 *((long *) (ind + ind_offset * act_tuple)) = rcv_size;
552 break;
553 case ECPGt_long_long:
555 *((long long int *) (ind + ind_offset * act_tuple)) = rcv_size;
556 break;
557 default:
558 break;
559 }
560 sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
561 }
562
563 pval += size;
564 }
565 break;
566
567 case ECPGt_char:
569 case ECPGt_string:
570 {
571 char *str = (char *) (var + offset * act_tuple);
572
573 /*
574 * If varcharsize is unknown and the offset is that of
575 * char *, then this variable represents the array of
576 * character pointers. So, use extra indirection.
577 */
578 if (varcharsize == 0 && offset == sizeof(char *))
579 str = *(char **) str;
580
581 if (varcharsize > size)
582 {
583 /*
584 * compatibility mode, blank pad and null
585 * terminate char array
586 */
588 {
589 memset(str, ' ', varcharsize);
590 memcpy(str, pval, size);
591 str[varcharsize - 1] = '\0';
592
593 /*
594 * compatibility mode empty string gets -1
595 * indicator but no warning
596 */
597 if (size == 0)
598 {
599 /* truncation */
600 switch (ind_type)
601 {
602 case ECPGt_short:
604 *((short *) (ind + ind_offset * act_tuple)) = -1;
605 break;
606 case ECPGt_int:
608 *((int *) (ind + ind_offset * act_tuple)) = -1;
609 break;
610 case ECPGt_long:
612 *((long *) (ind + ind_offset * act_tuple)) = -1;
613 break;
614 case ECPGt_long_long:
616 *((long long int *) (ind + ind_offset * act_tuple)) = -1;
617 break;
618 default:
619 break;
620 }
621 }
622 }
623 else
624 {
625 strncpy(str, pval, size + 1);
626 }
627 /* do the rtrim() */
628 if (type == ECPGt_string)
629 {
630 char *last = str + size;
631
632 while (last > str && (*last == ' ' || *last == '\0'))
633 {
634 *last = '\0';
635 last--;
636 }
637 }
638 }
639 else
640 {
641 int charsize = varcharsize;
642
643 /*
644 * assume that the caller provided storage exactly
645 * fit when varcharsize is zero.
646 */
647 if (varcharsize == 0)
648 charsize = size + 1;
649
650 strncpy(str, pval, charsize);
651
652 /* compatibility mode, null terminate char array */
653 if (ORACLE_MODE(compat) && (charsize - 1) < size)
654 {
656 str[charsize - 1] = '\0';
657 }
658
659 if (charsize < size || (ORACLE_MODE(compat) && (charsize - 1) < size))
660 {
661 /* truncation */
662 switch (ind_type)
663 {
664 case ECPGt_short:
666 *((short *) (ind + ind_offset * act_tuple)) = size;
667 break;
668 case ECPGt_int:
670 *((int *) (ind + ind_offset * act_tuple)) = size;
671 break;
672 case ECPGt_long:
674 *((long *) (ind + ind_offset * act_tuple)) = size;
675 break;
676 case ECPGt_long_long:
678 *((long long int *) (ind + ind_offset * act_tuple)) = size;
679 break;
680 default:
681 break;
682 }
683 sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
684 }
685 }
686 pval += size;
687 }
688 break;
689
690 case ECPGt_varchar:
691 {
693 (struct ECPGgeneric_varchar *) (var + offset * act_tuple);
694
695 variable->len = size;
696 if (varcharsize == 0)
697 strncpy(variable->arr, pval, variable->len);
698 else
699 {
700 strncpy(variable->arr, pval, varcharsize);
701
702 if (variable->len > varcharsize)
703 {
704 /* truncation */
705 switch (ind_type)
706 {
707 case ECPGt_short:
709 *((short *) (ind + ind_offset * act_tuple)) = variable->len;
710 break;
711 case ECPGt_int:
713 *((int *) (ind + ind_offset * act_tuple)) = variable->len;
714 break;
715 case ECPGt_long:
717 *((long *) (ind + ind_offset * act_tuple)) = variable->len;
718 break;
719 case ECPGt_long_long:
721 *((long long int *) (ind + ind_offset * act_tuple)) = variable->len;
722 break;
723 default:
724 break;
725 }
726 sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
727
728 variable->len = varcharsize;
729 }
730 }
731 pval += size;
732 }
733 break;
734
735 case ECPGt_decimal:
736 case ECPGt_numeric:
737 for (endptr = pval; *endptr && *endptr != ',' && *endptr != '}'; endptr++);
738 endchar = *endptr;
739 *endptr = '\0';
740 nres = PGTYPESnumeric_from_asc(pval, &scan_length);
741 *endptr = endchar;
742
743 /* did we get an error? */
744 if (nres == NULL)
745 {
746 ecpg_log("ecpg_get_data on line %d: RESULT %s; errno %d\n",
747 lineno, pval, errno);
748
750 {
751 /*
752 * Informix wants its own NULL value here instead
753 * of an error
754 */
755 nres = PGTYPESnumeric_new();
756 if (nres)
758 else
759 {
762 return false;
763 }
764 }
765 else
766 {
769 return false;
770 }
771 }
772 else
773 {
774 if (!isarray && garbage_left(isarray, &scan_length, compat))
775 {
776 free(nres);
779 return false;
780 }
781 }
782 pval = scan_length;
783
784 if (type == ECPGt_numeric)
785 PGTYPESnumeric_copy(nres, (numeric *) (var + offset * act_tuple));
786 else
787 PGTYPESnumeric_to_decimal(nres, (decimal *) (var + offset * act_tuple));
788
790 break;
791
792 case ECPGt_interval:
793 if (*pval == '"')
794 pval++;
795
796 for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
797 endchar = *endptr;
798 *endptr = '\0';
799 ires = PGTYPESinterval_from_asc(pval, &scan_length);
800 *endptr = endchar;
801
802 /* did we get an error? */
803 if (ires == NULL)
804 {
805 ecpg_log("ecpg_get_data on line %d: RESULT %s; errno %d\n",
806 lineno, pval, errno);
807
809 {
810 /*
811 * Informix wants its own NULL value here instead
812 * of an error
813 */
814 ires = (interval *) ecpg_alloc(sizeof(interval), lineno);
815 if (!ires)
816 return false;
817
819 }
820 else
821 {
824 return false;
825 }
826 }
827 else
828 {
829 if (*scan_length == '"')
830 scan_length++;
831
832 if (!isarray && garbage_left(isarray, &scan_length, compat))
833 {
834 free(ires);
837 return false;
838 }
839 }
840 pval = scan_length;
841
842 PGTYPESinterval_copy(ires, (interval *) (var + offset * act_tuple));
843 free(ires);
844 break;
845
846 case ECPGt_date:
847 if (*pval == '"')
848 pval++;
849
850 for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
851 endchar = *endptr;
852 *endptr = '\0';
853 ddres = PGTYPESdate_from_asc(pval, &scan_length);
854 *endptr = endchar;
855
856 /* did we get an error? */
857 if (errno != 0)
858 {
859 ecpg_log("ecpg_get_data on line %d: RESULT %s; errno %d\n",
860 lineno, pval, errno);
861
863 {
864 /*
865 * Informix wants its own NULL value here instead
866 * of an error
867 */
869 }
870 else
871 {
874 return false;
875 }
876 }
877 else
878 {
879 if (*scan_length == '"')
880 scan_length++;
881
882 if (!isarray && garbage_left(isarray, &scan_length, compat))
883 {
886 return false;
887 }
888 }
889
890 *((date *) (var + offset * act_tuple)) = ddres;
891 pval = scan_length;
892 break;
893
894 case ECPGt_timestamp:
895 if (*pval == '"')
896 pval++;
897
898 for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
899 endchar = *endptr;
900 *endptr = '\0';
901 tres = PGTYPEStimestamp_from_asc(pval, &scan_length);
902 *endptr = endchar;
903
904 /* did we get an error? */
905 if (errno != 0)
906 {
907 ecpg_log("ecpg_get_data on line %d: RESULT %s; errno %d\n",
908 lineno, pval, errno);
909
911 {
912 /*
913 * Informix wants its own NULL value here instead
914 * of an error
915 */
917 }
918 else
919 {
922 return false;
923 }
924 }
925 else
926 {
927 if (*scan_length == '"')
928 scan_length++;
929
930 if (!isarray && garbage_left(isarray, &scan_length, compat))
931 {
934 return false;
935 }
936 }
937
938 *((timestamp *) (var + offset * act_tuple)) = tres;
939 pval = scan_length;
940 break;
941
942 default:
946 return false;
947 break;
948 }
949 if (ECPG_IS_ARRAY(isarray))
950 {
951 bool string = false;
952
953 /* set array to next entry */
954 ++act_tuple;
955
956 /* set pval to the next entry */
957
958 /*
959 * *pval != '\0' should not be needed, but is used as a safety
960 * guard
961 */
962 for (; *pval != '\0' && (string || (!array_delimiter(isarray, *pval) && !array_boundary(isarray, *pval))); ++pval)
963 if (*pval == '"')
964 string = string ? false : true;
965
966 if (array_delimiter(isarray, *pval))
967 ++pval;
968 }
969 }
970 } while (*pval != '\0' && !array_boundary(isarray, *pval));
971
972 return true;
973}
unsigned ecpg_hex_enc_len(unsigned srclen)
Definition: data.c:128
static bool garbage_left(enum ARRAY_TYPE isarray, char **scan_length, enum COMPAT_MODE compat)
Definition: data.c:46
unsigned ecpg_hex_dec_len(unsigned srclen)
Definition: data.c:134
static unsigned hex_decode(const char *src, unsigned len, char *dst)
Definition: data.c:161
static bool array_delimiter(enum ARRAY_TYPE isarray, char c)
Definition: data.c:20
static bool array_boundary(enum ARRAY_TYPE isarray, char c)
Definition: data.c:33
static bool check_special_value(char *ptr, double *retval, char **endptr)
Definition: data.c:101
enum COMPAT_MODE compat
Definition: ecpg.c:26
bool force_indicator
Definition: ecpg.c:18
#define ECPG_CONVERT_BOOL
Definition: ecpgerrno.h:29
#define ECPG_UNSUPPORTED
Definition: ecpgerrno.h:18
#define ECPG_FLOAT_FORMAT
Definition: ecpgerrno.h:24
#define ECPG_INT_FORMAT
Definition: ecpgerrno.h:22
#define ECPG_MISSING_INDICATOR
Definition: ecpgerrno.h:31
#define ECPG_INTERVAL_FORMAT
Definition: ecpgerrno.h:26
#define ECPG_UINT_FORMAT
Definition: ecpgerrno.h:23
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
#define ECPG_NOT_FOUND
Definition: ecpgerrno.h:10
#define ECPG_DATA_NOT_ARRAY
Definition: ecpgerrno.h:33
#define ECPG_NUMERIC_FORMAT
Definition: ecpgerrno.h:25
#define ECPG_DATE_FORMAT
Definition: ecpgerrno.h:27
#define ECPG_TIMESTAMP_FORMAT
Definition: ecpgerrno.h:28
#define ECPG_SQLSTATE_NO_DATA
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
@ ECPG_COMPAT_PGSQL
char * ecpg_alloc(long size, int lineno)
Definition: memory.c:19
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
#define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER
void ecpg_log(const char *format,...) pg_attribute_printf(1
#define ORACLE_MODE(X)
#define INFORMIX_MODE(X)
const char * ecpg_type_name(enum ECPGttype typ)
Definition: typename.c:17
#define ECPG_SQLSTATE_DATATYPE_MISMATCH
#define ECPG_IS_ARRAY(X)
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
bool ecpg_internal_regression_mode
Definition: misc.c:29
@ ECPGt_float
Definition: ecpgtype.h:47
@ ECPGt_long_long
Definition: ecpgtype.h:45
@ ECPGt_short
Definition: ecpgtype.h:43
@ ECPGt_decimal
Definition: ecpgtype.h:51
@ ECPGt_bytea
Definition: ecpgtype.h:67
@ ECPGt_numeric
Definition: ecpgtype.h:49
@ ECPGt_varchar
Definition: ecpgtype.h:48
@ ECPGt_timestamp
Definition: ecpgtype.h:54
@ ECPGt_unsigned_short
Definition: ecpgtype.h:43
@ ECPGt_int
Definition: ecpgtype.h:44
@ ECPGt_long
Definition: ecpgtype.h:44
@ ECPGt_unsigned_char
Definition: ecpgtype.h:43
@ ECPGt_double
Definition: ecpgtype.h:47
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_date
Definition: ecpgtype.h:53
@ ECPGt_interval
Definition: ecpgtype.h:55
@ ECPGt_unsigned_long
Definition: ecpgtype.h:44
@ ECPGt_bool
Definition: ecpgtype.h:46
@ ECPGt_unsigned_long_long
Definition: ecpgtype.h:45
@ ECPGt_unsigned_int
Definition: ecpgtype.h:44
@ ECPGt_char
Definition: ecpgtype.h:43
@ ECPGt_string
Definition: ecpgtype.h:65
int PQgetlength(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3887
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3876
int PQfformat(const PGresult *res, int field_num)
Definition: fe-exec.c:3708
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3901
const char * str
#define free(a)
Definition: header.h:65
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:108
void ECPGset_noind_null(enum ECPGttype type, void *ptr)
Definition: misc.c:292
return false
Definition: isn.c:130
long date
Definition: pgtypes_date.h:9
date PGTYPESdate_from_asc(char *str, char **endptr)
Definition: datetime.c:47
int PGTYPESinterval_copy(interval *intvlsrc, interval *intvldest)
Definition: interval.c:1082
interval * PGTYPESinterval_from_asc(char *str, char **endptr)
Definition: interval.c:1003
int PGTYPESnumeric_copy(numeric *src, numeric *dst)
Definition: numeric.c:1388
numeric * PGTYPESnumeric_new(void)
Definition: numeric.c:42
int PGTYPESnumeric_to_decimal(numeric *src, decimal *dst)
Definition: numeric.c:1547
void PGTYPESnumeric_free(numeric *var)
Definition: numeric.c:385
numeric * PGTYPESnumeric_from_asc(char *str, char **endptr)
Definition: numeric.c:321
timestamp PGTYPEStimestamp_from_asc(char *str, char **endptr)
Definition: timestamp.c:202
int64 timestamp
static pg_noinline void Size size
Definition: slab.c:607
#define sqlca
Definition: sqlca.h:59
Definition: sqlca.h:20
const char * type

References array_boundary(), array_delimiter(), check_special_value(), compat, ecpg_alloc(), ECPG_ARRAY_ARRAY, ECPG_COMPAT_PGSQL, ECPG_CONVERT_BOOL, ECPG_DATA_NOT_ARRAY, ECPG_DATE_FORMAT, ECPG_FLOAT_FORMAT, ecpg_hex_dec_len(), ecpg_hex_enc_len(), 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_bytea, 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, force_indicator, free, garbage_left(), hex_decode(), INFORMIX_MODE, ORACLE_MODE, 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(), res, size, sqlca, str, and type.

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

◆ ecpg_hex_dec_len()

unsigned ecpg_hex_dec_len ( unsigned  srclen)

Definition at line 134 of file data.c.

135{
136 return srclen >> 1;
137}

Referenced by ecpg_get_data().

◆ ecpg_hex_enc_len()

unsigned ecpg_hex_enc_len ( unsigned  srclen)

Definition at line 128 of file data.c.

129{
130 return srclen << 1;
131}

Referenced by convert_bytea_to_string(), ecpg_get_data(), and print_param_value().

◆ ecpg_hex_encode()

unsigned ecpg_hex_encode ( const char *  src,
unsigned  len,
char *  dst 
)

Definition at line 191 of file data.c.

192{
193 static const char hextbl[] = "0123456789abcdef";
194 const char *end = src + len;
195
196 while (src < end)
197 {
198 *dst++ = hextbl[(*src >> 4) & 0xF];
199 *dst++ = hextbl[*src & 0xF];
200 src++;
201 }
202 return len * 2;
203}
const void size_t len
static const char hextbl[]
Definition: pgp-info.c:87

References hextbl, and len.

Referenced by convert_bytea_to_string(), and print_param_value().

◆ garbage_left()

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

Definition at line 46 of file data.c.

47{
48 /*
49 * INFORMIX allows for selecting a numeric into an int, the result is
50 * truncated
51 */
52 if (isarray == ECPG_ARRAY_NONE)
53 {
54 if (INFORMIX_MODE(compat) && **scan_length == '.')
55 {
56 /* skip invalid characters */
57 do
58 {
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}
@ ECPG_ARRAY_NONE

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

Referenced by ecpg_get_data().

◆ get_float8_infinity()

static double get_float8_infinity ( void  )
static

Definition at line 80 of file data.c.

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

Referenced by check_special_value().

◆ get_float8_nan()

static double get_float8_nan ( void  )
static

Definition at line 90 of file data.c.

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}

Referenced by check_special_value().

◆ get_hex()

static char get_hex ( char  c)
inlinestatic

Definition at line 140 of file data.c.

141{
142 static const int8 hexlookup[128] = {
143 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
144 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
145 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
146 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
147 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
148 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
149 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
150 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
151 };
152 int res = -1;
153
154 if (c > 0 && c < 127)
155 res = hexlookup[(unsigned char) c];
156
157 return (char) res;
158}
int8_t int8
Definition: c.h:482
static const int8 hexlookup[128]
Definition: encode.c:169

References hexlookup, and res.

Referenced by hex_decode().

◆ hex_decode()

static unsigned hex_decode ( const char *  src,
unsigned  len,
char *  dst 
)
static

Definition at line 161 of file data.c.

162{
163 const char *s,
164 *srcend;
165 char v1,
166 v2,
167 *p;
168
169 srcend = src + len;
170 s = src;
171 p = dst;
172 while (s < srcend)
173 {
174 if (*s == ' ' || *s == '\n' || *s == '\t' || *s == '\r')
175 {
176 s++;
177 continue;
178 }
179 v1 = get_hex(*s++) << 4;
180 if (s >= srcend)
181 return -1;
182
183 v2 = get_hex(*s++);
184 *p++ = v1 | v2;
185 }
186
187 return p - dst;
188}
static char get_hex(char c)
Definition: data.c:140

References get_hex(), and len.

Referenced by ecpg_get_data().