./test_char_select
relname=___pg_foreign_table_columns
relname=
relname=
The first three relnames should have been
postgres=# select relname from pg_class order by relname limit 3;
relname
---------------------------
_pg_foreign_data_wrappers
_pg_foreign_servers
_pg_foreign_table_columns
It's obvious that the first element of the array is being overwritten with an offset of 1.
This happens because, the array of char pointer is dumped as
/* Fetch multiple columns into one structure. */
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 3 from cur1", ECPGt_EOIT,
ECPGt_char,(strings),(long)0,(long)3,(1)*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
Since the offset is 1, the next result overwrites the previous result except for the first byte.
PFA patch ecpg_char_ptr_arr.patch to fix this issue. It has changes as follows
1. Dump array of char pointer with right offset i.e. sizeof(char *)
2. While reading array of char pointer in ecpg_do_prologue(), use the address instead of the value at that address
3. The pointer arithmetic should treat such variable as char **, instead of char *
ECPG regression tests do not show any failures with this patch.
--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company