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. If you declare the cursor with an in-place name then it's name will not be known outside of the module it is declared in. However, you can declare a character host variable into which you place your cursor name then you can pass the name around as a string and use it in host variables wherever a cursor name is needed. I do this all the time: EXEC SQL BEGIN DECLARE SECTION; string mycursor[19]; EXEC SQL END DECLARE SECTION; strcpy( mycursor, "FirstCurs" ); EXEC SQL DECLARE :mycursor CURSOR FOR ... retcode = open_func( mycursor, arg1, arg2, arg3 ); ::: retcode = fetch-func( mycursor, retval1, retval2, ... ); ::: int open_func( char *passedcurs, int arg1, ... ) { EXEC SQL BEGIN DECLARE SECTION; string localcurs[19]; int firstarg = arg1; EXEC SQL END DECLARE SECTION; ::: strcpy( localcurs, passedcurs ); EXEC SQL OPEN :localcurs USING ... ::: } You get the idea. We have a middleware server I wrote that reads hundreds of SQL statements and parameters from a database when it starts up, prepares statements for each and declares a cursor for each storing the names of each in a data structure. When a request comes in to execute one of the statements the name is extracted from the data structure and the CURSOR opened. Art S. Kagel