can also
be used in embedded programs. The <xref linkend="sql-execute"/>
command is used to execute either kind of prepared statement.
</para>
</refsect1>
<refsect1>
<title>Parameters</title>
<variablelist>
<varlistentry id="ecpg-sql-prepare-prepared-name">
<term><replaceable class="parameter">prepared_name</replaceable></term>
<listitem>
<para>
An identifier for the prepared query.
</para>
</listitem>
</varlistentry>
<varlistentry id="ecpg-sql-prepare-string">
<term><replaceable class="parameter">string</replaceable></term>
<listitem>
<para>
A literal string or a host variable containing a preparable
SQL statement, one of SELECT, INSERT, UPDATE, or DELETE.
Use question marks (<literal>?</literal>) for parameter values
to be supplied at execution.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Notes</title>
<para>
In typical usage, the <replaceable>string</replaceable> is a host
variable reference to a string containing a dynamically-constructed
SQL statement. The case of a literal string is not very useful;
you might as well just write a direct SQL <command>PREPARE</command>
statement.
</para>
<para>
If you do use a literal string, keep in mind that any double quotes
you might wish to include in the SQL statement must be written as
octal escapes (<literal>\042</literal>) not the usual C
idiom <literal>\"</literal>. This is because the string is inside
an <literal>EXEC SQL</literal> section, so the ECPG lexer parses it
according to SQL rules not C rules. Any embedded backslashes will
later be handled according to C rules; but <literal>\"</literal>
causes an immediate syntax error because it is seen as ending the
literal.
</para>
</refsect1>
<refsect1>
<title>Examples</title>
<programlisting>
char *stmt = "SELECT * FROM test1 WHERE a = ? AND b = ?";
EXEC SQL ALLOCATE DESCRIPTOR outdesc;
EXEC SQL PREPARE foo FROM :stmt;
EXEC SQL EXECUTE foo USING SQL DESCRIPTOR indesc INTO SQL DESCRIPTOR outdesc;
</programlisting>
</refsect1>
<refsect1>
<title>Compatibility</title>
<para>
<command>PREPARE</command> is specified in the SQL standard.
</para>
</refsect1>
<refsect1>
<title>See Also</title>
<simplelist type="inline">
<member><xref linkend="sql-execute"/></member>
</simplelist>
</refsect1>
</refentry>
<refentry id="ecpg-sql-set-autocommit">
<refnamediv>
<refname>SET AUTOCOMMIT</refname>
<refpurpose>set the autocommit behavior of the current session</refpurpose>
</refnamediv>
<refsynopsisdiv>
<synopsis>
SET AUTOCOMMIT { = | TO } { ON | OFF }
</synopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>
<command>SET AUTOCOMMIT</command> sets the autocommit behavior of
the current database session. By default, embedded SQL programs
are <emphasis>not</emphasis> in autocommit mode,
so <command>COMMIT</command> needs to be issued explicitly when
desired. This command can change the session to autocommit mode,
where each individual statement is committed implicitly.
</para>
</refsect1>
<refsect1>
<title>Compatibility</title>
<para>
<command>SET AUTOCOMMIT</command> is an extension of PostgreSQL ECPG.
</para>
</refsect1>
</refentry>
<refentry id="ecpg-sql-set-connection">
<refnamediv>
<refname>SET CONNECTION</refname>
<refpurpose>select a database connection</refpurpose>
</refnamediv>
<refsynopsisdiv>
<synopsis>
SET CONNECTION [ TO | = ] <replaceable class="parameter">connection_name</replaceable>
</synopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>
<command>SET CONNECTION</command> sets the <quote>current</quote>