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 Maoz, Internet developer.
Open University of Israel - Telem project
In response to
pgsql-interfaces by date
|Next:||From: Antonello De Santis||Date: 1999-03-28 19:46:03|
|Previous:||From: The Hermit Hacker||Date: 1999-03-27 19:22:44|
|Subject: Perl interface "oddity" ...|