pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
libpq++ and arrays?
3+ messages / 2 participants
[nested] [flat]

* libpq++ and arrays?
@ 1999-05-14 21:07 Alf Lewerken <lewerken@mail.bicos.de>
  1999-05-15 11:38 ` Re: [INTERFACES] libpq++ and arrays? Patrick Welche <prlw1@newn.cam.ac.uk>
  0 siblings, 1 reply; 3+ messages in thread

From: Alf Lewerken @ 1999-05-14 21:07 UTC (permalink / raw)
  To: pgsql-interfaces

Hi all

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[]);

in my C++-program a piece of code is:

main()
{
  char *nr_string, *some_other_string;

  PgDatabase test(pgenv, "test");
  test.Exec("begin");
  test.Exec("declare c cursor for select * from test");
  
  for(int i=0; i<test.Tuples();i++)
  {
     nr_string = test.GetValue(i, "nr");  // obtaining the value in 'nr' is easy

     some_other_string = test.GetValue(i, "some_value[1]"); // this gives an error
     // PQgetvalue: ERROR! field number -1 is out of range
   
     // so how do I obtain values in some_value[1], some_value[2] .... ?
  }
}

any help would be appreciated.


bye


Alf Lewerken

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [INTERFACES] libpq++ and arrays?
  1999-05-14 21:07 libpq++ and arrays? Alf Lewerken <lewerken@mail.bicos.de>
@ 1999-05-15 11:38 ` Patrick Welche <prlw1@newn.cam.ac.uk>
  0 siblings, 0 replies; 3+ messages in thread

From: Patrick Welche @ 1999-05-15 11:38 UTC (permalink / raw)
  To: lewerken@mail.bicos.de; +Cc: 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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [INTERFACES] libpq++ and arrays?
@ 1999-05-16 08:19 Alf Lewerken <lewerken@mail.bicos.de>
  0 siblings, 0 replies; 3+ messages in thread

From: Alf Lewerken @ 1999-05-16 08:19 UTC (permalink / raw)
  To: prlw1@cam.ac.uk; +Cc: pgsql-interfaces

>
>How about
>
>
>Add cursors to taste :)
>
>Cheers,
>
>Patrick
>

Thank you!

That saved my day :-)


bye

Alf Lewerken




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~1999-05-16 08:19 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-05-14 21:07 libpq++ and arrays? Alf Lewerken <lewerken@mail.bicos.de>
1999-05-15 11:38 ` Patrick Welche <prlw1@newn.cam.ac.uk>
1999-05-16 08:19 Re: [INTERFACES] libpq++ and arrays? Alf Lewerken <lewerken@mail.bicos.de>

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