snorri@strengur.is (Snorri Bergmann) (04/25/91)
Has anyone used Informix ESQL/C with C++ ? The problem seems to be that you need to define prototypes for every function that you use, otherwise you get compile (C++) time errors. So the question is: Has anyone defined those prototypes for C++ in order to compile code generated by Infomrix esql/c successfully? Thank you all in advance, -- Snorri Bergmann | Internet: snorri@strengur.is Strengur Consulting Engineers | Phone: +354 1 685130 Storhofdi 15 | Telefax: +354 1 680628 112 Reykjavik Iceland
hpe@cs.hut.fi (Hannu Peltonen) (04/25/91)
We use Informix 4.0 OnLine ESQL with HP C++ 2.0 (i.e., AT&T 2.0 cfront). We have written a header file that declares both the functions to be called by the application programmer and the functions called from the code generated by the preprocessor. The list of preprocessor functions may not be complete; we have added functions as we have encountered them in the generated code. To compile a C++ program with embedded SQL, we use a simple command script. The script removes C++ style comments ("// xxxxx"), which confuse the Informix preprocessor, runs the preprocessor, and finally compiles the C++ program. This has worked fine. Note that if a parameter of a function is to be used as an Informix host variable, one has to declare an extra variable. For example: void f (int n) { $ int nn = n; $ select ... where x = $n; ... } As a small detail, which has nothing to do with C++, we have noticed that the Informix "$include" statement fails to add a "#line" directive after the lines it has inserted. This means that the error messages from C or C++ compiler between the "$include" statement and the next ESQL statement have invalid line numbers. This problem can be avoided simply by writing #include <sqlca.h> instead of $ include sqlca; We have not written any "real" C++ interface which could perhaps represent tables as classes. The header file is as follows: ------------------ BEGIN HEADER FILE --------------------------------------- #ifndef _informix_ #define _informix_ #include <time.h> #ifndef TU_YEAR #include <datetime.h> #endif extern "C" { int bycmpr (const char *, const char *, int); void bycopy (const char *, char *, int); void byfill (char *, int, char); int byleng (const char *, int); void ldchar (const char *, char *, int); void rdownshift (char *); int rgetmsg (short, char *, short); int risnull (int, const char *); void rsetnull (int, char *); int rstod (const char *, double *); int rstoi (const char *, int *); int rstol (const char *, long *); int rtypalign (int, int); int rtypmsize (int, int); const char *rtypname (int); int rtypwidth (int, int); void rupshift (char *); void sqlbreak (); void sqlexit (); void sqlstart (); void stcat (const char *, char *); void stchar (const char *, char *, int); int stcmpr (const char *, const char *); void stcopy (const char *, char *); int stleng (const char *); void dtcurrent (dtime_t *); int dtcvasc (const char *, dtime_t *); int dtextend (const dtime_t *, dtime_t *); void dttoasc (const dtime_t *, char *); int incvasc (const char *, intrvl_t *); int intoasc (const intrvl_t *, char *); // The following functions are called from the code generated by the // Informix precompiler. void _iqdclcur (...); void _iqcopen (...); void _iqnftch (...); void _iqclose (...); void _iqdatabase (...); void _iqslct (...); void _iqprepare (...); void _iqdscribe (...); void _iqddclcur (...); void _iqfree (...); void _iqstmnt (...); void _iqeximm (...); void _iqbeginwork (...); void _iqcommit (...); void _iqrollback (...); void _iqxecute (...); } #endif -------------------- END HEADER FILE ----------------------------------------- -- ------------------------------------------------------------------------- Hannu Peltonen Telephone : +358-0-451 3244 Helsinki University of Technology FAX : +358-0-451 3293 Department of Computer Science Internet : hpe@cs.hut.fi Otakaari 1, SF-02150 Espoo, FINLAND -------------------------------------------------------------------------
kelly@bellahs.UUCP (Kelly Kingdon) (04/25/91)
In article <741@strengur.is>, snorri@strengur.is (Snorri Bergmann) writes: > Has anyone used Informix ESQL/C with C++ ? The problem seems to be that > you need to define prototypes for every function that you use, otherwise > you get compile (C++) time errors. > > So the question is: > Has anyone defined those prototypes for C++ in order to compile > code generated by Infomrix esql/c successfully? > > Thank you all in advance, > -- > Snorri Bergmann | Internet: snorri@strengur.is > Strengur Consulting Engineers | Phone: +354 1 685130 > Storhofdi 15 | Telefax: +354 1 680628 > 112 Reykjavik Iceland Yes we are using esql with C++. We created the following include file that resolves the C++ prototype errors: extern "C" { int rtypmsize (int, int); int rtypalign (int, int); void rsetnull (int, void *); int risnull (int, void *); void _iqbeginwork( ... ); void _iqcopen( ... ); void _iqdatabase( ... ); void _iqdclcur( ... ); void _iqddclcur( ... ); void _iqclose( ... ); void _iqcommit( ... ); void _iqdbclose( ... ); void _iqfree( ... ); void _iqnftch( ... ); void _iqprepare( ... ); void _iqstmnt( ... ); void _iqdscribe( ... ); void _iqslct( ... ); void _iqxecute( ... ); } Hope this helps! Kelly ============================================================================ = Kelly Kingdon Bell Atlantic Healthcare Systems = = Phone: (415) 925-0121 Greenbrae, CA. = = = = E-mail: uunet!bellahs!kelly uunet!kelly@bellahs.UUCP = = = disclaimer: My opinions are my own and do not reflect those of my employer
davidm@uunet.UU.NET (David S. Masterson) (04/25/91)
>>>>> On 25 Apr 91 08:12:27 GMT, hpe@cs.hut.fi (Hannu Peltonen) said:
Hannu> We use Informix 4.0 OnLine ESQL with HP C++ 2.0 (i.e., AT&T 2.0
Hannu> cfront). We have written a header file that declares both the
Hannu> functions to be called by the application programmer and the functions
Hannu> called from the code generated by the preprocessor.
Hannu> The list of preprocessor functions may not be complete; we have added
Hannu> functions as we have encountered them in the generated code.
Hannu> To compile a C++ program with embedded SQL, we use a simple command
Hannu> script. The script removes C++ style comments ("// xxxxx"), which
Hannu> confuse the Informix preprocessor, runs the preprocessor, and finally
Hannu> compiles the C++ program.
Wouldn't it be simpler (and less prone to problems when either C++ or ESQL/C
are upgraded) to embed the SQL in C-only functions and call those functions
from C++? That way the C++ stays in a C++ world and the ESQL/C preprocessor
is only used on stuff it was meant to be used on (C with embedded SQL).
Having taken Hannu's approach with C++ and VAX RDB, I can tell you that it was
no pretty picture when either VAX RDB or C++ were upgraded. If I could have
done it over, I think the C-only functions would be a more stable route until
the various vendors come up with real support for SQL/C++ code.
--
====================================================================
David Masterson Consilium, Inc.
(415) 691-6311 640 Clyde Ct.
uunet!cimshop!davidm Mtn. View, CA 94043
====================================================================
"If someone thinks they know what I said, then I didn't say it!"