2 doc/src/sgml/ref/ecpg-ref.sgml
3 PostgreSQL documentation
6 <refentry id="APP-ECPG">
8 <refentrytitle><application>ecpg</application></refentrytitle>
9 <manvolnum>1</manvolnum>
10 <refmiscinfo>Application</refmiscinfo>
14 <refname><application>ecpg</application></refname>
15 <refpurpose>embedded SQL C preprocessor</refpurpose>
18 <indexterm zone="app-ecpg">
19 <primary>ecpg</primary>
24 <command>ecpg</command>
25 <arg choice="opt" rep="repeat"><replaceable>option</replaceable></arg>
26 <arg choice="plain" rep="repeat"><replaceable>file</replaceable></arg>
31 <refsect1 id="APP-ECPG-description">
32 <title>Description</title>
35 <command>ecpg</command> is the embedded SQL preprocessor for C
36 programs. It converts C programs with embedded SQL statements to
37 normal C code by replacing the SQL invocations with special
38 function calls. The output files can then be processed with any C
43 <command>ecpg</command> will convert each input file given on the
44 command line to the corresponding C output file. Input files
45 preferably have the extension <filename>.pgc</filename>, in which
46 case the extension will be replaced by <filename>.c</filename> to
47 determine the output file name. If the extension of the input file
48 is not <filename>.pgc</filename>, then the output file name is
49 computed by appending <literal>.c</literal> to the full file name.
50 The output file name can also be overridden using the
51 <option>-o</option> option.
55 This reference page does not describe the embedded SQL language.
56 See <xref linkend="ecpg"> for more information on that topic.
62 <title>Options</title>
65 <command>ecpg</command> accepts the following command-line
70 <term><option>-c</option></term>
73 Automatically generate certain C code from SQL code. Currently, this
74 works for <literal>EXEC SQL TYPE</literal>.
80 <term><option>-C <replaceable>mode</replaceable></option></term>
83 Set a compatibility mode. <replaceable>mode</replaceable> can
84 be <literal>INFORMIX</literal> or
85 <literal>INFORMIX_SE</literal>.
91 <term><option>-D <replaceable>symbol</replaceable></option></term>
94 Define a C preprocessor symbol.
100 <term><option>-i</option></term>
103 Parse system include files as well.
109 <term><option>-I <replaceable class="parameter">directory</replaceable></option></term>
112 Specify an additional include path, used to find files included
113 via <literal>EXEC SQL INCLUDE</literal>. Defaults are
114 <filename>.</filename> (current directory),
115 <filename>/usr/local/include</filename>, the
116 <productname>PostgreSQL</productname> include directory which
117 is defined at compile time (default:
118 <filename>/usr/local/pgsql/include</filename>), and
119 <filename>/usr/include</filename>, in that order.
125 <term><option>-o <replaceable>filename</replaceable></option></term>
128 Specifies that <command>ecpg</command> should write all
129 its output to the given <replaceable>filename</replaceable>.
135 <term><option>-r <replaceable>option</replaceable></option></term>
138 Selects run-time behavior. <replaceable>Option</replaceable> can be
139 one of the following:
142 <term><option>no_indicator</option></term>
145 Do not use indicators but instead use special values to represent
146 null values. Historically there have been databases using this approach.
151 <term><option>prepare</option></term>
154 Prepare all statements before using them. Libecpg will keep a cache of
155 prepared statements and reuse a statement if it gets executed again. If the
156 cache runs full, libecpg will free the least used statement.
161 <term><option>questionmarks</option></term>
164 Allow question mark as placeholder for compatibility reasons.
165 This used to be the default long ago.
169 </variablelist></para>
174 <term><option>-t</option></term>
177 Turn on autocommit of transactions. In this mode, each SQL command is
178 automatically committed unless it is inside an explicit
179 transaction block. In the default mode, commands are committed
180 only when <command>EXEC SQL COMMIT</command> is issued.
186 <term><option>-v</option></term>
189 Print additional information including the version and the
196 <term><option>--version</option></term>
199 Print the <application>ecpg</application> version and exit.
205 <term><option>--help</option></term>
208 Show help about <application>ecpg</application> command line
223 When compiling the preprocessed C code files, the compiler needs to
224 be able to find the <application>ECPG</> header files in the
225 <productname>PostgreSQL</> include directory. Therefore, you might
226 have to use the <option>-I</> option when invoking the compiler
227 (e.g., <literal>-I/usr/local/pgsql/include</literal>).
231 Programs using C code with embedded SQL have to be linked against
232 the <filename>libecpg</filename> library, for example using the
233 linker options <literal>-L/usr/local/pgsql/lib -lecpg</literal>.
237 The value of either of these directories that is appropriate for
238 the installation can be found out using <xref
239 linkend="app-pgconfig">.
245 <title>Examples</title>
248 If you have an embedded SQL C source file named
249 <filename>prog1.pgc</filename>, you can create an executable
250 program using the following sequence of commands:
253 cc -I/usr/local/pgsql/include -c prog1.c
254 cc -o prog1 prog1.o -L/usr/local/pgsql/lib -lecpg
255 </programlisting></para>