]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/ecpg-ref.sgml
Trim trailing whitespace
[postgresql] / doc / src / sgml / ref / ecpg-ref.sgml
1 <!--
2 doc/src/sgml/ref/ecpg-ref.sgml
3 PostgreSQL documentation
4 -->
5
6 <refentry id="APP-ECPG">
7  <indexterm zone="app-ecpg">
8   <primary>ecpg</primary>
9  </indexterm>
10
11  <refmeta>
12   <refentrytitle><application>ecpg</application></refentrytitle>
13   <manvolnum>1</manvolnum>
14   <refmiscinfo>Application</refmiscinfo>
15  </refmeta>
16
17  <refnamediv>
18   <refname><application>ecpg</application></refname>
19   <refpurpose>embedded SQL C preprocessor</refpurpose>
20  </refnamediv>
21
22  <refsynopsisdiv>
23   <cmdsynopsis>
24    <command>ecpg</command>
25    <arg choice="opt" rep="repeat"><replaceable>option</replaceable></arg>
26    <arg choice="plain" rep="repeat"><replaceable>file</replaceable></arg>
27   </cmdsynopsis>
28  </refsynopsisdiv>
29
30
31  <refsect1 id="APP-ECPG-description">
32   <title>Description</title>
33
34   <para>
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
39    compiler tool chain.
40   </para>
41
42   <para>
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.
50   </para>
51
52   <para>
53    This reference page does not describe the embedded SQL language.
54    See <xref linkend="ecpg"> for more information on that topic.
55   </para>
56  </refsect1>
57
58
59  <refsect1>
60   <title>Options</title>
61
62   <para>
63    <command>ecpg</command> accepts the following command-line
64    arguments:
65
66    <variablelist>
67     <varlistentry>
68      <term><option>-c</option></term>
69      <listitem>
70       <para>
71        Automatically generate certain C code from SQL code.  Currently, this
72        works for <literal>EXEC SQL TYPE</literal>.
73       </para>
74      </listitem>
75     </varlistentry>
76
77     <varlistentry>
78      <term><option>-C <replaceable>mode</replaceable></option></term>
79      <listitem>
80       <para>
81        Set a compatibility mode.  <replaceable>mode</replaceable> can
82        be <literal>INFORMIX</literal> or
83        <literal>INFORMIX_SE</literal>.
84       </para>
85      </listitem>
86     </varlistentry>
87
88     <varlistentry>
89      <term><option>-D <replaceable>symbol</replaceable></option></term>
90      <listitem>
91       <para>
92        Define a C preprocessor symbol.
93       </para>
94      </listitem>
95     </varlistentry>
96
97     <varlistentry>
98      <term><option>-i</option></term>
99      <listitem>
100       <para>
101        Parse system include files as well.
102       </para>
103      </listitem>
104     </varlistentry>
105
106     <varlistentry>
107      <term><option>-I <replaceable class="parameter">directory</replaceable></option></term>
108      <listitem>
109       <para>
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.
118       </para>
119      </listitem>
120     </varlistentry>
121
122     <varlistentry>
123      <term><option>-o <replaceable>filename</replaceable></option></term>
124      <listitem>
125       <para>
126        Specifies that <command>ecpg</command> should write all
127        its output to the given <replaceable>filename</replaceable>.
128       </para>
129      </listitem>
130     </varlistentry>
131
132     <varlistentry>
133      <term><option>-r <replaceable>option</replaceable></option></term>
134      <listitem>
135       <para>
136        Selects run-time behavior.  <replaceable>Option</replaceable> can be
137        one of the following:
138        <variablelist>
139         <varlistentry>
140          <term><option>no_indicator</option></term>
141          <listitem>
142          <para>
143          Do not use indicators but instead use special values to represent
144          null values. Historically there have been databases using this approach.
145          </para>
146          </listitem>
147         </varlistentry>
148         <varlistentry>
149          <term><option>prepare</option></term>
150          <listitem>
151          <para>
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.
155          </para>
156          </listitem>
157         </varlistentry>
158         <varlistentry>
159          <term><option>questionmarks</option></term>
160          <listitem>
161          <para>
162          Allow question mark as placeholder for compatibility reasons.
163          This used to be the default long ago.
164          </para>
165          </listitem>
166         </varlistentry>
167        </variablelist></para>
168      </listitem>
169     </varlistentry>
170
171     <varlistentry>
172      <term><option>-t</option></term>
173      <listitem>
174       <para>
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.
179       </para>
180      </listitem>
181     </varlistentry>
182
183     <varlistentry>
184      <term><option>-v</option></term>
185      <listitem>
186       <para>
187        Print additional information including the version and the
188        "include" path.
189       </para>
190      </listitem>
191     </varlistentry>
192
193     <varlistentry>
194      <term><option>--version</option></term>
195      <listitem>
196       <para>
197        Print the <application>ecpg</application> version and exit.
198       </para>
199      </listitem>
200     </varlistentry>
201
202     <varlistentry>
203      <term><option>-?</option></term>
204      <term><option>--help</option></term>
205      <listitem>
206       <para>
207        Show help about <application>ecpg</application> command line
208        arguments, and exit.
209       </para>
210      </listitem>
211     </varlistentry>
212
213    </variablelist>
214   </para>
215  </refsect1>
216
217
218  <refsect1>
219   <title>Notes</title>
220
221   <para>
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>).
227   </para>
228
229   <para>
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>.
233   </para>
234
235   <para>
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">.
239   </para>
240  </refsect1>
241
242
243  <refsect1>
244   <title>Examples</title>
245
246   <para>
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:
250 <programlisting>
251 ecpg prog1.pgc
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>
255  </refsect1>
256
257 </refentry>