mirror of
https://github.com/postgres/postgres.git
synced 2025-07-20 05:03:10 +03:00
If no result is given NOTFOUND should be returned. Check for empty result
string too.
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.45 2009/10/01 18:03:54 meskes Exp $ */
|
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.46 2009/11/27 13:32:17 meskes Exp $ */
|
||||||
|
|
||||||
#define POSTGRES_ECPG_INTERNAL
|
#define POSTGRES_ECPG_INTERNAL
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
@ -62,6 +62,17 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
|
|
||||||
ecpg_log("ecpg_get_data on line %d: RESULT: %s offset: %ld; array: %s\n", lineno, pval ? (binary ? "BINARY" : pval) : "EMPTY", log_offset, isarray ? "yes" : "no");
|
ecpg_log("ecpg_get_data on line %d: RESULT: %s offset: %ld; array: %s\n", lineno, pval ? (binary ? "BINARY" : pval) : "EMPTY", log_offset, isarray ? "yes" : "no");
|
||||||
|
|
||||||
|
/* pval is a pointer to the value */
|
||||||
|
if (!pval)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* This should never happen because we already checked that we
|
||||||
|
* found at least one tuple, but let's play it safe.
|
||||||
|
*/
|
||||||
|
ecpg_raise(lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL);
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
|
||||||
/* We will have to decode the value */
|
/* We will have to decode the value */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -122,11 +133,10 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
if (value_for_indicator == -1)
|
if (value_for_indicator == -1)
|
||||||
return (true);
|
return (true);
|
||||||
|
|
||||||
/* pval is a pointer to the value */
|
|
||||||
/* let's check if it really is an array if it should be one */
|
/* let's check if it really is an array if it should be one */
|
||||||
if (isarray == ECPG_ARRAY_ARRAY)
|
if (isarray == ECPG_ARRAY_ARRAY)
|
||||||
{
|
{
|
||||||
if (!pval || *pval != '{')
|
if (*pval != '{')
|
||||||
{
|
{
|
||||||
ecpg_raise(lineno, ECPG_DATA_NOT_ARRAY,
|
ecpg_raise(lineno, ECPG_DATA_NOT_ARRAY,
|
||||||
ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
|
ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
|
||||||
@ -150,8 +160,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (binary)
|
if (binary)
|
||||||
{
|
|
||||||
if (pval)
|
|
||||||
{
|
{
|
||||||
if (varcharsize == 0 || varcharsize * offset >= size)
|
if (varcharsize == 0 || varcharsize * offset >= size)
|
||||||
memcpy((char *) ((long) var + offset * act_tuple),
|
memcpy((char *) ((long) var + offset * act_tuple),
|
||||||
@ -192,7 +200,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
}
|
}
|
||||||
pval += size;
|
pval += size;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
@ -209,8 +216,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
case ECPGt_short:
|
case ECPGt_short:
|
||||||
case ECPGt_int:
|
case ECPGt_int:
|
||||||
case ECPGt_long:
|
case ECPGt_long:
|
||||||
if (pval)
|
|
||||||
{
|
|
||||||
res = strtol(pval, &scan_length, 10);
|
res = strtol(pval, &scan_length, 10);
|
||||||
if (garbage_left(isarray, scan_length, compat))
|
if (garbage_left(isarray, scan_length, compat))
|
||||||
{
|
{
|
||||||
@ -219,9 +224,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
pval = scan_length;
|
pval = scan_length;
|
||||||
}
|
|
||||||
else
|
|
||||||
res = 0L;
|
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
@ -243,8 +245,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
case ECPGt_unsigned_short:
|
case ECPGt_unsigned_short:
|
||||||
case ECPGt_unsigned_int:
|
case ECPGt_unsigned_int:
|
||||||
case ECPGt_unsigned_long:
|
case ECPGt_unsigned_long:
|
||||||
if (pval)
|
|
||||||
{
|
|
||||||
ures = strtoul(pval, &scan_length, 10);
|
ures = strtoul(pval, &scan_length, 10);
|
||||||
if (garbage_left(isarray, scan_length, compat))
|
if (garbage_left(isarray, scan_length, compat))
|
||||||
{
|
{
|
||||||
@ -253,9 +253,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
pval = scan_length;
|
pval = scan_length;
|
||||||
}
|
|
||||||
else
|
|
||||||
ures = 0L;
|
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
@ -277,8 +274,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
#ifdef HAVE_LONG_LONG_INT_64
|
#ifdef HAVE_LONG_LONG_INT_64
|
||||||
#ifdef HAVE_STRTOLL
|
#ifdef HAVE_STRTOLL
|
||||||
case ECPGt_long_long:
|
case ECPGt_long_long:
|
||||||
if (pval)
|
|
||||||
{
|
|
||||||
*((long long int *) (var + offset * act_tuple)) = strtoll(pval, &scan_length, 10);
|
*((long long int *) (var + offset * act_tuple)) = strtoll(pval, &scan_length, 10);
|
||||||
if (garbage_left(isarray, scan_length, compat))
|
if (garbage_left(isarray, scan_length, compat))
|
||||||
{
|
{
|
||||||
@ -286,16 +281,11 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
pval = scan_length;
|
pval = scan_length;
|
||||||
}
|
|
||||||
else
|
|
||||||
*((long long int *) (var + offset * act_tuple)) = (long long) 0;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
#endif /* HAVE_STRTOLL */
|
#endif /* HAVE_STRTOLL */
|
||||||
#ifdef HAVE_STRTOULL
|
#ifdef HAVE_STRTOULL
|
||||||
case ECPGt_unsigned_long_long:
|
case ECPGt_unsigned_long_long:
|
||||||
if (pval)
|
|
||||||
{
|
|
||||||
*((unsigned long long int *) (var + offset * act_tuple)) = strtoull(pval, &scan_length, 10);
|
*((unsigned long long int *) (var + offset * act_tuple)) = strtoull(pval, &scan_length, 10);
|
||||||
if ((isarray && *scan_length != ',' && *scan_length != '}')
|
if ((isarray && *scan_length != ',' && *scan_length != '}')
|
||||||
|| (!isarray && !(INFORMIX_MODE(compat) && *scan_length == '.') && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
|
|| (!isarray && !(INFORMIX_MODE(compat) && *scan_length == '.') && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
|
||||||
@ -304,9 +294,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
pval = scan_length;
|
pval = scan_length;
|
||||||
}
|
|
||||||
else
|
|
||||||
*((unsigned long long int *) (var + offset * act_tuple)) = (long long) 0;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
#endif /* HAVE_STRTOULL */
|
#endif /* HAVE_STRTOULL */
|
||||||
@ -314,8 +301,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
|
|
||||||
case ECPGt_float:
|
case ECPGt_float:
|
||||||
case ECPGt_double:
|
case ECPGt_double:
|
||||||
if (pval)
|
|
||||||
{
|
|
||||||
if (isarray && *pval == '"')
|
if (isarray && *pval == '"')
|
||||||
dres = strtod(pval + 1, &scan_length);
|
dres = strtod(pval + 1, &scan_length);
|
||||||
else
|
else
|
||||||
@ -331,9 +316,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
pval = scan_length;
|
pval = scan_length;
|
||||||
}
|
|
||||||
else
|
|
||||||
dres = 0.0;
|
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
@ -350,8 +332,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPGt_bool:
|
case ECPGt_bool:
|
||||||
if (pval)
|
|
||||||
{
|
|
||||||
if (pval[0] == 'f' && pval[1] == '\0')
|
if (pval[0] == 'f' && pval[1] == '\0')
|
||||||
{
|
{
|
||||||
if (offset == sizeof(char))
|
if (offset == sizeof(char))
|
||||||
@ -381,7 +361,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
/* NULL is valid */
|
/* NULL is valid */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ecpg_raise(lineno, ECPG_CONVERT_BOOL,
|
ecpg_raise(lineno, ECPG_CONVERT_BOOL,
|
||||||
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
|
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
|
||||||
@ -391,7 +370,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
case ECPGt_char:
|
case ECPGt_char:
|
||||||
case ECPGt_unsigned_char:
|
case ECPGt_unsigned_char:
|
||||||
case ECPGt_string:
|
case ECPGt_string:
|
||||||
if (pval)
|
|
||||||
{
|
{
|
||||||
char *str = (char *) ((long) var + offset * act_tuple);
|
char *str = (char *) ((long) var + offset * act_tuple);
|
||||||
if (varcharsize == 0 || varcharsize > size)
|
if (varcharsize == 0 || varcharsize > size)
|
||||||
@ -446,7 +424,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPGt_varchar:
|
case ECPGt_varchar:
|
||||||
if (pval)
|
|
||||||
{
|
{
|
||||||
struct ECPGgeneric_varchar *variable =
|
struct ECPGgeneric_varchar *variable =
|
||||||
(struct ECPGgeneric_varchar *) ((long) var + offset * act_tuple);
|
(struct ECPGgeneric_varchar *) ((long) var + offset * act_tuple);
|
||||||
@ -495,8 +472,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
|
|
||||||
case ECPGt_decimal:
|
case ECPGt_decimal:
|
||||||
case ECPGt_numeric:
|
case ECPGt_numeric:
|
||||||
if (pval)
|
|
||||||
{
|
|
||||||
if (isarray && *pval == '"')
|
if (isarray && *pval == '"')
|
||||||
nres = PGTYPESnumeric_from_asc(pval + 1, &scan_length);
|
nres = PGTYPESnumeric_from_asc(pval + 1, &scan_length);
|
||||||
else
|
else
|
||||||
@ -545,9 +520,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pval = scan_length;
|
pval = scan_length;
|
||||||
}
|
|
||||||
else
|
|
||||||
nres = PGTYPESnumeric_from_asc("0.0", &scan_length);
|
|
||||||
|
|
||||||
if (type == ECPGt_numeric)
|
if (type == ECPGt_numeric)
|
||||||
PGTYPESnumeric_copy(nres, (numeric *) (var + offset * act_tuple));
|
PGTYPESnumeric_copy(nres, (numeric *) (var + offset * act_tuple));
|
||||||
@ -558,8 +530,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPGt_interval:
|
case ECPGt_interval:
|
||||||
if (pval)
|
|
||||||
{
|
|
||||||
if (isarray && *pval == '"')
|
if (isarray && *pval == '"')
|
||||||
ires = PGTYPESinterval_from_asc(pval + 1, &scan_length);
|
ires = PGTYPESinterval_from_asc(pval + 1, &scan_length);
|
||||||
else
|
else
|
||||||
@ -604,16 +574,12 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pval = scan_length;
|
pval = scan_length;
|
||||||
}
|
|
||||||
else
|
|
||||||
ires = PGTYPESinterval_from_asc("0 seconds", NULL);
|
|
||||||
|
|
||||||
PGTYPESinterval_copy(ires, (interval *) (var + offset * act_tuple));
|
PGTYPESinterval_copy(ires, (interval *) (var + offset * act_tuple));
|
||||||
free(ires);
|
free(ires);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPGt_date:
|
case ECPGt_date:
|
||||||
if (pval)
|
|
||||||
{
|
|
||||||
if (isarray && *pval == '"')
|
if (isarray && *pval == '"')
|
||||||
ddres = PGTYPESdate_from_asc(pval + 1, &scan_length);
|
ddres = PGTYPESdate_from_asc(pval + 1, &scan_length);
|
||||||
else
|
else
|
||||||
@ -655,12 +621,9 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
|
|
||||||
*((date *) (var + offset * act_tuple)) = ddres;
|
*((date *) (var + offset * act_tuple)) = ddres;
|
||||||
pval = scan_length;
|
pval = scan_length;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECPGt_timestamp:
|
case ECPGt_timestamp:
|
||||||
if (pval)
|
|
||||||
{
|
|
||||||
if (isarray && *pval == '"')
|
if (isarray && *pval == '"')
|
||||||
tres = PGTYPEStimestamp_from_asc(pval + 1, &scan_length);
|
tres = PGTYPEStimestamp_from_asc(pval + 1, &scan_length);
|
||||||
else
|
else
|
||||||
@ -702,7 +665,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
|
|
||||||
*((timestamp *) (var + offset * act_tuple)) = tres;
|
*((timestamp *) (var + offset * act_tuple)) = tres;
|
||||||
pval = scan_length;
|
pval = scan_length;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Reference in New Issue
Block a user