= f (type: 1)
datconnlimit = -1 (type: 5)
datfrozenxid = 379 (type: 1)
dattablespace = 1663 (type: 1)
datconfig = (type: 1)
datacl = (type: 1)
datid = 11511 (type: 1)
datname = postgres (type: 1)
numbackends = 0 (type: 5)
xact_commit = 221069 (type: 9)
xact_rollback = 18 (type: 9)
blks_read = 1176 (type: 9)
blks_hit = 13943750 (type: 9)
tup_returned = 77410091 (type: 9)
tup_fetched = 3253694 (type: 9)
tup_inserted = 0 (type: 9)
tup_updated = 0 (type: 9)
tup_deleted = 0 (type: 9)
</screen>
</example>
</sect3>
</sect2>
</sect1>
<sect1 id="ecpg-errors">
<title>Error Handling</title>
<para>
This section describes how you can handle exceptional conditions
and warnings in an embedded SQL program. There are two
nonexclusive facilities for this.
<itemizedlist>
<listitem>
<simpara>
Callbacks can be configured to handle warning and error
conditions using the <literal>WHENEVER</literal> command.
</simpara>
</listitem>
<listitem>
<simpara>
Detailed information about the error or warning can be obtained
from the <varname>sqlca</varname> variable.
</simpara>
</listitem>
</itemizedlist>
</para>
<sect2 id="ecpg-whenever">
<title>Setting Callbacks</title>
<para>
One simple method to catch errors and warnings is to set a
specific action to be executed whenever a particular condition
occurs. In general:
<programlisting>
EXEC SQL WHENEVER <replaceable>condition</replaceable> <replaceable>action</replaceable>;
</programlisting>
</para>
<para>
<replaceable>condition</replaceable> can be one of the following:
<variablelist>
<varlistentry id="ecpg-whenever-sqlerror">
<term><literal>SQLERROR</literal></term>
<listitem>
<para>
The specified action is called whenever an error occurs during
the execution of an SQL statement.
</para>
</listitem>
</varlistentry>
<varlistentry id="ecpg-whenever-sqlwarning">
<term><literal>SQLWARNING</literal></term>
<listitem>
<para>
The specified action is called whenever a warning occurs
during the execution of an SQL statement.
</para>
</listitem>
</varlistentry>
<varlistentry id="ecpg-whenever-not-found">
<term><literal>NOT FOUND</literal></term>
<listitem>
<para>
The specified action is called whenever an SQL statement
retrieves or affects zero rows. (This condition is not an
error, but you might be interested in handling it specially.)
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
<replaceable>action</replaceable> can be one of the following:
<variablelist>
<varlistentry id="ecpg-whenever-continue">
<term><literal>CONTINUE</literal></term>
<listitem>
<para>
This effectively means that the condition is ignored. This is
the default.
</para>
</listitem>
</varlistentry>
<varlistentry id="ecpg-whenever-goto">
<term><literal>GOTO <replaceable>label</replaceable></literal></term>
<term><literal>GO TO <replaceable>label</replaceable></literal></term>
<listitem>
<para>
Jump to the specified label (using a C <literal>goto</literal>
statement).
</para>
</listitem>
</varlistentry>
<varlistentry id="ecpg-whenever-sqlprint">
<term><literal>SQLPRINT</literal></term>
<listitem>
<para>
Print a message to standard error. This is useful for simple
programs or during prototyping. The details of the message
cannot be configured.
</para>
</listitem>
</varlistentry>
<varlistentry id="ecpg-whenever-stop">
<term><literal>STOP</literal></term>
<listitem>
<para>
Call <literal>exit(1)</literal>, which will terminate the
program.
</para>
</listitem>