This is explicity allowed in db2:
void f3(int i)
{
EXEC SQL BEGIN DECLARE SECTION;
char host_var_3[25];
EXEC SQL END DECLARE SECTION;
EXEC SQL SELECT COL2 INTO :host_var_3 FROM TBL2;
}
void f4(int i)
{
char host_var_3[25];
EXEC SQL INSERT INTO TBL2 VALUES (:host_var_3);
}
In db2 host variable definitions are global. You can have more than one
corresponding host variable with the proviso that they are of the same
type and size.
In ecpg I tried to use this definition:
exec sql begin declare section;
char date[9];
long time;
char ASXcode[7];
int thigh;
int tlow;
int tclose;
int topen;
int tvolume;
unsigned long long tvalue;
exec sql end declare section;
function ()
char date[9];
{
exec sql ... :date ...;
}
which is required in DB2 (in order to use the same host variable name) but
ecpg does not allow.
The construct that ecpg requires is not legal in DB2.