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