PostgreSQL

Скачать в pdf «PostgreSQL»


Usage


Preprocessing for Compilation


An embedded SQL source file must be preprocessed before compilation: ecpg [ -d ] [ -o file ] file .pgc


where the optional -d flag turns on debugging. The .pgc extension is an arbitrary means of denoting ecpg source.


You may want to redirect the preprocessor output to a log file.


Compiling and Linking


Assuming the Postgres binaries are in /usr/local/pgsql, you will need to compile and link your preprocessed source file:


gcc -g -I /usr/local/pgsql/include [ -o file ] file.c -L /usr/local/pgsql/lib -lecpg -lpq


Grammar


Libraries


The preprocessor will prepend two directives to the source:


#include <ecpgtype.h>


#include <ecpglib.h>


Variable Declaration


Variables declared within ecpg source code must be prepended with: exec sql begin declare section;


Similarly, variable declaration sections must terminate with: exec sql end declare section;


Note: Prior to version 2.1.0, each variable had to be declared on a separate line. As of version 2.1.0 multiple variables may be declared on a single line:


char foo(16), bar(16);


Error Handling


The SQL communication area is defined with: exec SQL include sqlca;


Note: The sqlca is in lowercase. While SQL convention may be followed, i.e., using uppercase to separate embedded SQL from C statements, sqlca (which includes the sqlca.h header file) MUST be lowercase. This is because the EXEC SQL prefix indicates that this INCLUDE will be parsed by ecpg. ecpg observes case sensitivity (SQLCA.h will not be found). EXEC SQL INCLUDE can be used to include other header files as long as case sensitivity is observed.

Скачать в pdf «PostgreSQL»