String array type in ecpg.

From: SAKAIDA <sakaida(at)psn(dot)co(dot)jp>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: String array type in ecpg.
Date: 2001-05-26 13:08:23
Message-ID: 20010526210752.5CBA.SAKAIDA@psn.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Hi,

String array type in ecpg is strange.

> pgbash
pgbash> create table test_array(code varchar(4), name text[3]);
pgbash> insert into test_array values('c01','{"n01","n02","n03"}');
pgbash> select * from test_array;
code|name
----+-------------------
c01 |{"n01","n02","n03"}
(1 row)

--------------------( ECPG program)------------------------
# include <stdio.h>
exec sql include sqlca;

main()
{
exec sql begin declare section;
char code[5];
char name[256];
exec sql end declare section;

exec sql connect to admin user admin;

exec sql declare cur cursor for select * from test_array;
exec sql open cur;
while(1)
{
exec sql fetch cur into :code, :name;
if( sqlca.sqlcode == 100 ) break;
printf("# code=(%s) name=(%s)\n", code, name );
}
exec sql close cur;
}
------------------------------------------------------------

Results are as follows.

# code=("n02","n03"}) name=({"n01","n02","n03"})
Segmentation fault (core dumped)

Here is the patch which corrects this bug.

*** postgresql-7.1.2/src/interfaces/ecpg/lib/data.c.orig Sat May 26 20:47:53 2001
--- postgresql-7.1.2/src/interfaces/ecpg/lib/data.c Sat May 26 21:33:10 2001
***************
*** 337,342 ****
--- 337,344 ----
return (false);
break;
}
+ if (type == ECPGt_char || type == ECPGt_unsigned_char || type == ECPGt_varchar)
+ break;
if (isarray)
{
bool string = false;

--
SAKAIDA Masaaki

Browse pgsql-interfaces by date

  From Date Subject
Next Message Tulassay Zsolt 2001-05-27 14:56:03 large objects, visual basic, ADO
Previous Message Randall Jonasz 2001-05-25 23:43:27 Re: C++ usage question