3 #define POSTGRES_ECPG_INTERNAL
60 }
while (isdigit((
unsigned char) **scan_length));
63 if (**scan_length !=
' ' && **scan_length !=
'\0')
73 #if defined(WIN32) && !defined(NAN)
74 static const uint32 nan[2] = {0xffffffff, 0x7fffffff};
76 #define NAN (*(const double *) nan)
83 return (
double) INFINITY;
85 return (
double) (HUGE_VAL * HUGE_VAL);
93 #if defined(NAN) && !(defined(__NetBSD__) && defined(__mips__))
96 return (
double) (0.0 / 0.0);
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,
154 if (
c > 0 &&
c < 127)
174 if (*s ==
' ' || *s ==
'\n' || *s ==
'\t' || *s ==
'\r')
193 static const char hextbl[] =
"0123456789abcdef";
194 const char *end = src +
len;
198 *dst++ =
hextbl[(*src >> 4) & 0xF];
199 *dst++ =
hextbl[*src & 0xF];
208 char *var,
char *
ind,
long varcharsize,
long offset,
212 char *pval = (
char *)
PQgetvalue(results, act_tuple, act_field);
213 int binary =
PQfformat(results, act_field);
215 int value_for_indicator = 0;
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");
254 value_for_indicator = -1;
260 *((
short *) (
ind + ind_offset * act_tuple)) = value_for_indicator;
264 *((
int *) (
ind + ind_offset * act_tuple)) = value_for_indicator;
268 *((
long *) (
ind + ind_offset * act_tuple)) = value_for_indicator;
272 *((
long long int *) (
ind + ind_offset * act_tuple)) = value_for_indicator;
275 if (value_for_indicator == -1)
302 if (value_for_indicator == -1)
333 if (varcharsize == 0 || varcharsize * offset >=
size)
334 memcpy(var + offset * act_tuple, pval,
size);
337 memcpy(var + offset * act_tuple, pval, varcharsize * offset);
339 if (varcharsize * offset <
size)
346 *((
short *) (
ind + ind_offset * act_tuple)) =
size;
350 *((
int *) (
ind + ind_offset * act_tuple)) =
size;
354 *((
long *) (
ind + ind_offset * act_tuple)) =
size;
358 *((
long long int *) (
ind + ind_offset * act_tuple)) =
size;
386 res = strtol(pval, &scan_length, 10);
398 *((
short *) (var + offset * act_tuple)) = (
short)
res;
401 *((
int *) (var + offset * act_tuple)) = (
int)
res;
404 *((
long *) (var + offset * act_tuple)) = (
long)
res;
415 ures = strtoul(pval, &scan_length, 10);
427 *((
unsigned short *) (var + offset * act_tuple)) = (
unsigned short) ures;
430 *((
unsigned int *) (var + offset * act_tuple)) = (
unsigned int) ures;
433 *((
unsigned long *) (var + offset * act_tuple)) = (
unsigned long) ures;
442 *((
long long int *) (var + offset * act_tuple)) = strtoll(pval, &scan_length, 10);
453 *((
unsigned long long int *) (var + offset * act_tuple)) = strtoull(pval, &scan_length, 10);
465 if (isarray && *pval ==
'"')
469 dres = strtod(pval, &scan_length);
471 if (isarray && *scan_length ==
'"')
486 *((
float *) (var + offset * act_tuple)) = dres;
489 *((
double *) (var + offset * act_tuple)) = dres;
498 if (pval[0] ==
'f' && pval[1] ==
'\0')
500 *((
bool *) (var + offset * act_tuple)) =
false;
504 else if (pval[0] ==
't' && pval[1] ==
'\0')
506 *((
bool *) (var + offset * act_tuple)) =
true;
510 else if (pval[0] ==
'\0' &&
PQgetisnull(results, act_tuple, act_field))
531 dec_size = src_size < dst_size ? src_size : dst_size;
534 if (dst_size < src_size)
543 *((
short *) (
ind + ind_offset * act_tuple)) = rcv_size;
547 *((
int *) (
ind + ind_offset * act_tuple)) = rcv_size;
551 *((
long *) (
ind + ind_offset * act_tuple)) = rcv_size;
555 *((
long long int *) (
ind + ind_offset * act_tuple)) = rcv_size;
571 char *
str = (
char *) (var + offset * act_tuple);
578 if (varcharsize == 0 && offset ==
sizeof(
char *))
581 if (varcharsize >
size)
589 memset(
str,
' ', varcharsize);
591 str[varcharsize - 1] =
'\0';
604 *((
short *) (
ind + ind_offset * act_tuple)) = -1;
608 *((
int *) (
ind + ind_offset * act_tuple)) = -1;
612 *((
long *) (
ind + ind_offset * act_tuple)) = -1;
616 *((
long long int *) (
ind + ind_offset * act_tuple)) = -1;
632 while (last >
str && (*last ==
' ' || *last ==
'\0'))
641 int charsize = varcharsize;
647 if (varcharsize == 0)
650 strncpy(
str, pval, charsize);
656 str[charsize - 1] =
'\0';
666 *((
short *) (
ind + ind_offset * act_tuple)) =
size;
670 *((
int *) (
ind + ind_offset * act_tuple)) =
size;
674 *((
long *) (
ind + ind_offset * act_tuple)) =
size;
678 *((
long long int *) (
ind + ind_offset * act_tuple)) =
size;
696 if (varcharsize == 0)
700 strncpy(
variable->arr, pval, varcharsize);
709 *((
short *) (
ind + ind_offset * act_tuple)) =
variable->len;
713 *((
int *) (
ind + ind_offset * act_tuple)) =
variable->len;
717 *((
long *) (
ind + ind_offset * act_tuple)) =
variable->len;
721 *((
long long int *) (
ind + ind_offset * act_tuple)) =
variable->len;
737 for (endptr = pval; *endptr && *endptr !=
',' && *endptr !=
'}'; endptr++);
746 ecpg_log(
"ecpg_get_data on line %d: RESULT %s; errno %d\n",
747 lineno, pval, errno);
796 for (endptr = pval; *endptr && *endptr !=
',' && *endptr !=
'"' && *endptr !=
'}'; endptr++);
805 ecpg_log(
"ecpg_get_data on line %d: RESULT %s; errno %d\n",
806 lineno, pval, errno);
829 if (*scan_length ==
'"')
850 for (endptr = pval; *endptr && *endptr !=
',' && *endptr !=
'"' && *endptr !=
'}'; endptr++);
859 ecpg_log(
"ecpg_get_data on line %d: RESULT %s; errno %d\n",
860 lineno, pval, errno);
879 if (*scan_length ==
'"')
890 *((
date *) (var + offset * act_tuple)) = ddres;
898 for (endptr = pval; *endptr && *endptr !=
',' && *endptr !=
'"' && *endptr !=
'}'; endptr++);
907 ecpg_log(
"ecpg_get_data on line %d: RESULT %s; errno %d\n",
908 lineno, pval, errno);
927 if (*scan_length ==
'"')
938 *((
timestamp *) (var + offset * act_tuple)) = tres;
964 string =
string ?
false :
true;
unsigned ecpg_hex_enc_len(unsigned srclen)
static char get_hex(char c)
static bool garbage_left(enum ARRAY_TYPE isarray, char **scan_length, enum COMPAT_MODE compat)
unsigned ecpg_hex_dec_len(unsigned srclen)
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)
static double get_float8_nan(void)
static unsigned hex_decode(const char *src, unsigned len, char *dst)
unsigned ecpg_hex_encode(const char *src, unsigned len, char *dst)
static bool array_delimiter(enum ARRAY_TYPE isarray, char c)
static double get_float8_infinity(void)
static bool array_boundary(enum ARRAY_TYPE isarray, char c)
static bool check_special_value(char *ptr, double *retval, char **endptr)
static void PGresult * res
#define ECPG_CONVERT_BOOL
#define ECPG_FLOAT_FORMAT
#define ECPG_MISSING_INDICATOR
#define ECPG_INTERVAL_FORMAT
#define ECPG_OUT_OF_MEMORY
#define ECPG_DATA_NOT_ARRAY
#define ECPG_NUMERIC_FORMAT
#define ECPG_TIMESTAMP_FORMAT
#define ECPG_SQLSTATE_NO_DATA
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
const char * ecpg_type_name(enum ECPGttype typ)
#define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER
void ecpg_log(const char *format,...) pg_attribute_printf(1
char * ecpg_alloc(long size, int lineno)
#define ECPG_SQLSTATE_DATATYPE_MISMATCH
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
bool ecpg_internal_regression_mode
@ ECPGt_unsigned_long_long
static const int8 hexlookup[128]
int PQgetlength(const PGresult *res, int tup_num, int field_num)
int PQfformat(const PGresult *res, int field_num)
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
void ECPGset_noind_null(enum ECPGttype type, void *ptr)
struct sqlca_t * ECPGget_sqlca(void)
static const char hextbl[]
date PGTYPESdate_from_asc(char *str, char **endptr)
int PGTYPESinterval_copy(interval *intvlsrc, interval *intvldest)
interval * PGTYPESinterval_from_asc(char *str, char **endptr)
int PGTYPESnumeric_copy(numeric *src, numeric *dst)
int PGTYPESnumeric_to_decimal(numeric *src, decimal *dst)
numeric * PGTYPESnumeric_new(void)
numeric * PGTYPESnumeric_from_asc(char *str, char **endptr)
void PGTYPESnumeric_free(numeric *var)
timestamp PGTYPEStimestamp_from_asc(char *str, char **endptr)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
static pg_noinline void Size size