Questions about pq library and ecpg - Mailing list pgsql-interfaces

From Antonello De Santis
Subject Questions about pq library and ecpg
Date
Msg-id 99032716072200.01169@zeman
Whole thread Raw
Responses Re: [INTERFACES] Questions about pq library and ecpg  (Herouth Maoz <herouth@oumail.openu.ac.il>)
Re: [INTERFACES] Questions about pq library and ecpg  (Michael Meskes <meskes@postgresql.org>)
List pgsql-interfaces
Hi,

I'm a new subscriber of this mailing list and new user of postgresql, let me
first greet everybody reading this mail.
I have a couple of questions about libpq and ecpg.
Is it possible to accomplish a query on a table whose name is specified in a
variable? That is, something like the following:

strcpy(str, 'table');
result=PQexec(conn, "insert into str values('Rome', 10)");

I guess a code like the above one would not give the expected result..... Is
there a way to work that out?
I'm trying to use the ecpg preprocessor to pass arguments of a query in
variables, but I get a few errors.... Here's the piece of code that doesn't
work:

 exec sql begin declare section;
 char str[80];
 exec sql end declare section;
 strcpy(str, "squadre");
 exec sql connect 'prova';
 exec sql select * from :str;
 exec sql commit;
 exec sql insert into :str values('Samp', 10);
 exec sql commit;
 exec sql disconnect 'prova';

ecpg gives an error message saying: parse error in line 10, that is line "exec
sql insert into :str values('Samp', 10);". If I replace var str with the name
of the table, it works correctly instead. The syntax seems to be correct so I
have no idea about where the error is.
The last question for now is the following: how can I display the content of a
table using ecpg instructions? The statement "exec sql select * from :str;",
doesn't print anything on screen..... Any trick please? Probably this is a
stupid question, so forgive me, I'm new to postgresql! :-)
Thanks to everybody.

Greetings,

  Antonello De Santis


pgsql-interfaces by date:

Previous
From: Byron Nikolaidis
Date:
Subject: Re: [Fwd: [INTERFACES] type error inserting large obj, Win32 ODBC]
Next
From: Wojciech Kromer
Date:
Subject: PsqlODBC and 'lo' type in PostrgreSQL 6.4.x