From: | Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il> |
---|---|
To: | ua01020(at)flashnet(dot)it, pgsql-interfaces(at)postgreSQL(dot)org |
Subject: | Re: [INTERFACES] Questions about pq library and ecpg |
Date: | 1999-03-28 16:37:28 |
Message-ID: | l0311070bb32405f4ef56@[147.233.148.142] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-interfaces |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Antonello De Santis | 1999-03-28 19:46:03 | pg_hba.conf |
Previous Message | The Hermit Hacker | 1999-03-27 19:22:44 | Perl interface "oddity" ... |