Database Reference
In-Depth Information
The following is the content of
MakeFile
to compile all the examples:
CC=gcc
POSTGRESQL_INCLUDE=/usr/local/pgsql.master/include
POSTGRESQL_LIB=/usr/local/pgsql.master/lib
CFLAGS=-I$(POSTGRESQL_INCLUDE)
LD_FLAGS=-L$(POSTGRESQL_LIB)
all:
$(CC) connection.c -o connection $(CFLAGS) $(LD_FLAGS) -
lpq
$(CC) exec.c -o exec $(CFLAGS) $(LD_FLAGS) -lpq
$(CC) retrieve.c -o retrieve $(CFLAGS) $(LD_FLAGS) -lpq
connection:
$(CC) connection.c -o connection $(CFLAGS) $(LD_FLAGS) -
lpq
exec:
$(CC) exec.c -o exec $(CFLAGS) $(LD_FLAGS) -lpq
retrieve:
$(CC) retrieve.c -o retrieve $(CFLAGS) $(LD_FLAGS) -lpq
clean:
rm -rf *.o connection exec retrieve
Using PQinish
The
PQfinish
function is used to close the connection with the server. It takes the
connection object
PGconn
pointer returned by the
PQconnectdb
,
PQsetdbLogin
,
or
PQsetdb
function. The syntax for
PQfinish
is as follows:
Void PQfinish(PGconn *conn);
Using PQreset
The
PQreset
function closes the previous connection and establishes a new
connection. Sometimes, we need a new connection after closing the previous
connection. Instead of calling
PQfinish
and
PQconnectdb
, the
PQreset
function
closes the connection and reconnects with the server. The syntax for
PQreset
is
as follows:
Void PQreset(PGconn *conn);