Home Explore Blog CI



postgresql

66th chunk of `doc/src/sgml/libpq.sgml`
1b39b40c726c5b29f859b897f207fbde25e0f69186e55cef0000000100000ffd
 <term><function>PQcmdStatus</function><indexterm><primary>PQcmdStatus</primary></indexterm></term>

     <listitem>
      <para>
       Returns the command status tag from the SQL command that generated
       the <structname>PGresult</structname>.
<synopsis>
char *PQcmdStatus(PGresult *res);
</synopsis>
      </para>

      <para>
       Commonly this is just the name of the command, but it might include
       additional data such as the number of rows processed. The caller
       should not free the result directly. It will be freed when the
       associated <structname>PGresult</structname> handle is passed to
       <xref linkend="libpq-PQclear"/>.
      </para>
     </listitem>
    </varlistentry>

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

     <listitem>
      <para>
       Returns the number of rows affected by the SQL command.
<synopsis>
char *PQcmdTuples(PGresult *res);
</synopsis>
      </para>

      <para>
       This function returns a string containing the number of rows
       affected by the <acronym>SQL</acronym> statement that generated the
       <structname>PGresult</structname>. This function can only be used following
       the execution of a <command>SELECT</command>, <command>CREATE TABLE AS</command>,
       <command>INSERT</command>, <command>UPDATE</command>, <command>DELETE</command>,
       <command>MERGE</command>, <command>MOVE</command>, <command>FETCH</command>,
       or <command>COPY</command> statement, or an <command>EXECUTE</command> of a
       prepared query that contains an <command>INSERT</command>,
       <command>UPDATE</command>, <command>DELETE</command>,
       or <command>MERGE</command> statement.
       If the command that generated the <structname>PGresult</structname> was anything
       else, <xref linkend="libpq-PQcmdTuples"/> returns an empty string. The caller
       should not free the return value directly. It will be freed when
       the associated <structname>PGresult</structname> handle is passed to
       <xref linkend="libpq-PQclear"/>.
      </para>
     </listitem>
    </varlistentry>

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

     <listitem>
      <para>
       Returns the OID<indexterm><primary>OID</primary><secondary>in libpq</secondary></indexterm>
       of the inserted row, if the <acronym>SQL</acronym> command was an
       <command>INSERT</command> that inserted exactly one row into a table that
       has OIDs, or a <command>EXECUTE</command> of a prepared query containing
       a suitable <command>INSERT</command> statement.  Otherwise, this function
       returns <literal>InvalidOid</literal>. This function will also
       return <literal>InvalidOid</literal> if the table affected by the
       <command>INSERT</command> statement does not contain OIDs.
<synopsis>
Oid PQoidValue(const PGresult *res);
</synopsis>
      </para>
     </listitem>
    </varlistentry>

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

     <listitem>
      <para>
       This function is deprecated in favor of
       <xref linkend="libpq-PQoidValue"/> and is not thread-safe.
       It returns a string with the OID of the inserted row, while
       <xref linkend="libpq-PQoidValue"/> returns the OID value.
<synopsis>
char *PQoidStatus(const PGresult *res);
</synopsis>
      </para>

     </listitem>
    </varlistentry>
   </variablelist>

  </sect2>

  <sect2 id="libpq-exec-escape-string">
   <title>Escaping Strings for Inclusion in SQL Commands</title>

   <indexterm zone="libpq-exec-escape-string">
    <primary>escaping strings</primary>
    <secondary>in libpq</secondary>
   </indexterm>

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

Title: libpq Functions: Retrieving Command Status, Affected Rows, and OID Values
Summary
This section describes libpq functions for retrieving information from PGresult objects. `PQcmdStatus` returns the command status tag. `PQcmdTuples` returns the number of rows affected. `PQoidValue` returns the OID of the inserted row if the command was a single-row INSERT. `PQoidStatus` is a deprecated, non-thread-safe alternative.