2000-03-31 11:27:42 +08:00
|
|
|
<!--
|
2002-01-19 05:17:07 +08:00
|
|
|
$Header: /cvsroot/pgsql/doc/src/sgml/ecpg.sgml,v 1.35 2002/01/18 21:17:07 momjian Exp $
|
2000-03-31 11:27:42 +08:00
|
|
|
-->
|
|
|
|
|
2000-09-30 04:21:34 +08:00
|
|
|
<chapter id="ecpg">
|
2000-03-31 06:22:41 +08:00
|
|
|
<docinfo>
|
|
|
|
<authorgroup>
|
|
|
|
<author>
|
|
|
|
<firstname>Linus</firstname>
|
|
|
|
<surname>Tolke</surname>
|
|
|
|
</author>
|
|
|
|
<author>
|
|
|
|
<firstname>Michael</firstname>
|
|
|
|
<surname>Meskes</surname>
|
|
|
|
</author>
|
|
|
|
</authorgroup>
|
|
|
|
<copyright>
|
|
|
|
<year>1996-1997</year>
|
|
|
|
<holder>Linus Tolke</holder>
|
|
|
|
</copyright>
|
|
|
|
<copyright>
|
|
|
|
<year>1998</year>
|
|
|
|
<holder>Michael Meskes</holder>
|
|
|
|
</copyright>
|
|
|
|
<date>Transcribed 1998-02-12</date>
|
|
|
|
</docinfo>
|
|
|
|
|
|
|
|
<title><application>ecpg</application> - Embedded <acronym>SQL</acronym>
|
|
|
|
in <acronym>C</acronym></title>
|
|
|
|
|
2001-11-13 03:19:39 +08:00
|
|
|
<indexterm zone="ecpg"><primary>embedded SQL</primary><secondary>in C</secondary></indexterm>
|
|
|
|
|
2000-03-31 06:22:41 +08:00
|
|
|
<para>
|
2001-09-06 08:23:42 +08:00
|
|
|
This describes the embedded <acronym>SQL</acronym> package for
|
2001-11-21 13:53:41 +08:00
|
|
|
<productname>PostgreSQL</productname>. It works with
|
2001-09-06 08:23:42 +08:00
|
|
|
<acronym>C</acronym> and <acronym>C++</acronym>. It was written by
|
|
|
|
Linus Tolke (<email>linus@epact.se</email>) and Michael Meskes
|
|
|
|
(<email>meskes@debian.org</email>). The package is installed with the
|
2001-11-21 13:53:41 +08:00
|
|
|
<productname>PostgreSQL</> distribution, and carries a similar license.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
2000-05-03 04:02:03 +08:00
|
|
|
|
2000-09-30 04:21:34 +08:00
|
|
|
<sect1 id="ecpg-why">
|
2000-03-31 06:22:41 +08:00
|
|
|
<title>Why Embedded <acronym>SQL</acronym>?</title>
|
|
|
|
|
|
|
|
<para>
|
2001-09-06 08:23:42 +08:00
|
|
|
Embedded <acronym>SQL</acronym> has advantages over other methods
|
|
|
|
for handling <acronym>SQL</acronym> queries. It takes care of
|
|
|
|
the tedious passing of information to and from variables in your
|
|
|
|
<acronym>C</acronym> or <acronym>C++</acronym> program. Many
|
|
|
|
<acronym>RDBMS</acronym> packages support this embedded language.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
|
2001-09-06 08:23:42 +08:00
|
|
|
<para>
|
|
|
|
There is an ANSI standard describing how the embedded language
|
|
|
|
should work. <application>ecpg</application> was designed to match
|
|
|
|
this standard as much as possible. It is possible to port embedded
|
|
|
|
<acronym>SQL</acronym> programs written for other
|
2001-11-21 13:53:41 +08:00
|
|
|
<acronym>RDBMS</acronym> to <productname>PostgreSQL</productname>.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
</sect1>
|
|
|
|
|
2000-09-30 04:21:34 +08:00
|
|
|
<sect1 id="ecpg-concept">
|
2000-03-31 06:22:41 +08:00
|
|
|
<title>The Concept</title>
|
|
|
|
|
|
|
|
<para>
|
2001-09-06 08:23:42 +08:00
|
|
|
You write your program in <acronym>C/C++</acronym> with special
|
|
|
|
<acronym>SQL</acronym> constructs. When declaring variables to be
|
|
|
|
used in <acronym>SQL</acronym> statements, you need to put them in a
|
|
|
|
special <command>declare</> section. You use a special syntax for the
|
|
|
|
<acronym>SQL</acronym> queries.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-09-06 08:23:42 +08:00
|
|
|
Before compiling you run the file through the embedded
|
|
|
|
<acronym>SQL</acronym> <acronym>C</acronym> preprocessor and it
|
|
|
|
converts the <acronym>SQL</acronym> statements you used to function
|
|
|
|
calls with the variables used as arguments. Both query input and
|
|
|
|
result output variables are passed.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-09-06 08:23:42 +08:00
|
|
|
After compiling, you must link with a special library that contains
|
|
|
|
needed functions. These functions fetch information from the
|
|
|
|
arguments, perform the <acronym>SQL</acronym> query using the
|
|
|
|
<filename>libpq</filename> interface, and put the result in the
|
|
|
|
arguments specified for output.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
</sect1>
|
|
|
|
|
2000-09-30 04:21:34 +08:00
|
|
|
<sect1 id="ecpg-use">
|
2000-03-31 06:22:41 +08:00
|
|
|
<title>How To Use <application>ecpg</application></title>
|
|
|
|
|
|
|
|
<para>
|
2001-09-06 08:23:42 +08:00
|
|
|
This section describes how to use <application>ecpg</application>.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
<title>Preprocessor</title>
|
|
|
|
|
|
|
|
<para>
|
2001-09-06 08:23:42 +08:00
|
|
|
The preprocessor is called <application>ecpg</application>. After
|
2001-11-21 13:53:41 +08:00
|
|
|
installation it resides in the <productname>PostgreSQL</productname>
|
2001-09-06 08:23:42 +08:00
|
|
|
<filename>bin/</filename> directory.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
<sect2>
|
|
|
|
<title>Library</title>
|
|
|
|
|
|
|
|
<para>
|
2001-09-06 08:23:42 +08:00
|
|
|
The <application>ecpg</application> library is called
|
|
|
|
<filename>libecpg.a</filename> or <filename>libecpg.so</filename>.
|
|
|
|
Additionally, the library uses the <filename>libpq</filename>
|
|
|
|
library for communication to the
|
2001-11-21 13:53:41 +08:00
|
|
|
<productname>PostgreSQL</productname> server. You will have to link
|
2001-09-06 08:23:42 +08:00
|
|
|
your program using <parameter>-lecpg -lpq</parameter>.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-09-13 23:55:24 +08:00
|
|
|
The library has some methods that are <quote>hidden</quote> but may prove
|
2001-09-06 08:23:42 +08:00
|
|
|
useful.
|
2000-03-31 06:22:41 +08:00
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2001-11-01 04:37:39 +08:00
|
|
|
<function>ECPGdebug(int <replaceable>on</replaceable>, FILE
|
|
|
|
*<replaceable>stream</replaceable>)</function> turns on debug
|
|
|
|
logging if called with the first argument non-zero. Debug
|
|
|
|
logging is done on <replaceable>stream</replaceable>. Most
|
|
|
|
<acronym>SQL</acronym> statement log their arguments and results.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-11-01 04:37:39 +08:00
|
|
|
The most important function , <function>ECPGdo</function>, logs
|
|
|
|
all <acronym>SQL</acronym> statements with both the expanded
|
|
|
|
string, i.e. the string with all the input variables inserted,
|
2001-11-21 13:53:41 +08:00
|
|
|
and the result from the <productname>PostgreSQL</productname>
|
2001-11-01 04:37:39 +08:00
|
|
|
server. This can be very useful when searching for errors in
|
|
|
|
your <acronym>SQL</acronym> statements.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2001-11-01 04:37:39 +08:00
|
|
|
<function>ECPGstatus()</function>
|
|
|
|
This method returns TRUE if we are connected to a database and FALSE if not.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
<title>Error handling</title>
|
|
|
|
|
|
|
|
<para>
|
2001-11-21 13:53:41 +08:00
|
|
|
To detect errors from the <productname>PostgreSQL</productname>
|
2001-09-06 08:23:42 +08:00
|
|
|
server, include a line like:
|
2001-09-11 05:58:47 +08:00
|
|
|
<programlisting>
|
2001-09-06 08:23:42 +08:00
|
|
|
exec sql include sqlca;
|
2001-09-11 05:58:47 +08:00
|
|
|
</programlisting>
|
2001-09-06 08:23:42 +08:00
|
|
|
in the include section of your file. This will define a struct and
|
|
|
|
a variable with the name <parameter>sqlca</parameter> as follows:
|
2001-09-11 05:58:47 +08:00
|
|
|
<programlisting>
|
1999-03-24 22:54:10 +08:00
|
|
|
struct sqlca
|
|
|
|
{
|
|
|
|
char sqlcaid[8];
|
|
|
|
long sqlabc;
|
|
|
|
long sqlcode;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
int sqlerrml;
|
|
|
|
char sqlerrmc[70];
|
|
|
|
} sqlerrm;
|
|
|
|
char sqlerrp[8];
|
|
|
|
long sqlerrd[6];
|
|
|
|
/* 0: empty */
|
1999-09-15 22:14:10 +08:00
|
|
|
/* 1: OID of processed tuple if applicable */
|
1999-03-24 22:54:10 +08:00
|
|
|
/* 2: number of rows processed in an INSERT, UPDATE */
|
|
|
|
/* or DELETE statement */
|
|
|
|
/* 3: empty */
|
|
|
|
/* 4: empty */
|
|
|
|
/* 5: empty */
|
|
|
|
char sqlwarn[8];
|
|
|
|
/* 0: set to 'W' if at least one other is 'W' */
|
2001-11-01 04:37:39 +08:00
|
|
|
/* 1: if 'W' at least one character string */
|
1999-03-24 22:54:10 +08:00
|
|
|
/* value was truncated when it was */
|
|
|
|
/* stored into a host variable. */
|
|
|
|
/* 2: empty */
|
|
|
|
/* 3: empty */
|
|
|
|
/* 4: empty */
|
|
|
|
/* 5: empty */
|
|
|
|
/* 6: empty */
|
|
|
|
/* 7: empty */
|
|
|
|
char sqlext[8];
|
1998-03-01 16:16:16 +08:00
|
|
|
} sqlca;
|
2001-09-11 05:58:47 +08:00
|
|
|
</programlisting>
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-10-19 04:32:58 +08:00
|
|
|
If an no error occurred in the last <acronym>SQL</acronym> statement.
|
|
|
|
<parameter>sqlca.sqlcode</parameter> will be 0 (ECPG_NO_ERROR). If
|
|
|
|
<parameter>sqlca.sqlcode</parameter> is less that zero, this is a
|
2001-09-06 08:23:42 +08:00
|
|
|
serious error, like the database definition does not match the
|
2001-10-19 04:32:58 +08:00
|
|
|
query. If it is greater than zero, it is a normal error like the
|
2001-09-06 08:23:42 +08:00
|
|
|
table did not contain the requested row.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-09-06 08:23:42 +08:00
|
|
|
<parameter>sqlca.sqlerrm.sqlerrmc</parameter> will contain a string
|
|
|
|
that describes the error. The string ends with the line number in
|
|
|
|
the source file.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-10-19 04:32:58 +08:00
|
|
|
These are the errors that can occur:
|
2000-03-31 06:22:41 +08:00
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
2001-09-11 05:58:47 +08:00
|
|
|
<term><computeroutput>-12, Out of memory in line %d.</computeroutput></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
Should not normally occur. This indicates your virtual memory is
|
|
|
|
exhausted.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-200 (ECPG_UNSUPPORTED): Unsupported type %s on line %d.</computeroutput></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
Should not normally occur. This indicates the preprocessor has
|
|
|
|
generated something that the library does not know about.
|
|
|
|
Perhaps you are running incompatible versions of the
|
|
|
|
preprocessor and the library.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-201 (ECPG_TOO_MANY_ARGUMENTS): Too many arguments line %d.</computeroutput></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
2001-11-21 13:53:41 +08:00
|
|
|
This means that <productname>PostgreSQL</productname> has
|
2001-11-01 04:37:39 +08:00
|
|
|
returned more arguments than we have matching variables.
|
|
|
|
Perhaps you have forgotten a couple of the host variables in
|
|
|
|
the <command>INTO :var1,:var2</command>-list.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-202 (ECPG_TOO_FEW_ARGUMENTS): Too few arguments line %d.</computeroutput></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
2001-11-21 13:53:41 +08:00
|
|
|
This means that <productname>PostgreSQL</productname> has
|
2001-11-01 04:37:39 +08:00
|
|
|
returned fewer arguments than we have host variables. Perhaps
|
|
|
|
you have too many host variables in the <command>INTO
|
|
|
|
:var1,:var2</command>-list.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-203 (ECPG_TOO_MANY_MATCHES): Too many matches line %d.</computeroutput></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
This means the query has returned several rows but the
|
|
|
|
variables specified are not arrays. The
|
|
|
|
<command>SELECT</command> command was not unique.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-204 (ECPG_INT_FORMAT): Not correctly formatted int type: %s line %d.</computeroutput></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
This means the host variable is of type <type>int</type> and
|
2001-11-21 13:53:41 +08:00
|
|
|
the field in the <productname>PostgreSQL</productname> database
|
2001-11-01 04:37:39 +08:00
|
|
|
is of another type and contains a value that cannot be
|
|
|
|
interpreted as an <type>int</type>. The library uses
|
|
|
|
<function>strtol()</function> for this conversion.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-205 (ECPG_UINT_FORMAT): Not correctly formatted unsigned type: %s line %d.</computeroutput></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
This means the host variable is of type <type>unsigned
|
|
|
|
int</type> and the field in the
|
2001-11-21 13:53:41 +08:00
|
|
|
<productname>PostgreSQL</productname> database is of another type
|
2001-11-01 04:37:39 +08:00
|
|
|
and contains a value that cannot be interpreted as an
|
|
|
|
<type>unsigned int</type>. The library uses
|
|
|
|
<function>strtoul()</function> for this conversion.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2002-01-07 10:29:15 +08:00
|
|
|
<term><computeroutput>-206 (ECPG_FLOAT_FORMAT): Not correctly formatted floating-point type: %s line %d.</computeroutput></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
This means the host variable is of type <type>float</type> and
|
2001-11-21 13:53:41 +08:00
|
|
|
the field in the <productname>PostgreSQL</productname> database
|
2001-11-01 04:37:39 +08:00
|
|
|
is of another type and contains a value that cannot be
|
|
|
|
interpreted as a <type>float</type>. The library uses
|
|
|
|
<function>strtod()</function> for this conversion.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-207 (ECPG_CONVERT_BOOL): Unable to convert %s to bool on line %d.</computeroutput></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
This means the host variable is of type <type>bool</type> and
|
2001-11-21 13:53:41 +08:00
|
|
|
the field in the <productname>PostgreSQL</productname> database
|
2001-11-01 04:37:39 +08:00
|
|
|
is neither <literal>'t'</> nor <literal>'f'</>.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-208 (ECPG_EMPTY): Empty query line %d.</computeroutput></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
2001-11-21 13:53:41 +08:00
|
|
|
<productname>PostgreSQL</productname> returned <symbol>PGRES_EMPTY_QUERY</symbol>, probably
|
2001-11-01 04:37:39 +08:00
|
|
|
because the query indeed was empty.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2001-10-12 04:25:42 +08:00
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-209 (ECPG_MISSING_INDICATOR): NULL value without indicator in line %d.</computeroutput></term>
|
2001-10-12 04:25:42 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
2001-11-21 13:53:41 +08:00
|
|
|
<productname>PostgreSQL</productname> returned <symbol>ECPG_MISSING_INDICATOR</symbol>
|
2001-11-01 04:37:39 +08:00
|
|
|
because a NULL was returned and no NULL indicator variable was supplied.
|
|
|
|
</para>
|
2001-10-12 04:25:42 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2000-03-31 06:22:41 +08:00
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-210 (ECPG_NO_ARRAY): Variable is not an array in line %d.</computeroutput></term>
|
2001-10-19 04:32:58 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
2001-11-21 13:53:41 +08:00
|
|
|
<productname>PostgreSQL</productname> returned <symbol>ECPG_NO_ARRAY</symbol>
|
2001-11-01 04:37:39 +08:00
|
|
|
because an ordinary variable was used in a place that requires
|
|
|
|
an array.
|
|
|
|
</para>
|
2001-10-19 04:32:58 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-211 (ECPG_DATA_NOT_ARRAY): Data read from backend is not an array in line %d.</computeroutput></term>
|
2001-10-19 04:32:58 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
2001-11-21 13:53:41 +08:00
|
|
|
<productname>PostgreSQL</productname> returned <symbol>ECPG_DATA_NOT_ARRAY</symbol>
|
2001-11-01 04:37:39 +08:00
|
|
|
because the database returned an ordinary variable in a place
|
|
|
|
that requires array value.
|
|
|
|
</para>
|
2001-10-19 04:32:58 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-220 (ECPG_NO_CONN): No such connection %s in line %d.</computeroutput></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
The program tried to access a connection that does not exist.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-221 (ECPG_NOT_CONN): Not connected in line %d.</computeroutput></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
The program tried to access a connection that does exist but is
|
|
|
|
not open.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-230 (ECPG_INVALID_STMT): Invalid statement name %s in line %d.</computeroutput></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
The statement you are trying to use has not been prepared.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-240 (ECPG_UNKNOWN_DESCRIPTOR): Descriptor %s not found in line %d.</computeroutput></term>
|
2001-10-19 04:32:58 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
The descriptor specified was not foundstatement you are trying to use has not been prepared.
|
|
|
|
</para>
|
2001-10-19 04:32:58 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-241 (ECPG_INVALID_DESCRIPTOR_INDEX): Descriptor index out of range in line %d.</computeroutput></term>
|
2001-10-19 04:32:58 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
The descriptor index specified was out of range.
|
|
|
|
</para>
|
2001-10-19 04:32:58 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-242 (ECPG_UNKNOWN_DESCRIPTOR_ITEM): Descriptor %s not found in line %d.</computeroutput></term>
|
2001-10-19 04:32:58 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
The descriptor specified was not foundstatement you are trying to use has not been prepared.
|
|
|
|
</para>
|
2001-10-19 04:32:58 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-243 (ECPG_VAR_NOT_NUMERIC): Variable is not a numeric type in line %d.</computeroutput></term>
|
2001-10-19 04:32:58 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
The database returned a numeric value and the variable was not
|
|
|
|
numeric.
|
|
|
|
</para>
|
2001-10-19 04:32:58 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-244 (ECPG_VAR_NOT_CHAR): Variable is not a character type in line %d.</computeroutput></term>
|
2001-10-19 04:32:58 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
The database returned a non-numeric value and the variable was
|
|
|
|
numeric.
|
|
|
|
</para>
|
2001-10-19 04:32:58 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-400 (ECPG_PGSQL): Postgres error: %s line %d.</computeroutput></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
2001-11-21 13:53:41 +08:00
|
|
|
Some <productname>PostgreSQL</productname> error.
|
2001-11-01 04:37:39 +08:00
|
|
|
The message contains the error message from the
|
2001-11-21 13:53:41 +08:00
|
|
|
<productname>PostgreSQL</productname> backend.
|
2001-11-01 04:37:39 +08:00
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-401 (ECPG_TRANS): Error in transaction processing line %d.</computeroutput></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
2001-11-21 13:53:41 +08:00
|
|
|
<productname>PostgreSQL</productname> signaled that we cannot start,
|
2001-11-01 04:37:39 +08:00
|
|
|
commit or rollback the transaction.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>-402 (ECPG_CONNECT): Could not connect to database %s in line %d.</computeroutput></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
The connect to the database did not work.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-10-19 04:43:05 +08:00
|
|
|
<term><computeroutput>100 (ECPG_NOT_FOUND): Data not found line %d.</computeroutput></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
This is a <quote>normal</quote> error that tells you that what you are querying cannot
|
|
|
|
be found or you are at the end of the cursor.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
</sect1>
|
|
|
|
|
2000-09-30 04:21:34 +08:00
|
|
|
<sect1 id="ecpg-limitations">
|
2000-03-31 06:22:41 +08:00
|
|
|
<title>Limitations</title>
|
|
|
|
|
|
|
|
<para>
|
2001-11-01 04:37:39 +08:00
|
|
|
What will never be included and why it cannot be done:
|
|
|
|
|
2000-03-31 06:22:41 +08:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
2001-09-06 08:23:42 +08:00
|
|
|
<term>Oracle's single tasking</term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2001-11-01 04:37:39 +08:00
|
|
|
Oracle version 7.0 on <systemitem class="osname">AIX</> 3 uses OS-supported locks in shared
|
|
|
|
memory that allow an application designer to link an application
|
|
|
|
in a <quote>single tasking</quote> way. Instead of starting one client
|
|
|
|
process per application process, both the database part and the
|
|
|
|
application part run in the same process. In later versions of
|
|
|
|
Oracle this is no longer supported.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-11-01 04:37:39 +08:00
|
|
|
This would require a total redesign of the
|
2001-11-21 13:53:41 +08:00
|
|
|
<productname>PostgreSQL</productname> access model and the
|
2001-11-01 04:37:39 +08:00
|
|
|
performance gain does not justify the effort.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
</sect1>
|
|
|
|
|
2000-09-30 04:21:34 +08:00
|
|
|
<sect1 id="ecpg-porting">
|
2000-03-31 06:22:41 +08:00
|
|
|
<title>Porting From Other <acronym>RDBMS</acronym> Packages</title>
|
|
|
|
|
|
|
|
<para>
|
2001-09-06 08:23:42 +08:00
|
|
|
The design of <application>ecpg</application> follows the SQL
|
|
|
|
standard. Porting from a standard RDBMS should not be a problem.
|
|
|
|
Unfortunately there is no such thing as a standard RDBMS. Therefore
|
|
|
|
<application>ecpg</application> tries to understand syntax
|
|
|
|
extensions as long as they do not create conflicts with the
|
|
|
|
standard.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-09-06 08:23:42 +08:00
|
|
|
The following list shows all the known incompatibilities. If you
|
2001-11-09 07:37:50 +08:00
|
|
|
find one not listed please notify the developers. Note, however, that
|
2001-09-06 08:23:42 +08:00
|
|
|
we list only incompatibilities from a precompiler of another RDBMS
|
|
|
|
to <application>ecpg</application> and not
|
|
|
|
<application>ecpg</application> features that these RDBMS do not
|
|
|
|
support.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
2001-09-06 08:23:42 +08:00
|
|
|
<term>Syntax of FETCH</term>
|
2001-11-13 03:19:39 +08:00
|
|
|
<indexterm><primary>FETCH</><secondary>embedded SQL</></indexterm>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2001-11-01 04:37:39 +08:00
|
|
|
The standard syntax for FETCH is:
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
<para>
|
2001-11-01 04:37:39 +08:00
|
|
|
FETCH [direction] [amount] IN|FROM <replaceable>cursor</replaceable>.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
<para>
|
2001-11-13 03:19:39 +08:00
|
|
|
<indexterm><primary>Oracle</></>
|
|
|
|
<application>Oracle</application>, however, does not use the keywords IN
|
2001-11-01 04:37:39 +08:00
|
|
|
or FROM. This feature cannot be added since it would create parsing
|
|
|
|
conflicts.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
</sect1>
|
|
|
|
|
2000-09-30 04:21:34 +08:00
|
|
|
<sect1 id="ecpg-develop">
|
2000-03-31 06:22:41 +08:00
|
|
|
<title>For the Developer</title>
|
|
|
|
|
|
|
|
<para>
|
2001-09-06 08:23:42 +08:00
|
|
|
This section explain how <application>ecpg</application>
|
|
|
|
works internally. It contains valuable information to help users
|
|
|
|
understand how to use <application>ecpg</application>.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
<title>The Preprocessor</title>
|
|
|
|
|
|
|
|
<para>
|
2001-09-11 05:58:47 +08:00
|
|
|
The first four lines written by <command>ecpg</command> to the output are fixed lines.
|
2001-09-06 08:23:42 +08:00
|
|
|
Two are comments and two are include lines necessary to interface
|
|
|
|
to the library.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-09-06 08:23:42 +08:00
|
|
|
Then the preprocessor reads through the file and writes output.
|
|
|
|
Normally it just echoes everything to the output.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-09-06 08:23:42 +08:00
|
|
|
When it sees an <command>EXEC SQL</command> statement, it
|
|
|
|
intervenes and changes it. The <command>EXEC SQL</command>
|
|
|
|
statement can be one of these:
|
2000-03-31 06:22:41 +08:00
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>Declare sections</term>
|
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
<command>Declare</> sections begin with:
|
|
|
|
<programlisting>
|
1998-03-01 16:16:16 +08:00
|
|
|
exec sql begin declare section;
|
2001-11-01 04:37:39 +08:00
|
|
|
</programlisting>
|
|
|
|
and end with:
|
|
|
|
<programlisting>
|
1998-03-01 16:16:16 +08:00
|
|
|
exec sql end declare section;
|
2001-11-01 04:37:39 +08:00
|
|
|
</programlisting>
|
|
|
|
In this section only variable declarations are allowed. Every
|
|
|
|
variable declared within this section is stored in a list
|
|
|
|
of variables indexed by name together with its corresponding
|
|
|
|
type.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
In particular the definition of a structure or union also must
|
|
|
|
be listed inside a <command>declare</> section. Otherwise
|
|
|
|
<application>ecpg</application> cannot handle these types since
|
|
|
|
it does not know the definition.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The declaration is also echoed to the file to make it a normal
|
|
|
|
C variable.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The special types <type>VARCHAR</type> and <type>VARCHAR2</type> are converted into a named struct
|
|
|
|
for every variable. A declaration like:
|
|
|
|
<programlisting>
|
1998-03-01 16:16:16 +08:00
|
|
|
VARCHAR var[180];
|
2001-11-01 04:37:39 +08:00
|
|
|
</programlisting>
|
|
|
|
is converted into:
|
|
|
|
<programlisting>
|
1998-03-01 16:16:16 +08:00
|
|
|
struct varchar_var { int len; char arr[180]; } var;
|
2001-11-01 04:37:39 +08:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term>Include statements</term>
|
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
An include statement looks like:
|
|
|
|
<programlisting>
|
1998-03-01 16:16:16 +08:00
|
|
|
exec sql include filename;
|
2001-11-01 04:37:39 +08:00
|
|
|
</programlisting>
|
|
|
|
Note that this is NOT the same as:
|
|
|
|
<programlisting>
|
1998-03-01 16:16:16 +08:00
|
|
|
#include <filename.h>
|
2001-11-01 04:37:39 +08:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Instead the file specified is parsed by
|
|
|
|
<application>ecpg</application> so the contents of the file are
|
|
|
|
included in the resulting C code. This way you are able to
|
|
|
|
specify EXEC SQL commands in an include file.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term>Connect statement</term>
|
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
A connect statement looks like:
|
|
|
|
<programlisting>
|
2000-03-31 06:22:41 +08:00
|
|
|
exec sql connect to <replaceable>connection target</replaceable>;
|
2001-11-01 04:37:39 +08:00
|
|
|
</programlisting>
|
|
|
|
It creates a connection to the specified database.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The <replaceable>connection target</replaceable> can be specified in the
|
|
|
|
following ways:
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
<literal>dbname[@server][:port][as <replaceable>connection
|
|
|
|
name</replaceable>][user <replaceable>user name</replaceable>]</literal>
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
<literal>tcp:postgresql://server[:port][/dbname][as
|
|
|
|
<replaceable>connection name</replaceable>][user <replaceable>user name</replaceable>]</literal>
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
<literal>unix:postgresql://server[:port][/dbname][as
|
|
|
|
<replaceable>connection name</replaceable>][user <replaceable>user name</replaceable>]</literal>
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
<literal><replaceable>character variable</replaceable>[as
|
|
|
|
<replaceable>connection name</replaceable>][user <replaceable>user name</replaceable>]</literal>
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
<literal><replaceable>character string</replaceable>[as
|
|
|
|
<replaceable>connection name</replaceable>][<replaceable>user</replaceable>]</literal>
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
<literal>default</literal>
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
<literal>user</literal>
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
There are also different ways to specify the user name:
|
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
<literal><replaceable>userid</replaceable></literal>
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
<literal><replaceable>userid</replaceable>/<replaceable>password</replaceable></literal>
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
<literal><replaceable>userid</replaceable> identified by <replaceable>password</replaceable></literal>
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
<literal><replaceable>userid</replaceable> using <replaceable>password</replaceable></literal>
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Finally, the <replaceable>userid</replaceable> and <replaceable>password</replaceable> may be a constant text, a
|
|
|
|
character variable, or a character string.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term>Disconnect statements</term>
|
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
A disconnect statement looks like:
|
|
|
|
<programlisting>
|
2000-03-31 06:22:41 +08:00
|
|
|
exec sql disconnect [<replaceable>connection target</replaceable>];
|
2001-11-01 04:37:39 +08:00
|
|
|
</programlisting>
|
|
|
|
It closes the connection to the specified database.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The <replaceable>connection target</replaceable> can be specified in the
|
|
|
|
following ways:
|
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
<literal><replaceable>connection name</replaceable></literal>
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
<literal>default</literal>
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
<literal>current</literal>
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
2001-11-01 12:48:00 +08:00
|
|
|
<literal>all</literal>
|
2001-11-01 04:37:39 +08:00
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2001-08-27 01:04:02 +08:00
|
|
|
<varlistentry>
|
|
|
|
<term>Open cursor statement</term>
|
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
An open cursor statement looks like:
|
|
|
|
<programlisting>
|
2001-08-27 01:04:02 +08:00
|
|
|
exec sql open <replaceable>cursor</replaceable>;
|
2001-11-01 04:37:39 +08:00
|
|
|
</programlisting>
|
|
|
|
and is not copied to the output. Instead, the cursor's
|
|
|
|
<command>DECLARE</> command is used because it opens the cursor
|
|
|
|
as well.
|
|
|
|
</para>
|
2001-08-27 01:04:02 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term>Commit statement</term>
|
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
A commit statement looks like:
|
|
|
|
<programlisting>
|
2001-08-27 01:04:02 +08:00
|
|
|
exec sql commit;
|
2001-11-01 04:37:39 +08:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
2001-08-27 01:04:02 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term>Rollback statement</term>
|
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
A rollback statement looks like:
|
|
|
|
<programlisting>
|
2001-08-27 01:04:02 +08:00
|
|
|
exec sql rollback;
|
2001-11-01 04:37:39 +08:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
2001-08-27 01:04:02 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2000-03-31 06:22:41 +08:00
|
|
|
<varlistentry>
|
|
|
|
<term>Other statements</term>
|
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
Other <acronym>SQL</acronym> statements are used by
|
|
|
|
starting with <command>exec sql</command> and ending with
|
|
|
|
<command>;</command>. Everything in between is treated as an
|
|
|
|
<acronym>SQL</acronym> statement and parsed for variable
|
|
|
|
substitution.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Variable substitution occurs when a symbol starts with a colon
|
|
|
|
(<command>:</command>). The variable with that name is looked
|
|
|
|
up among the variables that were previously declared within a
|
|
|
|
<command>declare</> section. Depending on whether the variable is
|
|
|
|
being use for input or output, a pointer to the variable is
|
|
|
|
output to allow access by the function.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
For every variable that is part of the <acronym>SQL</acronym>
|
|
|
|
query, the function gets other arguments:
|
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The type as a special symbol.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
A pointer to the value or a pointer to the pointer.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The size of the variable if it is a <type>char</type> or <type>varchar</type>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The number of elements in the array (for array fetches).
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The offset to the next element in the array (for array fetches).
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The type of the indicator variable as a special symbol.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
A pointer to the value of the indicator variable or a pointer to the pointer of the indicator variable.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
0.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Number of elements in the indicator array (for array fetches).
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The offset to the next element in the indicator array (for
|
|
|
|
array fetches).
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
<title>A Complete Example</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Here is a complete example describing the output of the preprocessor of a
|
2001-09-11 05:58:47 +08:00
|
|
|
file <filename>foo.pgc</filename>:
|
2001-11-01 04:37:39 +08:00
|
|
|
<programlisting>
|
1998-03-01 16:16:16 +08:00
|
|
|
exec sql begin declare section;
|
|
|
|
int index;
|
|
|
|
int result;
|
|
|
|
exec sql end declare section;
|
|
|
|
...
|
1999-03-24 22:54:10 +08:00
|
|
|
exec sql select res into :result from mytable where index = :index;
|
2001-11-01 04:37:39 +08:00
|
|
|
</programlisting>
|
2000-03-31 06:22:41 +08:00
|
|
|
is translated into:
|
2001-11-01 04:37:39 +08:00
|
|
|
<programlisting>
|
1999-03-24 22:54:10 +08:00
|
|
|
/* Processed by ecpg (2.6.0) */
|
1998-03-01 16:16:16 +08:00
|
|
|
/* These two include files are added by the preprocessor */
|
1999-03-24 22:54:10 +08:00
|
|
|
#include <ecpgtype.h>;
|
|
|
|
#include <ecpglib.h>;
|
|
|
|
|
1998-03-01 16:16:16 +08:00
|
|
|
/* exec sql begin declare section */
|
|
|
|
|
1999-03-24 22:54:10 +08:00
|
|
|
#line 1 "foo.pgc"
|
|
|
|
|
1998-03-01 16:16:16 +08:00
|
|
|
int index;
|
|
|
|
int result;
|
|
|
|
/* exec sql end declare section */
|
|
|
|
...
|
1999-03-24 22:54:10 +08:00
|
|
|
ECPGdo(__LINE__, NULL, "select res from mytable where index = ? ",
|
2001-11-01 04:37:39 +08:00
|
|
|
ECPGt_int,&(index),1L,1L,sizeof(int),
|
1999-03-24 22:54:10 +08:00
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
|
|
|
|
ECPGt_int,&(result),1L,1L,sizeof(int),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
|
|
|
|
#line 147 "foo.pgc"
|
2001-11-01 04:37:39 +08:00
|
|
|
</programlisting>
|
2001-09-06 08:23:42 +08:00
|
|
|
(The indentation in this manual is added for readability and not
|
|
|
|
something the preprocessor does.)
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
<title>The Library</title>
|
|
|
|
|
|
|
|
<para>
|
2001-09-06 08:23:42 +08:00
|
|
|
The most important function in the library is
|
|
|
|
<function>ECPGdo</function>. It takes a variable number of
|
|
|
|
arguments. Hopefully there are no computers that limit the
|
2001-09-11 05:58:47 +08:00
|
|
|
number of variables that can be accepted by a <function>varargs()</function> function. This
|
2001-09-06 08:23:42 +08:00
|
|
|
can easily add up to 50 or so arguments.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The arguments are:
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>A line number</term>
|
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
This is a line number of the original line; used in error messages only.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term>A string</term>
|
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
This is the <acronym>SQL</acronym> query that is to be issued.
|
|
|
|
It is modified by the input variables, i.e. the variables that
|
|
|
|
where not known at compile time but are to be entered in the
|
|
|
|
query. Where the variables should go the string contains
|
|
|
|
<literal>?</literal>.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term>Input variables</term>
|
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
As described in the section about the preprocessor, every input variable
|
|
|
|
gets ten arguments.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2001-09-11 05:58:47 +08:00
|
|
|
<term><literal>ECPGt_EOIT</literal></term>
|
2000-03-31 06:22:41 +08:00
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
An enum telling that there are no more input variables.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term>Output variables</term>
|
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
As described in the section about the preprocessor, every input variable
|
|
|
|
gets ten arguments. These variables are filled by the function.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term>ECPGt_EORT</term>
|
|
|
|
<listitem>
|
2001-11-01 04:37:39 +08:00
|
|
|
<para>
|
|
|
|
An enum telling that there are no more variables.
|
|
|
|
</para>
|
2000-03-31 06:22:41 +08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2002-01-19 04:32:54 +08:00
|
|
|
In the default mode, queries are committed only when <command>exec
|
|
|
|
sql commit</command> is issued. <application>Ecpg</application>
|
|
|
|
also supports auto-commit of transactions via the
|
|
|
|
<option>-t</option> command-line option or via the <literal>exec
|
|
|
|
sql set autocommit to on</literal> statement. In
|
2002-01-19 05:17:07 +08:00
|
|
|
<literal>autocommit</literal> mode, each query is automatically
|
2002-01-19 04:32:54 +08:00
|
|
|
committed unless it is inside an explicit transaction block. This
|
|
|
|
mode can be explicitly turned off using <literal>exec sql set
|
|
|
|
autocommit to off</literal>.
|
2000-03-31 06:22:41 +08:00
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
</sect1>
|
|
|
|
</chapter>
|
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode:sgml
|
|
|
|
sgml-omittag:nil
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
sgml-parent-document:nil
|
|
|
|
sgml-default-dtd-file:"./reference.ced"
|
|
|
|
sgml-exposed-tags:nil
|
2000-03-31 11:27:42 +08:00
|
|
|
sgml-local-catalogs:("/usr/lib/sgml/catalog")
|
2000-03-31 06:22:41 +08:00
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
-->
|