Home Explore Blog CI



postgresql

39th chunk of `doc/src/sgml/libpq.sgml`
3c3898fe269981290e8f647e58bb58409d5a2577cdb7517b0000000100000faf
 linkend="libpq-PQport"/> until
       the connection is established.  The status of the connection can be
       checked using the function <xref linkend="libpq-PQstatus"/>.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQservice">
     <term><function>PQservice</function><indexterm><primary>PQservice</primary></indexterm></term>

     <listitem>
      <para>
       Returns the service of the active connection.

<synopsis>
char *PQservice(const PGconn *conn);
</synopsis>
      </para>

      <para>
       <xref linkend="libpq-PQservice"/> returns <symbol>NULL</symbol> if the
       <parameter>conn</parameter> argument is <symbol>NULL</symbol>.
       Otherwise, if there was no service provided, it returns an empty string.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQtty">
     <term><function>PQtty</function><indexterm><primary>PQtty</primary></indexterm></term>

     <listitem>
      <para>
       This function no longer does anything, but it remains for backwards
       compatibility.  The function always return an empty string, or
       <symbol>NULL</symbol> if the <parameter>conn</parameter> argument is
       <symbol>NULL</symbol>.

<synopsis>
char *PQtty(const PGconn *conn);
</synopsis>
      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQoptions">
     <term><function>PQoptions</function><indexterm><primary>PQoptions</primary></indexterm></term>

     <listitem>
      <para>
       Returns the command-line options passed in the connection request.
<synopsis>
char *PQoptions(const PGconn *conn);
</synopsis>
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>

  <para>
   The following functions return status data that can change as operations
   are executed on the <structname>PGconn</structname> object.

   <variablelist>
    <varlistentry id="libpq-PQstatus">
     <term><function>PQstatus</function><indexterm><primary>PQstatus</primary></indexterm></term>

     <listitem>
      <para>
       Returns the status of the connection.
<synopsis>
ConnStatusType PQstatus(const PGconn *conn);
</synopsis>
      </para>

      <para>
       The status can be one of a number of values.  However, only two of
       these are seen outside of an asynchronous connection procedure:
       <symbol>CONNECTION_OK</symbol> and
       <symbol>CONNECTION_BAD</symbol>. A good connection to the database
       has the status <symbol>CONNECTION_OK</symbol>.  A failed
       connection attempt is signaled by status
       <symbol>CONNECTION_BAD</symbol>.  Ordinarily, an OK status will
       remain so until <xref linkend="libpq-PQfinish"/>, but a communications
       failure might result in the status changing to
       <symbol>CONNECTION_BAD</symbol> prematurely.  In that case the
       application could try to recover by calling
       <xref linkend="libpq-PQreset"/>.
      </para>

      <para>
       See the entry for <xref linkend="libpq-PQconnectStartParams"/>, <function>PQconnectStart</function>
       and <function>PQconnectPoll</function> with regards to other status codes that
       might be returned.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQtransactionStatus">
     <term><function>PQtransactionStatus</function><indexterm><primary>PQtransactionStatus</primary></indexterm></term>

     <listitem>
      <para>
       Returns the current in-transaction status of the server.

<synopsis>
PGTransactionStatusType PQtransactionStatus(const PGconn *conn);
</synopsis>

       The status can be <literal>PQTRANS_IDLE</literal> (currently idle),
       <literal>PQTRANS_ACTIVE</literal> (a command is in progress),
       <literal>PQTRANS_INTRANS</literal> (idle, in a valid transaction block),
       or <literal>PQTRANS_INERROR</literal> (idle, in a failed transaction block).
       <literal>PQTRANS_UNKNOWN</literal> is reported if the connection is bad.
       <literal>PQTRANS_ACTIVE</literal>

Title: Connection Status Functions: PQtty, PQoptions, PQstatus, and PQtransactionStatus
Summary
This section documents the functions PQtty (now deprecated), PQoptions (returns command-line options), PQstatus (returns the connection status), and PQtransactionStatus (returns the current transaction status of the server). PQtty always returns an empty string or NULL if the connection is NULL. PQstatus returns CONNECTION_OK or CONNECTION_BAD. PQtransactionStatus returns the transaction state: idle, active, in a valid transaction block, or in a failed transaction block.