Using ESQL/C with C++
Posted in 1995
Hi,
One of the more common requests these days is:
How do I compile ESQL/C code for use with C++?
There have been a variety of answers, but not any one systematic answer.
Now there is what I believe is a definitive answer -- it's all in the
attached shell archive.
What do you get?
* Updated ESQL/C prototypes for 4.00, 4.1x and 5.0x
* An esql++ compiler
* A pair of patch files for modifying youe standard ESQL/C compiler
* A minimal test application.
* No documentation apart from this message!
What do you need to do?
* Unpack the shell archive.
* Place the esql* headers in either $INFORMIXDIR/incl (version 4)
or $INFORMIXDIR/incl/esql (version 5 or later)
* Place the esql++ script in $INFORMIXDIR/bin
* Decide which version of ESQL/C you are using and set the
ESQLC_VERSION environment variable to a value such as:
export ESQLC_VERSION=506 # 5.06.UC1
* Optionally modify esql++ to give the correct default value of
of ESQLC_VERSION.
* Decide which C++ compiler you use -- if it isn't CC, set:
export INFORMIXC=g++* Try compiling the test application:
esql++ -o testapp testmain.ec testsub.ec
* Run it against your local stores database -- it should say '2'.
What if you can't modify your INFORMIXDIR?
* Copy $INFORMIXDIR/bin/esql to somewhere where you can modify it
(eg /some/where/bin/esql)
* Patch it.
* Place the headers in another directory (eg /some/where/include).
* Modify esql++ so that:
-- arglist starts of with -I/some/where/include as one component
-- ESQL defaults to /some/where/bin/esql
What about version 8 or later ESQL/C?
* I haven't been able to test that; it isn't available to me either.
* With luck, you won't need this at all.
* Given the normal way things work, you will probably need to modify the
case to include 8 (or whatever) where it currently has 7[0-9][0-9].
Testing?
* Tested against Informix-ESQL/C versions 4.12.UC1, 5.03.UC1, 5.04.UC1,
5.05.UC1, 5.06.UC1, 6.00.UE1.
Bugs?
* Life will get very difficult if you routinely pass arguments with a
single single quote in them to your compiler:
esql++ -DOPENQUOTE="'" -DSOMMAT="string with blanks" thingy.ec
I do have a solution: it is another program called escape which
deals with precisely that sort of problem.
arglist="$arglist `escape $arg`"
But that requires some more source and isn't generally necessary.
Any problems? Better let me know. Especially if you've got a fix.
Yours,
Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>
: "@(#)shar.sh 1.9"
#! /bin/sh
#
# This is a shell archive.
# Remove everything above this line and run sh on the resulting file.
# If this archive is complete, you will see this message at the end:
# "All files extracted"
#
# Created: Tue Dec 12 17:53:23 PST 1995 by johnl at Informix Software Ltd.
# Files archived in this archive:
# esql++
# esql.v4.patch
# esql.v5.patch
# esql4_00.h
# esql4_10.h
# esql5_00.h
# esqlc.h
# esqllib.h
# testapp.h
# testmain.ec
# testsub.ec
#
#--------------------
if [ -f esql++ -a "$1" != "-c" ]
then echo shar: esql++ already exists
else
echo 'x - esql++ (1825 characters)'
sed -e 's/^X//' >esql++ <<'SHAR-EOF'
X: "@(#)esql++.sh 1.1 95/12/12"
X#
X# ESQL/C++ compiler script
X# For Informix-ESQL/C Versions 4.00, 4.1x, 5.0x, 6.0x, 7.1x or later
X
X#################################################################
X# Prerequisite (mandatory) change to installed esql script for
X# Version 4.00, 4.1x, 5.0x ESQL/C compiler scripts.
X# diff old.esql new.esql
X# < CC="cc"
X# --
X# > CC=${INFORMIXC:-"cc"}
X#################################################################
X# Additional prerequisite for pre-6.00 versions of ESQL/C:
X# -- These extra headers must be installed in:
X# * $INFORMIXDIR/incl/esql -- Version 5.00
X# * $INFORMIXDIR/incl -- Version 4.1x or 4.00
X# -- esqlc.h, esqllib.h, esql5_00.h, esql4_10.h, esql4_00.h
X#################################################################
X
X: ${ESQL:=esql}
X: ${ESQLC_VERSION:=600}
X
XINFORMIXC=${INFORMIXC:-CC}
Xexport INFORMIXC
X
Xtmpfile=${TMPDIR:-/tmp}/esql.$$
Xtrap "rm -f $tmpfile; exit 1" 0 1 2 3 13 15
X
Xestat=0
Xarglist="-DESQLC_VERSION=${ESQLC_VERSION}"
Xwhile [ $# -gt 0 ]
Xdo
X arg=$1
X case "$arg" in
X *.ec)
X oname=`basename $arg .ec`.c
X if eval $ESQL $arglist -e $arg
X then : OK
X else estat=1
X fi
X case $ESQLC_VERSION in
X 4[01][0-9])
X {
X echo '#include "esqlc.h"'
X sed '/_iq[a-z]/s/(char \\*) *0/0/g' $oname
X } > $tmpfile
X mv $tmpfile $oname
X ;;
X 50[0-9]|60[0-9]|7[0-9][0-9])
X {
X echo '#include "esqlc.h"'
X sed '1,/^$/d' $oname
X } > $tmpfile
X mv $tmpfile $oname
X ;;
X esac
X arglist="$arglist $oname"
X ;;
X *.o | *.c | *.cc | *.cpp)
X arglist="$arglist $arg"
X ;;
X -o)
X if [ $# -lt 1 ]
X then error "-o option requires argument"
X fi
X shift
X output="-o $1"
X ;;
X -V)
X exec $ESQL $arg
X ;;
X *)
X arglist="$arglist '$arg'"
X ;;
X esac
X shift
Xdone
X
Xrm -f $tmpfile
Xtrap 0 1 2 3 13 15
X
Xif [ $estat != 0 ]
Xthen exit 1
Xfi
X
Xeval exec $ESQL $arglist $output
SHAR-EOF
chmod 555 esql++
if [ `wc -c <esql++` -ne 1825 ]
then echo shar: esql++ unpacked with wrong size
fi
# end of overwriting check
fi
#--------------------
if [ -f esql.v4.patch -a "$1" != "-c" ]
then echo shar: esql.v4.patch already exists
else
echo 'x - esql.v4.patch (353 characters)'
sed -e 's/^X//' >esql.v4.patch <<'SHAR-EOF'
X*** esql Tue Dec 12 17:22:46 1995
X--- esql4 Tue Dec 12 17:17:24 1995
X***************
X*** 25,31 ****
X : '
X INFDIR=${INFORMIXDIR=/usr/informix}
X PREPCC=${INFDIR}/lib/esqlc
X! CC="cc"
X STAT=0
X TYPE=unix
X ANSI=
X--- 25,31 ----
X : '
X INFDIR=${INFORMIXDIR=/usr/informix}
X PREPCC=${INFDIR}/lib/esqlc
X! CC=${INFORMIXC:-"cc"}
X STAT=0
X TYPE=unix
X ANSI=
SHAR-EOF
chmod 664 esql.v4.patch
if [ `wc -c <esql.v4.patch` -ne 353 ]
then echo shar: esql.v4.patch unpacked with wrong size
fi
# end of overwriting check
fi
#--------------------
if [ -f esql.v5.patch -a "$1" != "-c" ]
then echo shar: esql.v5.patch already exists
else
echo 'x - esql.v5.patch (357 characters)'
sed -e 's/^X//' >esql.v5.patch <<'SHAR-EOF'
X*** esql Tue Dec 12 17:22:34 1995
X--- esql5 Tue Dec 12 17:16:18 1995
X***************
X*** 25,31 ****
X : '
X INFDIR=${INFORMIXDIR=/usr/informix}
X PREPCC=${INFDIR}/lib/esql/esqlc
X! CC="cc"
X STAT=0
X TYPE=unix
X A=
X---