Cursor WITH "SELECT *" in ESQL/C
Posted in 2000
Topics: SQL Development & Query Writing, Connectivity: ESQL/C, 4GL & Embedded SQL
In ESQL/C, can I declare a cursor with "SELECT * " statement instead of listing down all the individual fields with the SELECT statement. EXEC SQL DECLARE myCursor CURSOR FOR SELECT * FROM myTable; EXEC SQL OPEN myCursor; How to write FETCH statement to get field values into different host variables? Thanks, Vamsee. Sent via Deja.com http://www.deja.com/ Before you buy.
vamsee_2000@my-deja.com wrote: > In ESQL/C, can I declare a cursor with "SELECT * " statement instead of > listing down all the individual fields with the SELECT statement. Yes. Of course, your code will break if the table is modified after the program is compiled and before it is run, but that is often an acceptable risk. > EXEC SQL DECLARE myCursor CURSOR FOR SELECT * FROM myTable; > EXEC SQL OPEN myCursor; > How to write FETCH statement to get field values into different host > variables? Oh, just list all the variables that you want the values gotten into. :-) If you have a record (struct) with the right type, there is a shorthand that you can use, just listing :structvar as the host variable. ESQL/C must have been told the details of the structure, of course, so it must be defined inside a DECLARE SECTION. -- Yours, Jonathan Leffler (Jonathan.Leffler@Informix.com) #include <disclaimer.h> Guardian of DBD::Informix v1.00.PC1 -- http://www.perl.com/CPAN "I don't suffer from insanity; I enjoy every minute of it!"
Another way is to use interactive mode: struct sqlda *sqp; exec sql prepare fooid from "select * from mytable"; exec sql declare foocurs cursor for fooid; exec sql describe fooid into sqp; for( k=0;k<sq->sqld;k++) { switch( sq->sqlvar[k].sqltype & ~SQLNONULL) { case SQLCHAR: case SQLVCHAR: sq->sqlvar[k].sqllen++; size=sq->sqlvar[k].sqllen; break; default: size=sq->sqlvar[k].sqllen; break; } sq->sqlvar[k].sqldata=(char *)malloc(size); } exec sql open foocurs; for(;;) { exec sql fetch foocurs using descriptor sq; if(sqlca.sqlcode) break; } exec sql close foocurs; -- -------------------------------------------------------- Peter Komanns E-Mail: p.komanns@sindata.it hiroshima 45; chernobyl 86; windows 95, 98, 2000... !!!!!! <vamsee_2000@my-deja.com> wrote in message news:8r2l8b$7af$1@nnrp1.deja.com... > In ESQL/C, can I declare a cursor with "SELECT * " statement instead of > listing down all the individual fields with the SELECT statement. > > EXEC SQL DECLARE myCursor CURSOR FOR SELECT * FROM myTable; > EXEC SQL OPEN myCursor; > How to write FETCH statement to get field values into different host > variables? > > Thanks, > Vamsee. > > > > > > > Sent via Deja.com http://www.deja.com/ > Before you buy.