Creating an ESQL/C program

About this task

To create an ESQL/C program:

Procedure

  1. Embed statements in a C-language source program to perform the following tasks:
    • Define host variables to store data for transfer between the program and the database server.
    • Access the database server through SQL statements.
    • Provide directives for the preprocessor and the C compiler.
  2. Preprocess the source file with the esql command to create a C-language source file and start the C compiler.
  3. As necessary, correct errors reported by the preprocessor and the compiler and repeat step 2.
  4. Using the esql command, link the compiled object code into one or more executable files.

Results

The source file can contain the following types of statements:
Preprocessor directives
preprocessor directives to create simple macro definitions, include files, and perform conditional compilation.

C preprocessor directives to create macro definitions, include system and C source files, and perform conditional C compilation.

Language statements
host variable definitions to store data for transfer between the program and the database server.

Embedded SQL statements to communicate with the database server.

C language statements to provide program logic.

For information about C preprocessor directives and C language statements, see a C programming text.

Your source code file name can have either of the following forms:
  • esqlc_source.ec
  • esqlc_source.ecp

The particular suffix that your 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 about the .ecp suffix and the non-default order of compilation, see Run the C preprocessor before the ESQL/C preprocessor.