From 1f393fc923ec77f25fd37e16fd8ccb480df82ebb Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Tue, 10 Feb 2015 12:00:13 +0100 Subject: 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. --- src/interfaces/ecpg/ecpglib/data.c | 63 ++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 26 deletions(-) (limited to 'src/interfaces/ecpg/ecpglib/data.c') diff --git a/src/interfaces/ecpg/ecpglib/data.c b/src/interfaces/ecpg/ecpglib/data.c index 28b1be758af..2d0c1180a3c 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); -- cgit v1.2.3