ECPG - connection name in "EXEC SQL AT ... " statement

From: Edward Pilipczuk <edx(at)astercity(dot)net>
To: <pgsql-interfaces(at)postgresql(dot)org>
Subject: ECPG - connection name in "EXEC SQL AT ... " statement
Date: 2001-10-22 08:34:59
Message-ID: 200110220835.KAA18304@zeng.uranos.eu.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

I've faced with the problem when trying to pass dynamically connection name
to DB into the "EXEC SQL AT ..." statement.

Let's revie the following example:
...
exec sql begin declare section;
char dbcn[17]; // connection name
char key[17]; // keyed query
char value[1024]; // result
exec sql end declare section;
strncpy(dbcn,connection_name, 16 ); dbcn[16] = '\0';
strncpy(key,param, 16 ); key[16] = '\0';
EXEC SQL AT :dbcn SELECT value INTO :value FROM table_name WHERE key = :key;
...
ecpg preprocessor produces the following ECPGdo call:
{ ECPGdo(__LINE__, dbcn, "select value from table_name where key = ? ",
ECPGt_char,(dbcn),17L,1L,17*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_char,(key),17L,1L,17*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
ECPGt_char,(value),1024L,1L,1024*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
...
and during the execution it produces the following runtime error:
"error [-201] Too many arguments in line 125."

Removing the ':' prefix from dbcn in EXEC statement results in interpreting
the dbcn literally, i.e., statement is translated to:
...
{ ECPGdo(__LINE__, "dbcn", "select value from table_name where key = ? ",
ECPGt_char,(key),17L,1L,17*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
ECPGt_char,(value),1024L,1L,1024*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
...

The workaround here is manually processing the resulting .c file (or via sed)
removing double quotes that surrounds the word dbcn.
...

!!!
Can anybody help in this matter ?
Is there any other solution ?

Regards,
Edward Pilipczuk

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Antonio Sergio de Mello e Souza 2001-10-22 14:44:19 ECPG error message
Previous Message Christopher C. Weis 2001-10-22 02:25:23 Re: Need help adding perl interface to 7.1.3 on MacOSX 10.1