Installing and configuring ECPGPlus v17

On Windows, ECPGPlus is installed by the EDB Postgres Advanced Server installation wizard as part of the Database Server component. On Linux, you install ECPGPlus by running an executable.

Installing ECPGPlus

On Linux, install with the edb-as<xx>-server-devel RPM package, where <xx> is the EDB Postgres Advanced Server version number. On Linux, the executable is located in:

/usr/edb/as14/bin

On Windows, the executable is located in:

C:\Program Files\edb\as14\bin

When invoking the ECPGPlus compiler, the executable must be in your search path (%PATH% on Windows, $PATH on Linux). For example, the following commands set the search path to include the directory that holds the ECPGPlus executable file ecpg.

On Windows:

set EDB_PATH=C:\Program Files\edb\as14\bin
set PATH=%EDB_PATH%;%PATH%

On Linux:

export EDB_PATH==/usr/edb/as14/bin
export PATH=$EDB_PATH:$PATH

Constructing a makefile

A makefile contains a set of instructions that tell the make utility how to transform a program written in C that contains embedded SQL into a C program. To try the examples, you need:

  • A C compiler and linker
  • The make utility
  • ECPGPlus preprocessor and library
  • A makefile that contains instructions for ECPGPlus

The following code is an example of a makefile for the samples included in this documentation. To use the sample code, save it in a file named makefile in the directory that contains the source code file.

INCLUDES = -I$(shell pg_config --includedir)
LIBPATH = -L $(shell pg_config --libdir)
CFLAGS += $(INCLUDES) -g
LDFLAGS += -g
LDLIBS += $(LIBPATH) -lecpg -lpq

.SUFFIXES: .pgc,.pc

.pgc.c:
     ecpg -c $(INCLUDES) $?

.pc.c:
     ecpg -C PROC -c $(INCLUDES) $?

The first two lines use the pg_config program to locate the necessary header files and library directories:

INCLUDES = -I$(shell pg_config --includedir)
LIBPATH = -L $(shell pg_config --libdir)

The pg_config program is shipped with EDB Postgres Advanced Server.

make knows to use the CFLAGS variable when running the C compiler and LDFLAGS and LDLIBS when invoking the linker. ECPG programs must be linked against the ECPG runtime library (-lecpg) and the libpq library (-lpq).

CFLAGS += $(INCLUDES) -g
LDFLAGS += -g
LDLIBS += $(LIBPATH) -lecpg -lpq

The sample makefile tells make how to translate a .pgc or a .pc file into a C program. Two lines in the makefile specify the mode in which the source file is compiled. The first compile option is:

.pgc.c:
      ecpg -c $(INCLUDES) $?

The first option tells make how to transform a file that ends in .pgc (presumably, an ECPG source file) into a file that ends in .c (a C program), using community ECPG, without the ECPGPlus enhancements. It invokes the ECPG precompiler with the -c flag, which instructs the compiler to convert SQL code into C, using the value of the INCLUDES variable and the name of the .pgc file.

.pc.c:
    ecpg -C PROC -c $(INCLUDES) $?

The second option tells make how to transform a file that ends in .pg (an ECPG source file) into a file that ends in .c (a C program) using the ECPGPlus extensions. It invokes the ECPG precompiler with the -c flag, which instructs the compiler to convert SQL code to C. It also uses the -C PROC flag, which instructs the compiler to use ECPGPlus in Pro*C-compatibility mode, using the value of the INCLUDES variable and the name of the .pgc file.

When you run make, pass the name of the ECPG source code file you want to compile. For example, to compile an ECPG source code file named customer_list.pgc, use the command:

make customer_list

The make utility:

  1. Consults the makefile located in the current directory.
  2. Discovers that the makefile contains a rule that compiles customer_list.pgc into a C program (customer_list.c).
  3. Uses the rules built into make to compile customer_list.c into an executable program.

ECPGPlus command line options

In the sample makefile, make includes the -C option when invoking ECPGPlus to invoke ECPGPlus in Pro*C-compatible mode.

If you include the -C PROC keywords at the command line, in addition to the ECPG syntax, you can use Pro*C command line syntax. For example:

$ ecpg -C PROC INCLUDE=/usr/edb/as14/include acct_update.c

To display a complete list of the other ECPGPlus options available, in the ECPGPlus installation directory, enter:

./ecpg --help

The command line options are:

OptionDescription
-cGenerate C code from embedded SQL code.
-C <mode>Specify a compatibility mode:

INFORMIX

INFORMIX_SE

PROC
-D <symbol>Define a preprocessor symbol.

The -D keyword isn't supported when compiling in PROC mode. Instead, use the Oracle-style ‘DEFINE=’ clause.
-hParse a header file. This option includes option '-c'.
-iParse system. Include files as well.
-I <directory>Search <directory> for include files.
-o <outfile>Write the result to <outfile>.
-r <option>Specify runtime behavior. The value of <option> can be:

no_indicator Don't use indicators, but instead use special values to represent NULL values.

prepare Prepare all statements before using them.

questionmarks Allow use of a question mark as a placeholder.

usebulk Enable bulk processing for INSERT, UPDATE, and DELETE statements that operate on host variable arrays.
--regressionRun in regression testing mode.
-tTurn on autocommit of transactions.
-lDisable #line directives.
--helpDisplay the help options.
--versionOutput version information.
Note

If you don't specify an output file name when invoking ECPGPlus, the output file name is created by removing the .pgc extension from the file name and appending .c.