INFORMIX
Informix-ESQL/C Programmer's Manual
Chapter 1: Programming with INFORMIX-ESQL/C
Home Contents Index Master Index New Book

What Is INFORMIX-ESQL/C?

ESQL/C is an SQL application programming interface (API) that enables you to embed Structured Query Language (SQL) statements directly into a C program. The ESQL/C preprocessor, which the esql command calls, converts each SQL statement and all Informix-specific code to C.

ESQL/C consists of the following software components:

WIN NT/95

ESQL/C Executable Files for Windows

For Windows environments, the ESQL/C product contains the following additional executable files:

These ESQL/C executable files are located in the %INFORMIXDIR%\bin, %INFORMIXDIR%\lib, and %INFORMIXDIR%\demo directories.
%INFORMIXDIR% represents the value of the INFORMIXDIR environment variable.

ESQL/C Library Functions

The ESQL/C library contains a set of C functions that you can use in your application. These functions fall into the following categories:

To access a database server through an ESQL/C application

    1. Write embedded SQL statements and calls to ESQL/C library functions into your C code to create an ESQL/C program.

    2. Convert the ESQL/C program to a C executable file with the esql command.

    3. Repeat step 2 as needed to remove programming errors.

The following sections provide detailed instructions for steps 1 and 2.

Creating an ESQL/C Program

An ESQL/C source file can contain the following types of statements:

For information on C preprocessor directives and C language statements, refer to a C programming text. This chapter provides an overview of the ESQL/C preprocessor directives (page 1-12), embedded SQL statements (page 1-17), and host variables (page 1-27).

Your ESQL/C source code filename can have either of the following forms:

The particular suffix that your ESQL/C source file has determines the default order in which that source file gets compiled by the esql command. The .ec suffix is the default suffix. For more information on the .ecp suffix and the non-default order of compilation, see "Running the C Preprocessor Before the ESQL/C Preprocessor".

Compiling an ESQL/C Program

You type the esql command to compile your ESQL/C program. The esql command passes your ESQL/C source file to the ESQL/C preprocessor and to the C compiler. It passes along options that are specific to both the ESQL/C preprocessor and the C compiler to preprocess, compile, and link your ESQL/Cprogram.

ESQL/C Preprocessor

To preprocess, compile, and link a program that contains ESQL/C statements, you must pass it through the ESQL/C preprocessor. You use the esql command to run the preprocessor on your ESQL/C source file and create an executable file. The esql command follows these steps to carry out the conversion:

The esql command processor is installed as part of the ESQL/C product. Before you use esql, make sure that:

    For information on how to set the INFORMIXDIR and PATH variables, see the Client Products Installation Guide for your operating system.

For a detailed explanation of the syntax of the esql command, see "Using the esql Command".

Warning: The C code that the ESQL/C preprocessor generates might change from one release of the product to the next. Therefore, do not design ESQL/C programs that depend on how Informix implements the functionality and features of the product in the C code that the ESQL/C preprocessor generates. Instead, develop your programs with the functionality and features of the product that this manual describes.

C Preprocessor and Compiler

The esql command does not itself compile and link the ESQL/C program. Instead, the C preprocessor preprocesses the C language preprocessing directives. The C compiler performs the compilation, and it also calls a link editor to link the C object files. The esql command calls the C compiler to initiate this process, but its main task is to translate ESQL/C code to C code.

Your ESQL/C source file contains commands for the C preprocessor (directives of the form #directive). In the case of the default order of compilation, these C directives have no effect on ESQL/C statements but take effect in the usual way when the C compiler processes the source file.

If you choose the option of running the C preprocessor on the ESQL/C source file before the ESQL/C preprocessor, you can use the C language #define and typedef directives to define ESQL/C host variables. For more information, see "Running the C Preprocessor Before the ESQL/C Preprocessor".

The C compiler takes the following actions:

For information about command-line options that affect the compilation and linking steps, see "Specifying a Particular C Compiler" and "General Options That Affect Linking".

Default Compilation Order

Once you have created an ESQL/C program file, you run the esql command on that file. By default, the ESQL/C preprocessor runs first and translates the embedded SQL statements in the program into ESQL/C function calls that communicate with the database server. The ESQL/C preprocessor produces a C source file and calls the C compiler. The C compiler then preprocesses and compiles your source file and links any other C source file, object file, or library file the same way as any other C program. If esql does not encounter errors in one of these steps, it generates an executable file. You can run the compiled ESQL/C program as you would any C program. When the program runs, it calls the ESQL/C library procedures; they set up communications with the database server to carry out the SQL operations.

Figure 1-1 illustrates the process by which an ESQL/C program becomes an executable program.

Figure 1-1
Relationship Between INFORMIX-ESQL/C and C

To preprocess, compile, and link a C program that contains ESQL/C statements, you must pass it through the ESQL/C preprocessor. Use the esql command to preprocess the ESQL/C source file and create an executable file. The esql command follows these steps to carry out the conversion:

Important: Keep in mind that with the default order of compilation, esql handles ESQL/C preprocessor directives before it calls the C compiler. Therefore, the ESQL/C directives take effect before the C compiler performs any preprocessing. You cannot access ESQL/C definitions within C preprocessor directives, nor can you use the C preprocessor to perform conditional compilation of ESQL/C statements.

Running the C Preprocessor First

With this release, you can either let the compilation of your ESQL/C source file follow the default order or let the C preprocessor run on the source file first, and then pass that file to the ESQL/C preprocessor. This feature is useful in case you want your ESQL/C program to access C preprocessor directives. For more information on this option, see "Running the C Preprocessor Before the ESQL/C Preprocessor".




Informix-ESQL/C Programmer's Manual, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.