Database Reference
In-Depth Information
Embedded SQL in C - ECPG
The Embedded C for PostgreSQL ( ECPG ) program is a combination of C language
and SQL commands. In the previous chapters, we have discussed the SQL
commands in detail as well as communication with PostgreSQL in C language. The
embedded SQL command is written in the .pgc iles in the marked section. This is a
two-step task:
• The irst step is to create a .pgc ile and compile with ECPG (embedded SQL
preprocess). The ECPG program generates a C program
• In the second step, the C program need to be compiled by the standard
C compiler
Hence, in this chapter, we will learn how to write the .pgc ile, and compile it using
the ASP and C compilers.
In this chapter, we will learn the following:
• Combining C language with SQL commands
• Constructs of the .pgc iles
• Different steps to compile the .pgc ile
Writing ECPG programs
Here is the sample code of the .pgc ile; we will discuss each and every command
in detail in the following sections. This following sample code connects to the
PostgreSQL server using ECPG and gets the PostgreSQL version. The code has four
parts, the DECLARE section where we can declare the variables and the second part is
where we connect to PostgreSQL using the EXEC SQL CONNECT command.
Search WWH ::




Custom Search