pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: ua01020@flashnet.it
To: pgsql-interfaces@postgreSQL.org
Subject: Re: [INTERFACES] Questions about pq library and ecpg
Date: Sun, 28 Mar 1999 18:37:28 +0200
Message-ID: <l0311070bb32405f4ef56@[147.233.148.142]> (raw)
In-Reply-To: <99032716072200.01169@zeman>

At 16:43 +0200 on 27/03/1999, Antonello De Santis wrote:


> 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....

IMO, this is too dynamic for ecpg. That is, last time I messed around with
embedded SQL, the format you presented could be used only to substitute
data values, not parts of the query like the name of a table or a field.

It can easily be done with libpq, though. Instead of what you wrote above,
you simply have to build the query correctly:

strcpy( str, 'table_name' );

sprintf( query, "INSERT INTO %s VALUES ('%s', %d)", str, "Rome", 10 );

result = PQexec( conn, query );

...

After the sprintf, the variable query (make sure you allocate enough
memory) will contain "INSERT INTO table_name VALUES ('Rome', 10)".

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma





view thread (4+ messages)  latest in thread

Message-ID: <l0311070bb32405f4ef56@[147.233.148.142]>
Permalink:  ../l0311070bb32405f4ef56@%5B147.233.148.142%5D/
Also on:    postgresql.org/message-id/l0311070bb32405f4ef56@[147.233.148.142]

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: herouth@oumail.openu.ac.il, ua01020@flashnet.it
  Subject: Re: [INTERFACES] Questions about pq library and ecpg
  In-Reply-To: <l0311070bb32405f4ef56@[147.233.148.142]>

* 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