Re: [INTERFACES] libpq++ and arrays?

Поиск
Список
Период
Сортировка
От Patrick Welche
Тема Re: [INTERFACES] libpq++ and arrays?
Дата
Msg-id E10icli-0001zG-00@quartz.newn.cam.ac.uk
обсуждение исходный текст
Ответ на libpq++ and arrays?  ("Alf Lewerken" <lewerken@mail.bicos.de>)
Список pgsql-interfaces
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


В списке pgsql-interfaces по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: [HACKERS] 6.5 cvs: problem with includes in src/interfaces/libpq++/
Следующее
От: prlw1@cam.ac.uk (Patrick Welche)
Дата:
Сообщение: Re: [HACKERS] 6.5 cvs: problem with includes in src/interfaces/libpq++/