Re: static cursor name problem
Posted in 1998
On Tue, 13 Oct 1998 mmohr@my-dejanews.com wrote: > I am building an archive library of database access routines. This library > consists of multiple files with some of the files containing cursor names > that are the same. I am using the -local switch to the esql compiler, but > this does not seem to make the cursor names unique. A 6 character hash is > prepended to the cursor name, but the problem is that the SAME 6 characters > are prepended to all the cursor names. This does not help with making the > cursor names unique. > > Here is an example of the compile line of one of the files: To be running into this problem, you have to be using 5.00 or later ESQL/C. That's good because it is also possible to create a solution. You can arrange for your code to use string variables to identify the cursors. Further, you could arrange for a 'unique cursor name generator' function to be used whenever you have to create a new cursor name. As a non-reentrant example: const char *gen_cursor_name(void) { static char namebuff[19]; static int counter = 0; sprintf(namebuff, "mohr_dbalib_%06d", counter++); return namebuff; } You can now use: int some_dbalib_routine(...) { -- Beware: do not fall for this trap!!! -- EXEC SQL BEGIN DECLARE SECTION; -- const char *p_name = gen_cursor_name(); -- const char *c_name = gen_cursor_name(); -- EXEC SQL END DECLARE SECTION; EXEC SQL BEGIN DECLARE SECTION; char p_name[19]; char c_name[19]; EXEC SQL END DECLARE SECTION; strcpy(p_name, gen_cursor_name()); strcpy(c_name, gen_cursor_name()); EXEC SQL PREPARE :p_name FROM "...whatever..."; EXEC SQL DECLARE :c_name CURSOR FOR :p_name; EXEC SQL OPEN :c_name USING ...; while (SQLCODE == 0) { EXEC SQL FETCH :c_name INTO ...; if (SQLCODE != 0) break; ... } EXEC SQL CLOSE :c_name; EXEC SQL FREE :c_name; EXEC SQL FREE :p_name; } Repeat for all the code. Document which names you use. That (or some variant on it) should get you around the problems. Yours, Jonathan Leffler (jleffler@informix.com) #include <witticism.h> Guardian of DBD::Informix v0.60 -- http://www.perl.com/CPAN Informix IDN for D4GL & Linux -- http://www.informix.com/idn