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