diff options
author | Michael Meskes <meskes@postgresql.org> | 2015-02-10 12:00:13 +0100 |
---|---|---|
committer | Michael Meskes <meskes@postgresql.org> | 2015-02-10 12:04:10 +0100 |
commit | 1f393fc923ec77f25fd37e16fd8ccb480df82ebb (patch) | |
tree | e771707dfd308ec99087cdfb601bdb74c07ef032 /src/interfaces/ecpg/ecpglib/data.c | |
parent | 025c02420de990c15a90e9e3f86fcfbc5b59ee88 (diff) | |
download | postgresql-1f393fc923ec77f25fd37e16fd8ccb480df82ebb.tar.gz postgresql-1f393fc923ec77f25fd37e16fd8ccb480df82ebb.zip |
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.c | 63 |
1 files changed, 37 insertions, 26 deletions
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); |