.TH ECPG UNIX 11/28/98 PostgreSQL \fIPostgreSQL\fP .SH NAME ecpg - embedded SQL preprocessor for C / PostgreSQL .SH SYNOPSIS .\" \fBecpg\fR [-v ] [-t] [-I include-path ] [-o outfile ] file1 [ file2 ] [ ... ] \fBecpg\fR [-v ] [-t] [-I include-path ] [-o outfile ] file1 [ file2 ] [ ... ] .SH DESCRIPTION .B \fIecpg\fP is an embedded SQL preprocessor for C / PostgreSQL. It enables development of C programs with embedded SQL code. .PP .B \fIecpg\fP is ultimately intended to be as compliant as possible with the ANSI SQL-2 standard and existing commercial ESQL/C packages. .SH OPTIONS .B \fIecpg\fP interprets the following flags when it is invoked on the command line: .PP .PD 0 .TP 10 .BI \-v Print version information. .PD .TP .B \-t Turn off auto-transactin mode. .PD .TP .PD .TP .B \-I include-path Specify additional include path. Defaults are \., /usr/local/include, the PostgreSQL include path which is defined at compile time (default: /usr/local/pgsql/lib), /usr/include .PD .TP .B \-o Specifies that ecpg should write all its output to outfile. If no such option is given the output is written to foo.c (if the input file was named foo.pgc.) If the input file was named foo.bar the output file will be named foo.bar.c. .PD .TP .B file1, file2... The files to be processed. .\" .SH INSTALLATION The .B \fIecpg\fP preprocessor is built during the PostgreSQL installation. Binaries and libraries are installed into the PGBASE (i.e., /usr/local/pgsql/... ) subdirectories. .SH PREPROCESSING FOR COMPILATION .B \fIecpg\fP .\" (-d ) (-o file) file.pgc ( 2> ecpf.log) (-o file) file.pgc .LP .\" The optional \-d flag turns on debugging and 2> ecpg.log .\" redirects the debug output. The .pgc extension is an .\" arbitrary means of denoting ecpg source. The .pgc extension is an arbitrary means of denoting ecpg source. .SH COMPILING AND LINKING Assuming the \fIPostgreSQL\fP binaries are in /usr/local/pgsql: .LP gcc -g -i /usr/local/pgsql/include (-o file) file.c -L /usr/local/pgsql/lib -lecpg -lpq .SH ECPG GRAMMAR .LP .SH LIBRARIES .LP The preprocessor will prepend two directives to the source: .LP \fI#include \fP and \fI#include \fP .SH VARIABLE DECLARATION Variables declared within ecpg source code must be prepended with: .LP EXEC SQL BEGIN DECLARE SECTION; .LP Similarly, variable declaration sections must terminate with: .LP EXEC SQL END DECLARE SECTION; .LP 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: .LP char foo(16), bar(16); .LP .SH ERROR HANDLING The SQL communication area is defined with: .LP EXEC SQL INCLUDE sqlca; .LP NOTE: the lowercase `sqlca'. 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. .LP The sqlprint command is used with the EXEC SQL WHENEVER statement to turn on error handling throughout the program: .LP EXEC SQL WHENEVER sqlerror sqlprint; .LP EXEC SQL WHENEVER not found sqlprint; .LP PLEASE NOTE: this is *not* an exhaustive example of usage for the EXEC SQL WHENEVER statement. Further examples of usage may be found in SQL manuals (e.g., `The LAN TIMES Guide to SQL' by Groff and Weinberg.) .LP .SH CONNECTING TO THE DATABASE SERVER Prior to version 2.1.0 the database name was single quoted: .RS EXEC SQL CONNECT 'test1'; .RE .LP As of version 2.1.0, the syntax has been simplified: .LP .RS EXEC SQL CONNECT test1; .RE (The database name is no longer quoted.) .LP Specifying a server and port name in the connect statement is also possible as of version 6.4. of PostgreSQL. The syntax is: .LP .RS dbname[@server][:port] .RE .LP or .LP .RS :postgresql://server[:port][/dbname][?options] .RE .SH QUERIES .LP .SS Create Table: .LP EXEC SQL CREATE TABLE foo (number int4, ascii char(16)); .RS EXEC SQL CREATE UNIQUE index num1 on foo(number); .RE EXEC SQL COMMIT; .LP .SS Insert: .LP EXEC SQL INSERT INTO foo (number, ascii) .RS VALUES (9999, 'doodad'); .RE EXEC SQL COMMIT; .LP .SS Delete: .LP EXEC SQL DELETE FROM foo .RS WHERE number = 9999; .RE EXEC SQL COMMIT; .LP .SS Singleton Select: .LP EXEC SQL SELECT foo INTO :FooBar FROM table1 .RS WHERE ascii = 'doodad'; .RE .LP .SS Select using Cursors: .LP EXEC SQL DECLARE foo_bar CURSOR FOR .RS SELECT number, ascii FROM foo .RS ORDER BY ascii; .RE .RE EXEC SQL FETCH foo_bar INTO :FooBar, DooDad; .LP ... EXEC SQL CLOSE foo_bar; .RS EXEC SQL COMMIT; .RE .LP .SS Updates .LP EXEC SQL UPDATE foo .RS SET ascii = 'foobar' .RE .RS WHERE number = 9999; .RE EXEC SQL COMMIT; .LP .SH BUGS .LP The is no EXEC SQL PREPARE statement. .LP The complete structure definition MUST be listed inside the declare section. .LP See the TODO file in the source for some more missing features. .LP .SH "RETURN VALUE" .LP ecpg returns 0 to the shell on successful completion, -1 for errors. .LP .SH "SEE ALSO" .PD 0 .TP \fIcc\fP(1), \fIpgintro\fP(l), \fIcommit\fP(l), \fIdelete\fP(l) .TP \fIfetch\fP(l), \fIselect\fP(l), \fIsql\fP(l) , \fIupdate\fP(l) .PD .SH FILES .PD 0 .TP .B /usr/src/pgsql/postgresql-${ver}/src/interfaces... ./ecpg/include.......source for \fIecpg\fP header files. ./ecpg/lib...........source for \fIecpg\fP libraries. ./ecpg/preproc.......source for \fIecpg\fP header files. ./ecpg/test..........source for \fIecpg\fP libraries. (test contains examples of syntax for ecpg SQL-C.) .PD .TP .B /usr/local/pgsql/bin \fIPostgreSQL\fP binaries including \fIecpg\fP. .PD .TP .B /usr/local/pgsql/include \fIPostgreSQL\fP headers including \fIecpglib.h\fP \fIecpgtype.h\fP and \fIsqlca.h\fP. .PD .TP .B /usr/local/pgsql/lib \fIPostgreSQL\fP libraries including \fIlibecpg.a\fP and \fIlibecpg.so\fP. .SH AUTHORS Linus Tolke \fI\fP - original author of ECPG (up to version 0.2). .br .PP Michael Meskes \fI\fP - actual author and maintainer of ECPG. .br .PP Thomas Good \fI\fP - author of this revision of the ecpg man page. .br .zZ