From: Patrick Welche <prlw1@newn.cam.ac.uk>
To: lewerken@mail.bicos.de
Cc: pgsql-interfaces@postgresql.org
Subject: Re: [INTERFACES] libpq++ and arrays?
Date: Sat, 15 May 1999 12:38:14 +0100 (BST)
Message-ID: <E10icli-0001zG-00@quartz.newn.cam.ac.uk> (raw)
In-Reply-To: <000f01be9e4d$d7cc1860$0700000a@sgi320.lewerkenedv.de>
Alf Lewerken wrote:
>
> I have the following problem:
> I'm using libpq++ to acces a Postgres-Database.
>
> The table was created in psql using:
> create table test values (nr int4, some_value float4[]);
...
> // so how do I obtain values in some_value[1], some_value[2] .... ?
How about
create table test (nr int4, some_value float4[]);
insert into test values (1,'{1,2,3}');
insert into test values (2,'{2,4,6}');
insert into test values (3,'{3,6,9}');
#include <iostream>
#include <libpq++.h>
int main()
{
const char *nr_string, *val1, *val2;
PgDatabase test("test");
test.Exec("select nr,test.some_value[1] as val1, test.some_value[2] as val2 "
"from test");
for(int i=0; i<test.Tuples();i++)
{
nr_string = test.GetValue(i, "nr");
val1 = test.GetValue(i, "val1");
val2 = test.GetValue(i, "val2");
cout<<"nr_string: "<<nr_string
<<"\nsome_value[1]: "<<val1
<<"\nsome_value[2]: "<<val2<<'\n';
}
return 0;
}
% a.out
nr_string: 1
some_value[1]: 1
some_value[2]: 2
nr_string: 2
some_value[1]: 2
some_value[2]: 4
nr_string: 3
some_value[1]: 3
some_value[2]: 6
Add cursors to taste :)
Cheers,
Patrick
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-interfaces@postgresql.org
Cc: prlw1@newn.cam.ac.uk, lewerken@mail.bicos.de
Subject: Re: [INTERFACES] libpq++ and arrays?
In-Reply-To: <E10icli-0001zG-00@quartz.newn.cam.ac.uk>
References: <000f01be9e4d$d7cc1860$0700000a@sgi320.lewerkenedv.de> <E10icli-0001zG-00@quartz.newn.cam.ac.uk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox