2 doc/src/sgml/ref/ecpg-ref.sgml
3 PostgreSQL documentation
6 <refentry id="APP-ECPG">
7 <indexterm zone="app-ecpg">
8 <primary>ecpg</primary>
12 <refentrytitle><application>ecpg</application></refentrytitle>
13 <manvolnum>1</manvolnum>
14 <refmiscinfo>Application</refmiscinfo>
18 <refname><application>ecpg</application></refname>
19 <refpurpose>embedded SQL C preprocessor</refpurpose>
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>.
46 The extension will be replaced by <filename>.c</filename> to
47 determine the output file name.
48 The output file name can also be overridden using the
49 <option>-o</option> option.
53 This reference page does not describe the embedded SQL language.
54 See <xref linkend="ecpg"> for more information on that topic.
60 <title>Options</title>
63 <command>ecpg</command> accepts the following command-line
68 <term><option>-c</option></term>
71 Automatically generate certain C code from SQL code. Currently, this
72 works for <literal>EXEC SQL TYPE</literal>.
78 <term><option>-C <replaceable>mode</replaceable></option></term>
81 Set a compatibility mode. <replaceable>mode</replaceable> can
82 be <literal>INFORMIX</literal> or
83 <literal>INFORMIX_SE</literal>.
89 <term><option>-D <replaceable>symbol</replaceable></option></term>
92 Define a C preprocessor symbol.
98 <term><option>-i</option></term>
101 Parse system include files as well.
107 <term><option>-I <replaceable class="parameter">directory</replaceable></option></term>
110 Specify an additional include path, used to find files included
111 via <literal>EXEC SQL INCLUDE</literal>. Defaults are
112 <filename>.</filename> (current directory),
113 <filename>/usr/local/include</filename>, the
114 <productname>PostgreSQL</productname> include directory which
115 is defined at compile time (default:
116 <filename>/usr/local/pgsql/include</filename>), and
117 <filename>/usr/include</filename>, in that order.
123 <term><option>-o <replaceable>filename</replaceable></option></term>
126 Specifies that <command>ecpg</command> should write all
127 its output to the given <replaceable>filename</replaceable>.
133 <term><option>-r <replaceable>option</replaceable></option></term>
136 Selects run-time behavior. <replaceable>Option</replaceable> can be
137 one of the following:
140 <term><option>no_indicator</option></term>
143 Do not use indicators but instead use special values to represent
144 null values. Historically there have been databases using this approach.
149 <term><option>prepare</option></term>
152 Prepare all statements before using them. Libecpg will keep a cache of
153 prepared statements and reuse a statement if it gets executed again. If the
154 cache runs full, libecpg will free the least used statement.
159 <term><option>questionmarks</option></term>
162 Allow question mark as placeholder for compatibility reasons.
163 This used to be the default long ago.
167 </variablelist></para>
172 <term><option>-t</option></term>
175 Turn on autocommit of transactions. In this mode, each SQL command is
176 automatically committed unless it is inside an explicit
177 transaction block. In the default mode, commands are committed
178 only when <command>EXEC SQL COMMIT</command> is issued.
184 <term><option>-v</option></term>
187 Print additional information including the version and the
194 <term><option>--version</option></term>
197 Print the <application>ecpg</application> version and exit.
203 <term><option>-?</option></term>
204 <term><option>--help</option></term>
207 Show help about <application>ecpg</application> command line
222 When compiling the preprocessed C code files, the compiler needs to
223 be able to find the <application>ECPG</> header files in the
224 <productname>PostgreSQL</> include directory. Therefore, you might
225 have to use the <option>-I</> option when invoking the compiler
226 (e.g., <literal>-I/usr/local/pgsql/include</literal>).
230 Programs using C code with embedded SQL have to be linked against
231 the <filename>libecpg</filename> library, for example using the
232 linker options <literal>-L/usr/local/pgsql/lib -lecpg</literal>.
236 The value of either of these directories that is appropriate for
237 the installation can be found out using <xref
238 linkend="app-pgconfig">.
244 <title>Examples</title>
247 If you have an embedded SQL C source file named
248 <filename>prog1.pgc</filename>, you can create an executable
249 program using the following sequence of commands:
252 cc -I/usr/local/pgsql/include -c prog1.c
253 cc -o prog1 prog1.o -L/usr/local/pgsql/lib -lecpg
254 </programlisting></para>