ferrario@irst.UUCP (Lorenza Ferrario) (12/04/89)
I'm trying to understand if it is possible to build an INGRES ESQL-C procedure
to allow to create a "select" with variable columns, that is, passing the name
of columns as program's variables (:name);
they follow pieces of the code I wrote to solve this problem.
...
exec sql begin declare section;
char *vect[20], *trans, tmpcol[20];
...
exec sql end declare section;
...
vect[0]="col1"; vect[1]="col2"; ....
...
for(i=0; i<i;){
trans=vect[i];
exec sql declare tmpcur cursor for
select :trans
from tabella;
exec sql open tmpcur;
exec sql whenever not found goto tmpcur_done;
while(sqlca.sqlcode == 0){
exec sql fetch tmpcur into
:tmpcol;
exec frs loadtable scelta tabellaf /* "scelta", "tabellaf" are form's
name and tablefield's name
respectively */
(:trans = :tmpcol);
}
tmpcur_done:
exec sql close tmp_cur;
++i;
}
...
It doesn't work as I aspected because the "select" section handles the column
name (:trans) as a constant string , not as a vairiable,so in the "tabellaf"
tablefield's column they appear "col1", "col2" and not the stored values of
these columns in the db table "tabella"; meanwhile in the "loadtable"
section there are no problems.
Is it possible to solve all that or do you think it is a stupid work?
Thanks in advance
lorenza ferrario
--
Lorenza Ferrario