Because an ecpg application is written in C, you will need a C compiler, the GNU make utility, and the ecpg preprocessor and library on your system before you can try the examples in this chapter.

The makefile for this chapter follows:

 1 #

 2 # Filename: makefile

 3 #

 4 INCLUDES   = -I/usr/include/pgsql


 6 CFLAGS    += $(INCLUDES) -g

 7 LDFLAGS   += -g

 8 LDLIBS    += -lecpg -lpq


10 ECPG       = /usr/bin/ecpg


12 .SUFFIXES: .pgc

13 .pgc.c:

14       $(ECPG) $(ECPGFLAGS) $?


16 ALL  = client1a client1b client2a client2b client2c

17 ALL += client3a client3b client3c client3d client3e client3f

18 ALL += client4.pgc


20 all: $(ALL)


22 clean:

23        rm -f $(ALL) *~

The examples in this chapter follow the normal PostgreSQL convention of naming ecpg source files with the extension .pgc. The makefile rules on lines 11 through 13 tell make that it can convert a .pgc file into a .c file by running the ecpg preprocessor.

For the examples in this chapter, I have used a version of the ecpg package that has not been released in an official distribution at the time of writing. You need to use a version of PostgreSQL later than version 7.2.1 to compile some of the sample applications. (Version 7.2.1 did not include the -c flag that I will discuss later, but releases after 7.2.1 should include that feature.) This feature is not required for most ecpg applications.

Assuming that you have the prerequisites in place, let's start out by developing a simple client that will connect to a database using ecpg.

    Part II: Programming with PostgreSQL