Re: Informix ESQL/C with C++
Posted in 1991
Path: emory!gatech!purdue!sample.eng.ohio-state.edu!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!news.funet.fi!funic!santra!cs.hut.fi!hpe
From: hpe@cs.hut.fi (Hannu Peltonen)
Newsgroups: comp.databases
Message-ID: <HPE.91Apr25101227@hutcs.hut.fi>
Date: 25 Apr 91 08:12:27 GMT
References: <741@strengur.is>
Sender: news@santra.uucp (Cnews - USENET news system)
Organization: Helsinki University of Technology, Finland
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
-------------------------------------------------------------------------