summaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/preproc
diff options
context:
space:
mode:
authorMichael Meskes <meskes@postgresql.org>2014-05-06 13:04:30 +0200
committerMichael Meskes <meskes@postgresql.org>2014-05-06 13:14:01 +0200
commit3a024c1104248a444caab5fa11b4442a1587a90b (patch)
tree75571a7962d68a766f0a0c4677412110fa3edb20 /src/interfaces/ecpg/preproc
parentc8fbeeb45ef835a5e513ad167fd984baa7dc00d8 (diff)
Fix handling of array of char pointers in ecpglib.
When array of char * was used as target for a FETCH statement returning more than one row, it tried to store all the result in the first element. Instead it should dump array of char pointers with right offset, use the address instead of the value of the C variable while reading the array and treat such variable as char **, instead of char * for pointer arithmetic. Patch by Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
Diffstat (limited to 'src/interfaces/ecpg/preproc')
-rw-r--r--src/interfaces/ecpg/preproc/type.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c
index 64e8361f1f4..9fb979febb0 100644
--- a/src/interfaces/ecpg/preproc/type.c
+++ b/src/interfaces/ecpg/preproc/type.c
@@ -410,7 +410,8 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
case ECPGt_unsigned_char:
case ECPGt_char_variable:
case ECPGt_string:
-
+ {
+ char *sizeof_name = "char";
/*
* we have to use the pointer except for arrays with given
* bounds, ecpglib will distinguish between * and []
@@ -420,12 +421,24 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
(atoi(varcharsize) == 0 && strcmp(varcharsize, "0") != 0) ||
(atoi(arrsize) == 0 && strcmp(arrsize, "0") != 0))
&& siz == NULL)
+ {
sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
+ if ((type == ECPGt_char || type == ECPGt_unsigned_char) &&
+ strcmp(varcharsize, "0") == 0)
+ {
+ /*
+ * If this is an array of char *, the offset would be
+ * sizeof(char *) and not sizeof(char).
+ */
+ sizeof_name = "char *";
+ }
+ }
else
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
- sprintf(offset, "(%s)*sizeof(char)", strcmp(varcharsize, "0") == 0 ? "1" : varcharsize);
+ sprintf(offset, "(%s)*sizeof(%s)", strcmp(varcharsize, "0") == 0 ? "1" : varcharsize, sizeof_name);
break;
+ }
case ECPGt_numeric:
/*