Documentation
 
 
 

Chapter 28. ECPG - Embedded SQL in C

28.1. Introduction

Embedded SQL in C (ECPG) is a program written in C with parts of the program written in SQL.Variables used in SQL statements and SQL commands are written in specially marked sections of the C program. To build the program, the source code is first passed through an embedded SQL preprocessor which converts it to an ordinary C program, and then it is processed by a C compiler. The embedded SQL C preprocessor converts the SQL statements that were used in the program to function calls with the variables used as arguments.

At link time, the C object module is linked to a library that contains the functions used in the program. These functions fetch the information from the arguments, perform the SQL query using the ordinary interface (libpq) and put back the result in the arguments dedicated for the output.

As stated, programs written for the embedded SQL interface are normal C programs with special code inserted to perform database-related actions. This special code always has the form:

EXEC SQL ...;

The embedded SQL statements syntactically take the place of a C statement. Depending on the particular statement, they may appear at the global level or within a function. Embedded SQL statements follow the case-sensitivity rules of normal SQL code, and not those of C.

 
 ©2004-2007 EnterpriseDB All Rights Reserved