diff options
author | Michael Meskes <meskes@postgresql.org> | 2014-05-06 13:04:30 +0200 |
---|---|---|
committer | Michael Meskes <meskes@postgresql.org> | 2014-05-06 13:09:51 +0200 |
commit | 8d6a07fa01cece1bd3508a81e59c0c0cbc0bb867 (patch) | |
tree | 266c3b24fc0dcf5c4f61d335a3c50d8235841f38 /src/interfaces/ecpg/ecpglib/execute.c | |
parent | 14ea89366fe321609afc5838ff9fe2ded1cd707d (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/ecpglib/execute.c')
-rw-r--r-- | src/interfaces/ecpg/ecpglib/execute.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index a90fb41483d..5ec8958b270 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -1930,7 +1930,14 @@ ecpg_do_prologue(int lineno, const int compat, const int force_indicator, var->arrsize = va_arg(args, long); var->offset = va_arg(args, long); - if (var->arrsize == 0 || var->varcharsize == 0) + /* + * Unknown array size means pointer to an array. + * Unknown varcharsize usually also means pointer. But if the + * type is character and the array size is known, it is an + * array of pointers to char, so use var->pointer as it is. + */ + if (var->arrsize == 0 || + (var->varcharsize == 0 && ((var->type != ECPGt_char && var->type != ECPGt_unsigned_char) || (var->arrsize <= 1)))) var->value = *((char **) (var->pointer)); else var->value = var->pointer; |