ecpg-ref.sgml 6.4 KB
Newer Older
1
<!--
2
$PostgreSQL: pgsql/doc/src/sgml/ref/ecpg-ref.sgml,v 1.32 2007/01/31 23:26:03 momjian Exp $
3
PostgreSQL documentation
4 5 6 7
-->

<refentry id="APP-ECPG">
 <refmeta>
P
Peter Eisentraut 已提交
8
  <refentrytitle><application>ecpg</application></refentrytitle>
9
  <manvolnum>1</manvolnum>
10 11
  <refmiscinfo>Application</refmiscinfo>
 </refmeta>
12

13
 <refnamediv>
P
Peter Eisentraut 已提交
14 15
  <refname><application>ecpg</application></refname>
  <refpurpose>embedded SQL C preprocessor</refpurpose>
16
 </refnamediv>
17

P
Peter Eisentraut 已提交
18 19 20 21
 <indexterm zone="app-ecpg">
  <primary>ecpg</primary>
 </indexterm>

22
 <refsynopsisdiv>
23 24
  <cmdsynopsis>
   <command>ecpg</command>
P
Peter Eisentraut 已提交
25
   <arg choice="opt" rep="repeat"><replaceable>option</replaceable></arg>
26 27
   <arg choice="plain" rep="repeat"><replaceable>file</replaceable></arg>
  </cmdsynopsis>
28 29
 </refsynopsisdiv>

P
Peter Eisentraut 已提交
30

31 32 33 34
 <refsect1 id="APP-ECPG-description">
  <title>Description</title>

  <para>
P
Peter Eisentraut 已提交
35 36 37 38 39
   <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.
40 41 42
  </para>

  <para>
P
Peter Eisentraut 已提交
43 44
   <command>ecpg</command> will convert each input file given on the
   command line to the corresponding C output file.  Input files
45
   preferably have the extension <filename>.pgc</filename>, in which
P
Peter Eisentraut 已提交
46 47 48 49 50 51
   case the extension will be replaced by <filename>.c</filename> to
   determine the output file name.  If the extension of the input file
   is not <filename>.pgc</filename>, then the output file name is
   computed by appending <literal>.c</literal> to the full file name.
   The output file name can also be overridden using the
   <option>-o</option> option.
52
  </para>
53

P
Peter Eisentraut 已提交
54 55
  <para>
   This reference page does not describe the embedded SQL language.
56
   See <xref linkend="ecpg"> for more information on that topic.
P
Peter Eisentraut 已提交
57
  </para>
58
 </refsect1>
59 60


61
 <refsect1>
P
Peter Eisentraut 已提交
62
  <title>Options</title>
63 64

  <para>
P
Peter Eisentraut 已提交
65 66 67 68 69 70 71 72
   <command>ecpg</command> accepts the following command-line
   arguments:

   <variablelist>
    <varlistentry>
     <term><option>-c</option></term>
     <listitem>
      <para>
73
       Automatically generate certain C code from SQL code.  Currently, this
P
Peter Eisentraut 已提交
74 75 76 77 78
       works for <literal>EXEC SQL TYPE</literal>.
      </para>
     </listitem>
    </varlistentry>

79 80 81 82
    <varlistentry>
     <term><option>-C <replaceable>mode</replaceable></option></term>
     <listitem>
      <para>
83
       Set a compatibility mode.  <replaceable>mode</replaceable> can
84 85 86 87 88 89
       be <literal>INFORMIX</literal> or
       <literal>INFORMIX_SE</literal>.
      </para>
     </listitem>
    </varlistentry>

P
Peter Eisentraut 已提交
90 91 92 93 94 95 96 97 98
    <varlistentry>
     <term><option>-D <replaceable>symbol</replaceable></option></term>
     <listitem>
      <para>
       Define a C preprocessor symbol.
      </para>
     </listitem>
    </varlistentry>

99 100 101 102 103 104 105 106 107
    <varlistentry>
     <term><option>-i</option></term>
     <listitem>
      <para>
       Parse system include files as well.
      </para>
     </listitem>
    </varlistentry>

P
Peter Eisentraut 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
    <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>
128
       Specifies that <command>ecpg</command> should write all
P
Peter Eisentraut 已提交
129 130 131 132 133
       its output to the given <replaceable>filename</replaceable>.
      </para>
     </listitem>
    </varlistentry>

134 135 136 137 138 139 140 141 142 143 144
    <varlistentry>
     <term><option>-r <replaceable>option</replaceable></option></term>
     <listitem>
      <para>
       Selects a run-time behavior.  Currently,
       <replaceable>option</replaceable> can only be
       <literal>no_indicator</literal>.
      </para>
     </listitem>
    </varlistentry>

P
Peter Eisentraut 已提交
145 146 147 148
    <varlistentry>
     <term><option>-t</option></term>
     <listitem>
      <para>
149
       Turn on autocommit of transactions. In this mode, each SQL command is
P
Peter Eisentraut 已提交
150
       automatically committed unless it is inside an explicit
151
       transaction block. In the default mode, commands are committed
P
Peter Eisentraut 已提交
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
       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>
168
     <term><option>--help</option></term>
P
Peter Eisentraut 已提交
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
     <listitem>
      <para>
       Show a brief summary of the command usage, then exit.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><option>--version</option></term>
     <listitem>
      <para>
       Output version information, then exit.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
185 186 187
  </para>
 </refsect1>

188 189

 <refsect1>
P
Peter Eisentraut 已提交
190
  <title>Notes</title>
191

P
Peter Eisentraut 已提交
192 193 194
  <para>
   When compiling the preprocessed C code files, the compiler needs to
   be able to find the <application>ECPG</> header files in the
B
Bruce Momjian 已提交
195 196 197
   <productname>PostgreSQL</> include directory.  Therefore, one might
   have to use the <option>-I</> option when invoking the compiler
   (e.g., <literal>-I/usr/local/pgsql/include</literal>).
P
Peter Eisentraut 已提交
198
  </para>
199

P
Peter Eisentraut 已提交
200 201 202
  <para>
   Programs using C code with embedded SQL have to be linked against
   the <filename>libecpg</filename> library, for example using the
203
   linker options <literal>-L/usr/local/pgsql/lib -lecpg</literal>.
P
Peter Eisentraut 已提交
204
  </para>
205

P
Peter Eisentraut 已提交
206 207 208 209 210
  <para>
   The value of either of these directories that is appropriate for
   the installation can be found out using <xref
   linkend="app-pgconfig">.
  </para>
211 212 213
 </refsect1>


P
Peter Eisentraut 已提交
214 215
 <refsect1>
  <title>Examples</title>
216

P
Peter Eisentraut 已提交
217 218 219 220
  <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:
P
Peter Eisentraut 已提交
221
<programlisting>
P
Peter Eisentraut 已提交
222 223 224
ecpg prog1.pgc
cc -I/usr/local/pgsql/include -c prog1.c
cc -o prog1 prog1.o -L/usr/local/pgsql/lib -lecpg
P
Peter Eisentraut 已提交
225
</programlisting>
226
  </para>
227
 </refsect1>
228

229
</refentry>