Home Explore Blog CI



postgresql

46th chunk of `doc/src/sgml/libpq.sgml`
f0e692de6fa4d135f7cbedc4e5b2b3aedb3780f0a44354cf0000000100000fa1
 <productname>OpenSSL</productname>, there is one struct,
       available under the name <literal>OpenSSL</literal>,
       and it returns a pointer to
       <productname>OpenSSL</productname>'s <literal>SSL</literal> struct.
       To use this function, code along the following lines could be used:
<programlisting><![CDATA[
#include <libpq-fe.h>
#include <openssl/ssl.h>

...

    SSL *ssl;

    dbconn = PQconnectdb(...);
    ...

    ssl = PQsslStruct(dbconn, "OpenSSL");
    if (ssl)
    {
        /* use OpenSSL functions to access ssl */
    }
]]></programlisting>
      </para>
      <para>
       This structure can be used to verify encryption levels, check server
       certificates, and more. Refer to the <productname>OpenSSL</productname>
       documentation for information about this structure.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQgetssl">
     <term><function>PQgetssl</function><indexterm><primary>PQgetssl</primary></indexterm></term>
     <listitem>
      <para>
       <indexterm><primary>SSL</primary><secondary sortas="libpq">in libpq</secondary></indexterm>
       Returns the SSL structure used in the connection, or NULL
       if SSL is not in use.

<synopsis>
void *PQgetssl(const PGconn *conn);
</synopsis>
      </para>

      <para>
       This function is equivalent to <literal>PQsslStruct(conn, "OpenSSL")</literal>. It should
       not be used in new applications, because the returned struct is
       specific to <productname>OpenSSL</productname> and will not be
       available if another <acronym>SSL</acronym> implementation is used.
       To check if a connection uses SSL, call
       <xref linkend="libpq-PQsslInUse"/> instead, and for more details about the
       connection, use <xref linkend="libpq-PQsslAttribute"/>.
      </para>
     </listitem>
    </varlistentry>

   </variablelist>
  </para>

 </sect1>

 <sect1 id="libpq-exec">
  <title>Command Execution Functions</title>

  <para>
   Once a connection to a database server has been successfully
   established, the functions described here are used to perform
   SQL queries and commands.
  </para>

  <sect2 id="libpq-exec-main">
   <title>Main Functions</title>

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

      <listitem>
       <para>
        Submits a command to the server and waits for the result.

<synopsis>
PGresult *PQexec(PGconn *conn, const char *command);
</synopsis>
       </para>

       <para>
        Returns a <structname>PGresult</structname> pointer or possibly a null
        pointer.  A non-null pointer will generally be returned except in
        out-of-memory conditions or serious errors such as inability to send
        the command to the server.  The <xref linkend="libpq-PQresultStatus"/> function
        should be called to check the return value for any errors (including
        the value of a null pointer, in which case it will return
        <symbol>PGRES_FATAL_ERROR</symbol>).  Use
        <xref linkend="libpq-PQerrorMessage"/> to get more information about such
        errors.
       </para>
      </listitem>
     </varlistentry>
    </variablelist>

    The command string can include multiple SQL commands
    (separated by semicolons).  Multiple queries sent in a single
    <xref linkend="libpq-PQexec"/> call are processed in a single transaction, unless
    there are explicit <command>BEGIN</command>/<command>COMMIT</command>
    commands included in the query string to divide it into multiple
    transactions.  (See <xref linkend="protocol-flow-multi-statement"/>
    for more details about how the server handles multi-query strings.)
    Note however that the returned
    <structname>PGresult</structname> structure describes only the result
    of the last command executed from the string.  Should one of the
    commands fail, processing of the string stops

Title: PQgetssl Function and Command Execution Functions in libpq
Summary
This section covers the PQgetssl function, which returns the SSL structure used in a connection (equivalent to PQsslStruct(conn, "OpenSSL")), but is discouraged for new applications due to its OpenSSL-specific nature. It then introduces command execution functions, starting with PQexec, which submits a command to the server and waits for the result, returning a PGresult pointer.