aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/ecpglib/sqlda.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/ecpg/ecpglib/sqlda.c')
-rw-r--r--src/interfaces/ecpg/ecpglib/sqlda.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/interfaces/ecpg/ecpglib/sqlda.c b/src/interfaces/ecpg/ecpglib/sqlda.c
index bc94f2f8594..30645a18572 100644
--- a/src/interfaces/ecpg/ecpglib/sqlda.c
+++ b/src/interfaces/ecpg/ecpglib/sqlda.c
@@ -106,9 +106,12 @@ sqlda_common_total_size(const PGresult *res, int row, enum COMPAT_MODE compat, l
case ECPGt_numeric:
/*
- * Let's align both the numeric struct and the digits array to
- * int Unfortunately we need to do double work here to compute
- * the size of the space needed for the numeric structure.
+ * We align the numeric struct to allow it to store a pointer,
+ * while the digits array is aligned to int (which seems like
+ * overkill, but let's keep compatibility here).
+ *
+ * Unfortunately we need to deconstruct the value twice to
+ * find out the digits array's size and then later fill it.
*/
ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
if (!PQgetisnull(res, row, i))
@@ -119,8 +122,7 @@ sqlda_common_total_size(const PGresult *res, int row, enum COMPAT_MODE compat, l
num = PGTYPESnumeric_from_asc(val, NULL);
if (!num)
break;
- if (num->ndigits)
- ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->ndigits + 1, &offset, &next_offset);
+ ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->digits - num->buf + num->ndigits, &offset, &next_offset);
PGTYPESnumeric_free(num);
}
break;
@@ -344,14 +346,11 @@ ecpg_set_compat_sqlda(int lineno, struct sqlda_compat ** _sqlda, const PGresult
memcpy(sqlda->sqlvar[i].sqldata, num, sizeof(numeric));
- if (num->ndigits)
- {
- ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->ndigits + 1, &offset, &next_offset);
- memcpy((char *) sqlda + offset, num->buf, num->ndigits + 1);
+ ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->digits - num->buf + num->ndigits, &offset, &next_offset);
+ memcpy((char *) sqlda + offset, num->buf, num->digits - num->buf + num->ndigits);
- ((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
- ((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
- }
+ ((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
+ ((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
PGTYPESnumeric_free(num);
@@ -533,14 +532,11 @@ ecpg_set_native_sqlda(int lineno, struct sqlda_struct ** _sqlda, const PGresult
memcpy(sqlda->sqlvar[i].sqldata, num, sizeof(numeric));
- if (num->ndigits)
- {
- ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->ndigits + 1, &offset, &next_offset);
- memcpy((char *) sqlda + offset, num->buf, num->ndigits + 1);
+ ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->digits - num->buf + num->ndigits, &offset, &next_offset);
+ memcpy((char *) sqlda + offset, num->buf, num->digits - num->buf + num->ndigits);
- ((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
- ((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
- }
+ ((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
+ ((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
PGTYPESnumeric_free(num);