Received: from mx99.openu.ac.il (arbel.openu.ac.il [147.233.32.4]) by hub.org (8.9.2/8.9.1) with ESMTP id LAA68466 for ; Sun, 28 Mar 1999 11:35:54 -0500 (EST) (envelope-from herouth@oumail.openu.ac.il) Received: from talmon.openu.ac.il (talmon.openu.ac.il [147.233.32.11]) by mx99.openu.ac.il (Postfix) with ESMTP for id 0B1744B4A2; Sun, 28 Mar 1999 18:35:52 +0200 (IST) Received: from [147.233.148.142] (1166.pc.openu.ac.il) by talmon.openu.ac.il (Netscape Messaging Server 3.54) with ESMTP id AAA3AC3; Sun, 28 Mar 1999 18:37:39 +0200 X-Sender: herouth@shaked.cc.openu.ac.il Message-Id: In-Reply-To: <99032716072200.01169@zeman> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Sun, 28 Mar 1999 18:37:28 +0200 To: ua01020@flashnet.it, pgsql-interfaces@postgreSQL.org From: Herouth Maoz Subject: Re: [INTERFACES] Questions about pq library and ecpg 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