variable length arrays (fields)
variable length arrays (fields)
От:
"nitinpdhavale" <nitinpdhavale@indiatimes.com>
Дата:
Hello all,I am having a problem accessing variable length
arrays ( or rather fields ) in postgres tables from
a C program. Can somebody please help me out ?
I've included the source files below. I've have not included
the error checks (CONNECTION_BAD etc).Thanks in advance, -npd
file test.sql
---------------
create table temp (key int4, count int4, a int4[], b int4[]);
insert into temp values( 1, 2, '{1,2}', '{3,4}' );
insert into temp values( 2, 1, '{1}', '{2}' );
insert into temp values( 3, 3, '{1,2,3}', '{3,4,5}' );
file test.c
-------------
include
#include
main()
{PGconn *conn;PGresult *res;int nf;int i, j, k;
conn = PQsetdb(NULL,NULL,NULL,NULL,"test");res = PQexec(conn,"BEGIN");PQclear(res);res = PQexec(conn,"DECLARE mc BINARY CURSOR FOR select * from temp");PQclear(res);res = PQexec(conn,"FETCH ALL in mc");PQclear(res);
nf = PQnfields(res);
for(i=0;i