Cursor WITH "SELECT *" in ESQL/C 
Author Message
 Cursor WITH "SELECT *" in ESQL/C
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.***.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT
 Cursor WITH "SELECT *" in ESQL/C

Quote:

> 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.

Quote:
> 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,

Guardian of DBD::Informix v1.00.PC1 -- http://www.perl.com/CPAN
     "I don't suffer from insanity; I enjoy every minute of it!"



Wed, 18 Jun 1902 08:00:00 GMT
 Cursor WITH "SELECT *" in ESQL/C
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);

Quote:
}

exec sql open foocurs;

    for(;;)
    {
exec sql    fetch foocurs using descriptor sq;
            if(sqlca.sqlcode)
                break;
    }
exec sql close foocurs;

--
--------------------------------------------------------
Peter Komanns

hiroshima 45; chernobyl 86; windows 95, 98, 2000... !!!!!!

Quote:
> 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.



Thu, 20 Mar 2003 06:16:11 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. max of ("...","...","..")

2. Replacement for ESQL/C-Function "rdefmtdate()"

3. ESQL/Cobol "BEGIN WORK WITHOUT REPLICATION"

4. ESQL/C prob with "INFORMIXSERVER"

5. Accecss to "sequence_values()" from ESQL/C

6. DB2 CLI: "client cursor" vs "server cursor"

7. How to make a "decimal"-field to an "integer"-field

8. "."and ","

9. "."and ","

10. The ""string""

11. aReport."Field".SetFilter("this")?


 
Powered by phpBB® Forum Software