Creating Informix ESQL/C Extensions

C-Extension libraries can be created from ESQL/C sources, as long as you have an Informix® ESQL/C compiler which is compatible with your Genero runtime system. In order to create these user extensions, you must first compile the .ec sources to object files by including the fglExt.h header file. Then you must create the shared library by linking with additional SQL libraries to resolve the functions used in the .ec source to execute SQL statements.

You can compile .ec extensions with the native Informix esql compiler. This section describes how to use the Informix esql compiler.

The following example shows how to compile and link an extension library with Informix esql compiler:

Linux™ command-line example:

esql -c -I$FGLDIR/include myext.ec 
gcc -c -I$FGLDIR/include -fPIC cinterf.c 
gcc -shared -o myext.so myext.o cinterf.o -L$FGLDIR/lib -lfgl \
    -L$INFORMIXDIR/lib -L$INFORMIXDIR/lib/esql `esql -libs`

Windows™ command-line example (using Microsoft™ Visual C++):

esql -c myext.ec -I%FGLDIR%/include 
cl /DBUILDDLL /I%FGLDIR%/include /c cintref.c 
esql -target:dll -o myext.dll myext.obj cinterf.obj %FGLDIR%\lib\libfgl.lib

When using Informix esql, you link the extension library with Informix client libraries. These libraries will be shared by the extension module and the Informix database driver loaded by the Genero runtime system. Since both the extension functions and the runtime database driver use the same functions to execute SQL queries, you can share the current SQL connection opened in the Genero program to execute SQL queries in the extension functions. However, mixing connection management instructions (DATABASE, CONNECT TO) as well as database creation can produce unexpected results. For example you cannot do a CREATE DATABASE in your ESQL/C extension, and expect that the main program can use this database to execute SQL statements.