summaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/ecpglib/data.c
diff options
context:
space:
mode:
authorMichael Meskes <meskes@postgresql.org>2015-02-11 11:13:11 +0100
committerMichael Meskes <meskes@postgresql.org>2015-02-11 11:27:21 +0100
commit32e6331958390ef8d09c5d696ec0afb1f34cd1e9 (patch)
tree7fcf9989b33424effccb6796b245ec4d065c8668 /src/interfaces/ecpg/ecpglib/data.c
parent14794f9b8ef9e555b93fd1d8f55594b821410f8e (diff)
Fixed array handling in ecpg.
When ecpg was rewritten to the new protocol version not all variable types were corrected. This patch rewrites the code for these types to fix that. It also fixes the documentation to correctly tell the status of array handling.
Diffstat (limited to 'src/interfaces/ecpg/ecpglib/data.c')
-rw-r--r--src/interfaces/ecpg/ecpglib/data.c63
1 files changed, 37 insertions, 26 deletions
diff --git a/src/interfaces/ecpg/ecpglib/data.c b/src/interfaces/ecpg/ecpglib/data.c
index 04f4c2212c7..c1bced45e50 100644
--- a/src/interfaces/ecpg/ecpglib/data.c
+++ b/src/interfaces/ecpg/ecpglib/data.c
@@ -291,6 +291,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
date ddres;
timestamp tres;
interval *ires;
+ char *endptr, endchar;
case ECPGt_short:
case ECPGt_int:
@@ -564,10 +565,11 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
case ECPGt_decimal:
case ECPGt_numeric:
- if (isarray && *pval == '"')
- nres = PGTYPESnumeric_from_asc(pval + 1, &scan_length);
- else
- nres = PGTYPESnumeric_from_asc(pval, &scan_length);
+ for (endptr = pval; *endptr && *endptr != ',' && *endptr != '}'; endptr++);
+ endchar = *endptr;
+ *endptr = '\0';
+ nres = PGTYPESnumeric_from_asc(pval, &scan_length);
+ *endptr = endchar;
/* did we get an error? */
if (nres == NULL)
@@ -600,10 +602,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
}
else
{
- if (isarray && *scan_length == '"')
- scan_length++;
-
- if (garbage_left(isarray, scan_length, compat))
+ if (!isarray && garbage_left(isarray, scan_length, compat))
{
free(nres);
ecpg_raise(lineno, ECPG_NUMERIC_FORMAT,
@@ -622,10 +621,14 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
break;
case ECPGt_interval:
- if (isarray && *pval == '"')
- ires = PGTYPESinterval_from_asc(pval + 1, &scan_length);
- else
- ires = PGTYPESinterval_from_asc(pval, &scan_length);
+ if (*pval == '"')
+ pval++;
+
+ for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
+ endchar = *endptr;
+ *endptr = '\0';
+ ires = PGTYPESinterval_from_asc(pval, &scan_length);
+ *endptr = endchar;
/* did we get an error? */
if (ires == NULL)
@@ -654,10 +657,10 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
}
else
{
- if (isarray && *scan_length == '"')
+ if (*scan_length == '"')
scan_length++;
- if (garbage_left(isarray, scan_length, compat))
+ if (!isarray && garbage_left(isarray, scan_length, compat))
{
free(ires);
ecpg_raise(lineno, ECPG_INTERVAL_FORMAT,
@@ -672,10 +675,14 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
break;
case ECPGt_date:
- if (isarray && *pval == '"')
- ddres = PGTYPESdate_from_asc(pval + 1, &scan_length);
- else
- ddres = PGTYPESdate_from_asc(pval, &scan_length);
+ if (*pval == '"')
+ pval++;
+
+ for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
+ endchar = *endptr;
+ *endptr = '\0';
+ ddres = PGTYPESdate_from_asc(pval, &scan_length);
+ *endptr = endchar;
/* did we get an error? */
if (errno != 0)
@@ -700,10 +707,10 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
}
else
{
- if (isarray && *scan_length == '"')
+ if (*scan_length == '"')
scan_length++;
- if (garbage_left(isarray, scan_length, compat))
+ if (!isarray && garbage_left(isarray, scan_length, compat))
{
ecpg_raise(lineno, ECPG_DATE_FORMAT,
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
@@ -716,10 +723,14 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
break;
case ECPGt_timestamp:
- if (isarray && *pval == '"')
- tres = PGTYPEStimestamp_from_asc(pval + 1, &scan_length);
- else
- tres = PGTYPEStimestamp_from_asc(pval, &scan_length);
+ if (*pval == '"')
+ pval++;
+
+ for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
+ endchar = *endptr;
+ *endptr = '\0';
+ tres = PGTYPEStimestamp_from_asc(pval, &scan_length);
+ *endptr = endchar;
/* did we get an error? */
if (errno != 0)
@@ -744,10 +755,10 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
}
else
{
- if (isarray && *scan_length == '"')
+ if (*scan_length == '"')
scan_length++;
- if (garbage_left(isarray, scan_length, compat))
+ if (!isarray && garbage_left(isarray, scan_length, compat))
{
ecpg_raise(lineno, ECPG_TIMESTAMP_FORMAT,
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);