mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-06 15:24:56 +08:00
If no result is given NOTFOUND should be returned. Check for empty result
string too.
This commit is contained in:
parent
81a82a13b2
commit
d7d5c6857b
@ -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
|
||||
#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");
|
||||
|
||||
/* 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 */
|
||||
|
||||
/*
|
||||
@ -122,11 +133,10 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
if (value_for_indicator == -1)
|
||||
return (true);
|
||||
|
||||
/* pval is a pointer to the value */
|
||||
/* let's check if it really is an array if it should be one */
|
||||
if (isarray == ECPG_ARRAY_ARRAY)
|
||||
{
|
||||
if (!pval || *pval != '{')
|
||||
if (*pval != '{')
|
||||
{
|
||||
ecpg_raise(lineno, ECPG_DATA_NOT_ARRAY,
|
||||
ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
|
||||
@ -150,8 +160,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
do
|
||||
{
|
||||
if (binary)
|
||||
{
|
||||
if (pval)
|
||||
{
|
||||
if (varcharsize == 0 || varcharsize * offset >= size)
|
||||
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;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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_int:
|
||||
case ECPGt_long:
|
||||
if (pval)
|
||||
{
|
||||
res = strtol(pval, &scan_length, 10);
|
||||
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);
|
||||
}
|
||||
pval = scan_length;
|
||||
}
|
||||
else
|
||||
res = 0L;
|
||||
|
||||
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_int:
|
||||
case ECPGt_unsigned_long:
|
||||
if (pval)
|
||||
{
|
||||
ures = strtoul(pval, &scan_length, 10);
|
||||
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);
|
||||
}
|
||||
pval = scan_length;
|
||||
}
|
||||
else
|
||||
ures = 0L;
|
||||
|
||||
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_STRTOLL
|
||||
case ECPGt_long_long:
|
||||
if (pval)
|
||||
{
|
||||
*((long long int *) (var + offset * act_tuple)) = strtoll(pval, &scan_length, 10);
|
||||
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);
|
||||
}
|
||||
pval = scan_length;
|
||||
}
|
||||
else
|
||||
*((long long int *) (var + offset * act_tuple)) = (long long) 0;
|
||||
|
||||
break;
|
||||
#endif /* HAVE_STRTOLL */
|
||||
#ifdef HAVE_STRTOULL
|
||||
case ECPGt_unsigned_long_long:
|
||||
if (pval)
|
||||
{
|
||||
*((unsigned long long int *) (var + offset * act_tuple)) = strtoull(pval, &scan_length, 10);
|
||||
if ((isarray && *scan_length != ',' && *scan_length != '}')
|
||||
|| (!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);
|
||||
}
|
||||
pval = scan_length;
|
||||
}
|
||||
else
|
||||
*((unsigned long long int *) (var + offset * act_tuple)) = (long long) 0;
|
||||
|
||||
break;
|
||||
#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_double:
|
||||
if (pval)
|
||||
{
|
||||
if (isarray && *pval == '"')
|
||||
dres = strtod(pval + 1, &scan_length);
|
||||
else
|
||||
@ -331,9 +316,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
return (false);
|
||||
}
|
||||
pval = scan_length;
|
||||
}
|
||||
else
|
||||
dres = 0.0;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
@ -350,8 +332,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
break;
|
||||
|
||||
case ECPGt_bool:
|
||||
if (pval)
|
||||
{
|
||||
if (pval[0] == 'f' && pval[1] == '\0')
|
||||
{
|
||||
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 */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ecpg_raise(lineno, ECPG_CONVERT_BOOL,
|
||||
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_unsigned_char:
|
||||
case ECPGt_string:
|
||||
if (pval)
|
||||
{
|
||||
char *str = (char *) ((long) var + offset * act_tuple);
|
||||
if (varcharsize == 0 || varcharsize > size)
|
||||
@ -446,7 +424,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
break;
|
||||
|
||||
case ECPGt_varchar:
|
||||
if (pval)
|
||||
{
|
||||
struct ECPGgeneric_varchar *variable =
|
||||
(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_numeric:
|
||||
if (pval)
|
||||
{
|
||||
if (isarray && *pval == '"')
|
||||
nres = PGTYPESnumeric_from_asc(pval + 1, &scan_length);
|
||||
else
|
||||
@ -545,9 +520,6 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
}
|
||||
}
|
||||
pval = scan_length;
|
||||
}
|
||||
else
|
||||
nres = PGTYPESnumeric_from_asc("0.0", &scan_length);
|
||||
|
||||
if (type == ECPGt_numeric)
|
||||
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;
|
||||
|
||||
case ECPGt_interval:
|
||||
if (pval)
|
||||
{
|
||||
if (isarray && *pval == '"')
|
||||
ires = PGTYPESinterval_from_asc(pval + 1, &scan_length);
|
||||
else
|
||||
@ -604,16 +574,12 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
}
|
||||
}
|
||||
pval = scan_length;
|
||||
}
|
||||
else
|
||||
ires = PGTYPESinterval_from_asc("0 seconds", NULL);
|
||||
|
||||
PGTYPESinterval_copy(ires, (interval *) (var + offset * act_tuple));
|
||||
free(ires);
|
||||
break;
|
||||
|
||||
case ECPGt_date:
|
||||
if (pval)
|
||||
{
|
||||
if (isarray && *pval == '"')
|
||||
ddres = PGTYPESdate_from_asc(pval + 1, &scan_length);
|
||||
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;
|
||||
pval = scan_length;
|
||||
}
|
||||
break;
|
||||
|
||||
case ECPGt_timestamp:
|
||||
if (pval)
|
||||
{
|
||||
if (isarray && *pval == '"')
|
||||
tres = PGTYPEStimestamp_from_asc(pval + 1, &scan_length);
|
||||
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;
|
||||
pval = scan_length;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user