summaryrefslogtreecommitdiffstats
path: root/doc/src/sgml/ref/ecpg-ref.sgml
blob: f3b6034f42aef9411fa2cc8669d02dc7cefdaaf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<!--
doc/src/sgml/ref/ecpg-ref.sgml
PostgreSQL documentation
-->

<refentry id="app-ecpg">
 <indexterm zone="app-ecpg">
  <primary>ecpg</primary>
 </indexterm>

 <refmeta>
  <refentrytitle><application>ecpg</application></refentrytitle>
  <manvolnum>1</manvolnum>
  <refmiscinfo>Application</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname><application>ecpg</application></refname>
  <refpurpose>embedded SQL C preprocessor</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
  <cmdsynopsis>
   <command>ecpg</command>
   <arg choice="opt" rep="repeat"><replaceable>option</replaceable></arg>
   <arg choice="plain" rep="repeat"><replaceable>file</replaceable></arg>
  </cmdsynopsis>
 </refsynopsisdiv>


 <refsect1 id="app-ecpg-description">
  <title>Description</title>

  <para>
   <command>ecpg</command> is the embedded SQL preprocessor for C
   programs.  It converts C programs with embedded SQL statements to
   normal C code by replacing the SQL invocations with special
   function calls.  The output files can then be processed with any C
   compiler tool chain.
  </para>

  <para>
   <command>ecpg</command> will convert each input file given on the
   command line to the corresponding C output file.  If an input file
   name does not have any extension, <filename>.pgc</filename> is
   assumed.  The file's extension will be replaced
   by <filename>.c</filename> to construct the output file name.
   But the output file name can be overridden using the
   <option>-o</option> option.
  </para>

  <para>
   If an input file name is just <literal>-</literal>,
   <command>ecpg</command> reads the program from standard input
   (and writes to standard output, unless that is overridden
   with <option>-o</option>).
  </para>

  <para>
   This reference page does not describe the embedded SQL language.
   See <xref linkend="ecpg"/> for more information on that topic.
  </para>
 </refsect1>


 <refsect1>
  <title>Options</title>

  <para>
   <command>ecpg</command> accepts the following command-line
   arguments:

   <variablelist>
    <varlistentry>
     <term><option>-c</option></term>
     <listitem>
      <para>
       Automatically generate certain C code from SQL code.  Currently, this
       works for <literal>EXEC SQL TYPE</literal>.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><option>-C <replaceable>mode</replaceable></option></term>
     <listitem>
      <para>
       Set a compatibility mode.  <replaceable>mode</replaceable> can
       be <literal>INFORMIX</literal>,
       <literal>INFORMIX_SE</literal>, or <literal>ORACLE</literal>.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><option>-D <replaceable>symbol</replaceable></option></term>
     <listitem>
      <para>
       Define a C preprocessor symbol.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><option>-h</option></term>
     <listitem>
      <para>
       Process header files.  When this option is specified, the output file
       extension becomes <literal>.h</literal> not <literal>.c</literal>,
       and the default input file extension is <literal>.pgh</literal>
       not <literal>.pgc</literal>.  Also, the <option>-c</option> option is
       forced on.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><option>-i</option></term>
     <listitem>
      <para>
       Parse system include files as well.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><option>-I <replaceable class="parameter">directory</replaceable></option></term>
     <listitem>
      <para>
       Specify an additional include path, used to find files included
       via <literal>EXEC SQL INCLUDE</literal>.  Defaults are
       <filename>.</filename> (current directory),
       <filename>/usr/local/include</filename>, the
       <productname>PostgreSQL</productname> include directory which
       is defined at compile time (default:
       <filename>/usr/local/pgsql/include</filename>), and
       <filename>/usr/include</filename>, in that order.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><option>-o <replaceable>filename</replaceable></option></term>
     <listitem>
      <para>
       Specifies that <command>ecpg</command> should write all
       its output to the given <replaceable>filename</replaceable>.
       Write <literal>-o -</literal> to send all output to standard output.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><option>-r <replaceable>option</replaceable></option></term>
     <listitem>
      <para>
       Selects run-time behavior.  <replaceable>Option</replaceable> can be
       one of the following:
       <variablelist>
        <varlistentry>
         <term><option>no_indicator</option></term>
         <listitem>
         <para>
         Do not use indicators but instead use special values to represent
         null values. Historically there have been databases using this approach.
         </para>
         </listitem>
        </varlistentry>
        <varlistentry>
         <term><option>prepare</option></term>
         <listitem>
         <para>
         Prepare all statements before using them. Libecpg will keep a cache of
         prepared statements and reuse a statement if it gets executed again. If the
         cache runs full, libecpg will free the least used statement.
         </para>
         </listitem>
        </varlistentry>
        <varlistentry>
         <term><option>questionmarks</option></term>
         <listitem>
         <para>
         Allow question mark as placeholder for compatibility reasons.
         This used to be the default long ago.
         </para>
         </listitem>
        </varlistentry>
       </variablelist></para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><option>-t</option></term>
     <listitem>
      <para>
       Turn on autocommit of transactions. In this mode, each SQL command is
       automatically committed unless it is inside an explicit
       transaction block. In the default mode, commands are committed
       only when <command>EXEC SQL COMMIT</command> is issued.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><option>-v</option></term>
     <listitem>
      <para>
       Print additional information including the version and the
       "include" path.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><option>--version</option></term>
     <listitem>
      <para>
       Print the <application>ecpg</application> version and exit.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><option>-?</option></term>
     <term><option>--help</option></term>
     <listitem>
      <para>
       Show help about <application>ecpg</application> command line
       arguments, and exit.
      </para>
     </listitem>
    </varlistentry>

   </variablelist>
  </para>
 </refsect1>


 <refsect1>
  <title>Notes</title>

  <para>
   When compiling the preprocessed C code files, the compiler needs to
   be able to find the <application>ECPG</application> header files in the
   <productname>PostgreSQL</productname> include directory.  Therefore, you might
   have to use the <option>-I</option> option when invoking the compiler
   (e.g., <literal>-I/usr/local/pgsql/include</literal>).
  </para>

  <para>
   Programs using C code with embedded SQL have to be linked against
   the <filename>libecpg</filename> library, for example using the
   linker options <literal>-L/usr/local/pgsql/lib -lecpg</literal>.
  </para>

  <para>
   The value of either of these directories that is appropriate for
   the installation can be found out using <xref
   linkend="app-pgconfig"/>.
  </para>
 </refsect1>


 <refsect1>
  <title>Examples</title>

  <para>
   If you have an embedded SQL C source file named
   <filename>prog1.pgc</filename>, you can create an executable
   program using the following sequence of commands:
<programlisting>
ecpg prog1.pgc
cc -I/usr/local/pgsql/include -c prog1.c
cc -o prog1 prog1.o -L/usr/local/pgsql/lib -lecpg
</programlisting></para>
 </refsect1>

</refentry>