Re: Looking for help with ESQL/C and informix
Posted in 1998
djboyd@sam.on-net.net wrote: > I need some example code on how one can create a cursor and then pass > it to different functions. Currently all my logic sits in void main > (void). I would like to break this up to make my code more > manageable. > ... You don't have to pass the cursors around, per se. Assuming you're using 5.0x or later ESQL/C, the cursors are global names which can be referenced whereever you need them: void dcl(void) { EXEC SQL DECLARE c1 CURSOR FOR SELECT ...; } void opn(void) { EXEC SQL OPEN c1; } Etc. If you're using 5.0x or later, you can also use string-variables for cursor names: void opn2(char *p_name) { EXEC SQL BEGIN DECLARE SECTION; char *c_name = p_name; EXEC SQL END DECLARE SECTION; EXEC SQL OPEN :c_name; } You can open any cursor which needs no USING arguments using the opn2() function. You can also treat statement names in the same way. If you are working with 4.1x or earlier versions of ESQL/C, the first question is 'Why?'. Assuming (charitably) that there's a good reason, then you need to know that cursor names are private to the source file they are found in, the DECLARE must precede any other use of the name, and you do not have string-valued cursor or statement names. Within a source file, you simply refer to the cursor by name, just as before. Yours, Jonathan Leffler (jleffler@earthlink.net) #include <many-aliases.h>