Re: Generic DECLARE SQL-statement ???
Posted in 1993
michel@taz.de ($ MiJa) writes (re-formatted): > I'm writing an abstraction layer in C++ for the INFORMIX ESQL/C > interface. I'm somewhat stuck with the problem of writing a generic > DECLARE statement with respect to the cursor name. As far as I know you > cannot put a DECLARE into a PREPARE statement, so I've found no way to > use a C-string as a cursor name in ESQL/C. The only solution I've > found is to provide a fixed number of cursors in that layer, which are > used stack-like. This solution works as far nobody wants to open more > cursors than I provide at the same time, but it is not what I wanted. > > Any suggestions ??? I did this a while back, esqlc parses the DECLARE and puts a static cursor declaration at the top of the output file, so you can't create cursors at run time from esql/c. The only way around this was to write pure C++, allocating and initialising the various informix structures manually, and directly using some of the private esql/c function calls otherwise generated by esql, which are undocumented and therefore could change at a whim. Other databases provide a pure C library interface to their engines, and INFORMIX SHOULD SERIOUSLY CONSIDER EITHER DOING THIS, OR DOCUMENTING AND SUPPORTING THE CODE THAT ESQL/C GENERATES (IMHO). Anyway I don't think I'm at liberty to send the whole thing to you, but here's my Cursor.h (header files are public aren't they?) which could get you going. 8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<---- #ifndef CURSOR_H #define CURSOR_H # ident "$Id: Cursor.h,v 1.2 1992/10/23 13:25:47 bill Exp bill $" /*--------------------------------------------------- * * Module: Cursor.h * * Purpose: Cursor definition * * Author: William Hails * * Date: Tue Oct 6 09:49:24 BST 1992 * * Log: $Log: Cursor.h,v $ * Revision 1.2 1992/10/23 13:25:47 bill * First WORKING version of Cursor. * * Revision 1.1 1992/10/06 16:08:52 bill * Initial revision * * *---------------------------------------------------*/ #pragma interface // include all the informix headers extern "C" { #include <sqlhdr.h> #include <sqlca.h> #include <sqlda.h> #include <sqlstype.h> #include <sqltypes.h> #include <decimal.h> #include <ctools.h> #include <datetime.h> } class Cursor { sqlda *udesc; char *buffer; char *cursorname; _SQCURSOR SQC; sqlca_s sqlca; char *_sqlwarn; char *select; public: Cursor(const char * ...); ~Cursor(); int fetch(int nargs ...); long sqlcode() { return sqlca.sqlcode; } long sqlerrd(int n) { if (n < 6 && n >= 0) return sqlca.sqlerrd[n]; else return -1; } char sqlwarn(int n) { if (n < 8 && n >= 0) return _sqlwarn[n]; else return '0'; } char *rgetmsg(short=0); // return value is static, do NOT delete }; #endif /* CURSOR_H */ =========================================================================== | Bill Hails <bill@tardis.co.uk> | | | C.L.I. Connect Ltd. | README: permission denied | | 19, Quarry St., Guildford, Surrey | | | GU1 3UY. Tel (UK) 0483 300 200 | | ===========================================================================