Home Explore Blog CI



postgresql

80th chunk of `doc/src/sgml/ecpg.sgml`
2e9172f763444dde9fcaa1d89ef9304adb120fb9232dfd6c0000000100000fa3
 </refsect1>

   <refsect1>
    <title>Compatibility</title>

    <para>
     <command>DESCRIBE</command> is specified in the SQL standard.
    </para>
   </refsect1>

   <refsect1>
    <title>See Also</title>

    <simplelist type="inline">
     <member><xref linkend="ecpg-sql-allocate-descriptor"/></member>
     <member><xref linkend="ecpg-sql-get-descriptor"/></member>
    </simplelist>
   </refsect1>
  </refentry>

  <refentry id="ecpg-sql-disconnect">
   <refnamediv>
    <refname>DISCONNECT</refname>
    <refpurpose>terminate a database connection</refpurpose>
   </refnamediv>

   <refsynopsisdiv>
<synopsis>
DISCONNECT <replaceable class="parameter">connection_name</replaceable>
DISCONNECT [ CURRENT ]
DISCONNECT ALL
</synopsis>
   </refsynopsisdiv>

   <refsect1>
    <title>Description</title>

    <para>
     <command>DISCONNECT</command> closes a connection (or all
     connections) to the database.
    </para>
   </refsect1>

   <refsect1>
    <title>Parameters</title>

    <variablelist>
     <varlistentry id="ecpg-sql-disconnect-connection-name">
      <term><replaceable class="parameter">connection_name</replaceable></term>
      <listitem>
       <para>
        A database connection name established by
        the <command>CONNECT</command> command.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry id="ecpg-sql-disconnect-current">
      <term><literal>CURRENT</literal></term>
      <listitem>
       <para>
        Close the <quote>current</quote> connection, which is either
        the most recently opened connection, or the connection set by
        the <command>SET CONNECTION</command> command.  This is also
        the default if no argument is given to
        the <command>DISCONNECT</command> command.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry id="ecpg-sql-disconnect-all">
      <term><literal>ALL</literal></term>
      <listitem>
       <para>
        Close all open connections.
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
   </refsect1>

   <refsect1>
    <title>Examples</title>

<programlisting>
int
main(void)
{
    EXEC SQL CONNECT TO testdb AS con1 USER testuser;
    EXEC SQL CONNECT TO testdb AS con2 USER testuser;
    EXEC SQL CONNECT TO testdb AS con3 USER testuser;

    EXEC SQL DISCONNECT CURRENT;  /* close con3          */
    EXEC SQL DISCONNECT ALL;      /* close con2 and con1 */

    return 0;
}
</programlisting>
   </refsect1>

   <refsect1>
    <title>Compatibility</title>

    <para>
     <command>DISCONNECT</command> is specified in the SQL standard.
    </para>
   </refsect1>

   <refsect1>
    <title>See Also</title>

    <simplelist type="inline">
     <member><xref linkend="ecpg-sql-connect"/></member>
     <member><xref linkend="ecpg-sql-set-connection"/></member>
    </simplelist>
   </refsect1>
  </refentry>

  <refentry id="ecpg-sql-execute-immediate">
   <refnamediv>
    <refname>EXECUTE IMMEDIATE</refname>
    <refpurpose>dynamically prepare and execute a statement</refpurpose>
   </refnamediv>

   <refsynopsisdiv>
<synopsis>
EXECUTE IMMEDIATE <replaceable class="parameter">string</replaceable>
</synopsis>
   </refsynopsisdiv>

   <refsect1>
    <title>Description</title>

    <para>
     <command>EXECUTE IMMEDIATE</command> immediately prepares and
     executes a dynamically specified SQL statement, without
     retrieving result rows.
    </para>
   </refsect1>

   <refsect1>
    <title>Parameters</title>

    <variablelist>
     <varlistentry id="ecpg-sql-execute-immediate-string">
      <term><replaceable class="parameter">string</replaceable></term>
      <listitem>
       <para>
        A literal string or a host variable containing the SQL
        statement to be executed.
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
   </refsect1>

   <refsect1>
    <title>Notes</title>

    <para>
     In typical usage, the <replaceable>string</replaceable> is a host
     variable

Title: ECPG DISCONNECT Command: Terminating Database Connections
Summary
This section describes the ECPG `DISCONNECT` command, which closes database connections. It details the parameters: `connection_name` (a database connection name established by `CONNECT`), `CURRENT` (closes the most recently opened or connection set by `SET CONNECTION`), and `ALL` (closes all open connections). An example shows how to connect to the database multiple times and then disconnect using `CURRENT` and `ALL`. The section also mentions that `DISCONNECT` is specified in the SQL standard and lists related commands like `CONNECT` and `SET CONNECTION`.