Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > media > main-testing > by-pkgid > bab02a23fa9f3df8d66a9a3231b50245 > files > 339

postgresql8.3-docs-8.3.6-2mdv2008.1.x86_64.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Database Connection Control Functions</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 8.3.6 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="libpq - C Library"
HREF="libpq.html"><LINK
REL="PREVIOUS"
TITLE="libpq - C Library"
HREF="libpq.html"><LINK
REL="NEXT"
TITLE="Connection Status Functions"
HREF="libpq-status.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2009-02-03T04:34:16"></HEAD
><BODY
CLASS="SECT1"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
>PostgreSQL 8.3.6 Documentation</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="libpq.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="libpq.html"
>Fast Backward</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
>Chapter 30. <SPAN
CLASS="APPLICATION"
>libpq</SPAN
> - C Library</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="libpq.html"
>Fast Forward</A
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="libpq-status.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="LIBPQ-CONNECT"
>30.1. Database Connection Control Functions</A
></H1
><P
>   The following functions deal with making a connection to a
   <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> backend server.  An
   application program can have several backend connections open at
   one time.  (One reason to do that is to access more than one
   database.)  Each connection is represented by a
   <TT
CLASS="STRUCTNAME"
>PGconn</TT
><A
NAME="AEN30251"
></A
> object, which
   is obtained from the function <CODE
CLASS="FUNCTION"
>PQconnectdb</CODE
> or
   <CODE
CLASS="FUNCTION"
>PQsetdbLogin</CODE
>.  Note that these functions will always
   return a non-null object pointer, unless perhaps there is too
   little memory even to allocate the <TT
CLASS="STRUCTNAME"
>PGconn</TT
> object.
   The <CODE
CLASS="FUNCTION"
>PQstatus</CODE
> function should be called to check
   whether a connection was successfully made before queries are sent
   via the connection object.

   <P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><DT
><CODE
CLASS="FUNCTION"
>PQconnectdb</CODE
><A
NAME="AEN30261"
></A
></DT
><DD
><P
>       Makes a new connection to the database server.

       </P><PRE
CLASS="SYNOPSIS"
>        PGconn *PQconnectdb(const char *conninfo);
       </PRE
><P>
      </P
><P
>       This function opens a new database connection using the parameters taken
       from the string <TT
CLASS="LITERAL"
>conninfo</TT
>.  Unlike <CODE
CLASS="FUNCTION"
>PQsetdbLogin</CODE
> below,
       the parameter set can be extended without changing the function signature,
       so use of this function (or its nonblocking analogues <CODE
CLASS="FUNCTION"
>PQconnectStart</CODE
>
       and <CODE
CLASS="FUNCTION"
>PQconnectPoll</CODE
>) is preferred for new application programming.
      </P
><P
>       The passed string
       can be empty to use all default parameters, or it can contain one or more
       parameter settings separated by whitespace.
       Each parameter setting is in the form <TT
CLASS="LITERAL"
>keyword = value</TT
>.
       Spaces around the equal sign are optional.
       To write an empty value or a value containing
       spaces, surround it with single quotes, e.g.,
       <TT
CLASS="LITERAL"
>keyword = 'a value'</TT
>.
       Single quotes and backslashes within the value must be escaped with a
       backslash, i.e., <TT
CLASS="LITERAL"
>\'</TT
> and <TT
CLASS="LITERAL"
>\\</TT
>.
      </P
><P
>       The currently recognized parameter key words are:

       <P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="LITERAL"
>host</TT
></DT
><DD
><P
>           Name of host to connect to.<A
NAME="AEN30283"
></A
>
           If this begins with a slash, it specifies Unix-domain
           communication rather than TCP/IP communication; the value is the
           name of the directory in which the socket file is stored.  The
           default behavior when <TT
CLASS="LITERAL"
>host</TT
> is not specified
           is to connect to a Unix-domain
           socket<A
NAME="AEN30286"
></A
> in
           <TT
CLASS="FILENAME"
>/tmp</TT
> (or whatever socket directory was specified
           when <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> was built). On machines without
           Unix-domain sockets, the default is to connect to <TT
CLASS="LITERAL"
>localhost</TT
>.
          </P
></DD
><DT
><TT
CLASS="LITERAL"
>hostaddr</TT
></DT
><DD
><P
>           Numeric IP address of host to connect to.  This should be in the
           standard IPv4 address format, e.g., <TT
CLASS="LITERAL"
>172.28.40.9</TT
>.  If
           your machine supports IPv6, you can also use those addresses.
           TCP/IP communication is
           always used when a nonempty string is specified for this parameter.
          </P
><P
>           Using <TT
CLASS="LITERAL"
>hostaddr</TT
> instead of <TT
CLASS="LITERAL"
>host</TT
> allows the
           application to avoid a host name look-up, which might be important in
           applications with time constraints. However, Kerberos and GSSAPI authentication
           requires the host name. The following therefore applies: If
           <TT
CLASS="LITERAL"
>host</TT
> is specified without <TT
CLASS="LITERAL"
>hostaddr</TT
>, a host name
           lookup occurs. If <TT
CLASS="LITERAL"
>hostaddr</TT
> is specified without
           <TT
CLASS="LITERAL"
>host</TT
>, the value for <TT
CLASS="LITERAL"
>hostaddr</TT
> gives the remote
           address. When Kerberos is used, a reverse name query occurs to obtain
           the host name for Kerberos. If both
           <TT
CLASS="LITERAL"
>host</TT
> and <TT
CLASS="LITERAL"
>hostaddr</TT
> are specified, the value for
           <TT
CLASS="LITERAL"
>hostaddr</TT
> gives the remote address; the value for
           <TT
CLASS="LITERAL"
>host</TT
> is ignored, unless Kerberos is used, in which case that
           value is used for Kerberos authentication. (Note that authentication is
           likely to fail if <SPAN
CLASS="APPLICATION"
>libpq</SPAN
> is passed a host name
           that is not the name of the machine at <TT
CLASS="LITERAL"
>hostaddr</TT
>.)  Also,
           <TT
CLASS="LITERAL"
>host</TT
> rather than <TT
CLASS="LITERAL"
>hostaddr</TT
> is used to identify
           the connection in <TT
CLASS="FILENAME"
>~/.pgpass</TT
> (see
           <A
HREF="libpq-pgpass.html"
>Section 30.13</A
>).
          </P
><P
>           Without either a host name or host address,
           <SPAN
CLASS="APPLICATION"
>libpq</SPAN
> will connect using a
           local Unix-domain socket; or on machines without Unix-domain
           sockets, it will attempt to connect to <TT
CLASS="LITERAL"
>localhost</TT
>.
          </P
></DD
><DT
><TT
CLASS="LITERAL"
>port</TT
></DT
><DD
><P
>           Port number to connect to at the server host, or socket file
           name extension for Unix-domain
           connections.<A
NAME="AEN30323"
></A
>
          </P
></DD
><DT
><TT
CLASS="LITERAL"
>dbname</TT
></DT
><DD
><P
>          The database name.  Defaults to be the same as the user name.
         </P
></DD
><DT
><TT
CLASS="LITERAL"
>user</TT
></DT
><DD
><P
>          <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> user name to connect as.
          Defaults to be the same as the operating system name of the user
          running the application.
         </P
></DD
><DT
><TT
CLASS="LITERAL"
>password</TT
></DT
><DD
><P
>          Password to be used if the server demands password authentication.
         </P
></DD
><DT
><TT
CLASS="LITERAL"
>connect_timeout</TT
></DT
><DD
><P
>          Maximum wait for connection, in seconds (write as a decimal integer
          string). Zero or not specified means wait indefinitely.  It is not
          recommended to use a timeout of less than 2 seconds.
         </P
></DD
><DT
><TT
CLASS="LITERAL"
>options</TT
></DT
><DD
><P
>           Command-line options to be sent to the server.
          </P
></DD
><DT
><TT
CLASS="LITERAL"
>tty</TT
></DT
><DD
><P
>          Ignored (formerly, this specified where to send server debug output).
         </P
></DD
><DT
><TT
CLASS="LITERAL"
>sslmode</TT
></DT
><DD
><P
>           This option determines whether or with what priority a
           <ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
> TCP/IP connection will be negotiated with the
           server. There are four modes: <TT
CLASS="LITERAL"
>disable</TT
> will attempt
           only an unencrypted <ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
> connection;
           <TT
CLASS="LITERAL"
>allow</TT
> will negotiate, trying first a
           non-<ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
> connection, then if that fails, trying an
           <ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
> connection; <TT
CLASS="LITERAL"
>prefer</TT
> (the default)
           will negotiate, trying first an <ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
> connection,
           then if that fails, trying a regular non-<ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
>
           connection; <TT
CLASS="LITERAL"
>require</TT
> will try only an
           <ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
> connection.  <TT
CLASS="LITERAL"
>sslmode</TT
> is ignored
           for Unix domain socket communication.
          </P
><P
>           If <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> is compiled without SSL support,
           using option <TT
CLASS="LITERAL"
>require</TT
> will cause an error, while
           options <TT
CLASS="LITERAL"
>allow</TT
> and <TT
CLASS="LITERAL"
>prefer</TT
> will be
           accepted but <SPAN
CLASS="APPLICATION"
>libpq</SPAN
> will not in fact attempt
           an <ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
>
           connection.<A
NAME="AEN30380"
></A
>
          </P
></DD
><DT
><TT
CLASS="LITERAL"
>requiressl</TT
></DT
><DD
><P
>           This option is deprecated in favor of the <TT
CLASS="LITERAL"
>sslmode</TT
>
           setting.
          </P
><P
>           If set to 1, an <ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
> connection to the server
           is required (this is equivalent to <TT
CLASS="LITERAL"
>sslmode</TT
>
           <TT
CLASS="LITERAL"
>require</TT
>).  <SPAN
CLASS="APPLICATION"
>libpq</SPAN
> will then refuse
           to connect if the server does not accept an
           <ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
> connection.  If set to 0 (default),
           <SPAN
CLASS="APPLICATION"
>libpq</SPAN
> will negotiate the connection type with
           the server (equivalent to <TT
CLASS="LITERAL"
>sslmode</TT
>
           <TT
CLASS="LITERAL"
>prefer</TT
>).  This option is only available if
           <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> is compiled with SSL support.
          </P
></DD
><DT
><TT
CLASS="LITERAL"
>krbsrvname</TT
></DT
><DD
><P
>           Kerberos service name to use when authenticating with Kerberos 5
           or GSSAPI.
           This must match the service name specified in the server
           configuration for Kerberos authentication to succeed. (See also
           <A
HREF="auth-methods.html#KERBEROS-AUTH"
>Section 21.2.5</A
> and <A
HREF="auth-methods.html#GSSAPI-AUTH"
>Section 21.2.3</A
>.)
          </P
></DD
><DT
><TT
CLASS="LITERAL"
>gsslib</TT
></DT
><DD
><P
>           GSS library to use for GSSAPI authentication. Only used on Windows.
           Set to <TT
CLASS="LITERAL"
>gssapi</TT
> to force libpq to use the GSSAPI
           library for authentication instead of the default SSPI.
          </P
></DD
><DT
><TT
CLASS="LITERAL"
>service</TT
></DT
><DD
><P
>           Service name to use for additional parameters.  It specifies a service
           name in <TT
CLASS="FILENAME"
>pg_service.conf</TT
> that holds additional connection parameters.
           This allows applications to specify only a service name so connection parameters
           can be centrally maintained. See <A
HREF="libpq-pgservice.html"
>Section 30.14</A
>.
          </P
></DD
></DL
></DIV
><P>

       If  any  parameter is unspecified, then the corresponding
       environment variable (see <A
HREF="libpq-envars.html"
>Section 30.12</A
>)
       is checked. If the  environment  variable is not set either,
       then the indicated built-in defaults are used.
      </P
></DD
><DT
><CODE
CLASS="FUNCTION"
>PQsetdbLogin</CODE
><A
NAME="AEN30423"
></A
></DT
><DD
><P
>       Makes a new connection to the database server.
</P><PRE
CLASS="SYNOPSIS"
>PGconn *PQsetdbLogin(const char *pghost,
                     const char *pgport,
                     const char *pgoptions,
                     const char *pgtty,
                     const char *dbName,
                     const char *login,
                     const char *pwd);</PRE
><P>
       </P
><P
>        This is the predecessor of <CODE
CLASS="FUNCTION"
>PQconnectdb</CODE
> with a fixed
        set of parameters.  It has the same functionality except that the
        missing parameters will always take on default values.  Write <TT
CLASS="SYMBOL"
>NULL</TT
> or an
        empty string for any one of the fixed parameters that is to be defaulted.
      </P
><P
>        If the <TT
CLASS="PARAMETER"
>dbName</TT
> contains an <TT
CLASS="SYMBOL"
>=</TT
> sign, it
        is taken as a <TT
CLASS="PARAMETER"
>conninfo</TT
> string in exactly the same way as
        if it had been passed to <CODE
CLASS="FUNCTION"
>PQconnectdb</CODE
>, and the remaining
        parameters are then applied as above.
      </P
></DD
><DT
><CODE
CLASS="FUNCTION"
>PQsetdb</CODE
><A
NAME="AEN30439"
></A
></DT
><DD
><P
>   Makes a new connection to the database server.
</P><PRE
CLASS="SYNOPSIS"
>PGconn *PQsetdb(char *pghost,
                char *pgport,
                char *pgoptions,
                char *pgtty,
                char *dbName);</PRE
><P>
     </P
><P
>      This is a macro that calls <CODE
CLASS="FUNCTION"
>PQsetdbLogin</CODE
> with null pointers
      for the <TT
CLASS="PARAMETER"
>login</TT
> and <TT
CLASS="PARAMETER"
>pwd</TT
> parameters.  It is provided
      for backward compatibility with very old programs.
     </P
></DD
><DT
><CODE
CLASS="FUNCTION"
>PQconnectStart</CODE
><A
NAME="AEN30451"
></A
><BR><CODE
CLASS="FUNCTION"
>PQconnectPoll</CODE
><A
NAME="AEN30455"
></A
></DT
><DD
><P
>       <A
NAME="AEN30459"
></A
>
       Make a connection to the database server in a nonblocking manner.

       </P><PRE
CLASS="SYNOPSIS"
>        PGconn *PQconnectStart(const char *conninfo);
       </PRE
><P>

       </P><PRE
CLASS="SYNOPSIS"
>        PostgresPollingStatusType PQconnectPoll(PGconn *conn);
       </PRE
><P>
      </P
><P
>       These two functions are used to open a connection to a database server such
       that your application's thread of execution is not blocked on remote I/O
       whilst doing so.
       The point of this approach is that the waits for I/O to complete can occur
       in the application's main loop, rather than down inside
       <CODE
CLASS="FUNCTION"
>PQconnectdb</CODE
>, and so the application can manage this
       operation in parallel with other activities.
      </P
><P
>       The database connection is made using the parameters taken from the string
       <TT
CLASS="LITERAL"
>conninfo</TT
>, passed to <CODE
CLASS="FUNCTION"
>PQconnectStart</CODE
>. This string is in
       the same format as described above for <CODE
CLASS="FUNCTION"
>PQconnectdb</CODE
>.
      </P
><P
>       Neither <CODE
CLASS="FUNCTION"
>PQconnectStart</CODE
> nor <CODE
CLASS="FUNCTION"
>PQconnectPoll</CODE
> will block, so long as a number of
       restrictions are met:
       <P
></P
></P><UL
><LI
><P
>          The <TT
CLASS="LITERAL"
>hostaddr</TT
> and <TT
CLASS="LITERAL"
>host</TT
> parameters are used appropriately to ensure that
          name and reverse name queries are not made. See the documentation of
          these parameters under <CODE
CLASS="FUNCTION"
>PQconnectdb</CODE
> above for details.
         </P
></LI
><LI
><P
>          If you call <CODE
CLASS="FUNCTION"
>PQtrace</CODE
>, ensure that the stream object
          into which you trace will not block.
         </P
></LI
><LI
><P
>          You ensure that the socket is in the appropriate state
          before calling <CODE
CLASS="FUNCTION"
>PQconnectPoll</CODE
>, as described below.
         </P
></LI
></UL
><P>
      </P
><P
>       To begin a nonblocking connection request, call <TT
CLASS="LITERAL"
>conn = PQconnectStart("<TT
CLASS="REPLACEABLE"
><I
>connection_info_string</I
></TT
>")</TT
>.
       If <TT
CLASS="VARNAME"
>conn</TT
> is null, then <SPAN
CLASS="APPLICATION"
>libpq</SPAN
> has been unable to allocate a new <TT
CLASS="STRUCTNAME"
>PGconn</TT
>
       structure. Otherwise, a valid <TT
CLASS="STRUCTNAME"
>PGconn</TT
> pointer is returned (though not yet
       representing a valid connection to the database). On return from
       <CODE
CLASS="FUNCTION"
>PQconnectStart</CODE
>, call <TT
CLASS="LITERAL"
>status = PQstatus(conn)</TT
>. If <TT
CLASS="VARNAME"
>status</TT
> equals
       <TT
CLASS="SYMBOL"
>CONNECTION_BAD</TT
>, <CODE
CLASS="FUNCTION"
>PQconnectStart</CODE
> has failed.
      </P
><P
>       If <CODE
CLASS="FUNCTION"
>PQconnectStart</CODE
> succeeds, the next stage is to poll
       <SPAN
CLASS="APPLICATION"
>libpq</SPAN
> so that it can proceed with the connection sequence.
       Use <CODE
CLASS="FUNCTION"
>PQsocket(conn)</CODE
> to obtain the descriptor of the
       socket underlying the database connection.
       Loop thus: If <CODE
CLASS="FUNCTION"
>PQconnectPoll(conn)</CODE
> last returned
       <TT
CLASS="SYMBOL"
>PGRES_POLLING_READING</TT
>, wait until the socket is ready to
       read (as indicated by <CODE
CLASS="FUNCTION"
>select()</CODE
>, <CODE
CLASS="FUNCTION"
>poll()</CODE
>, or
       similar system function).
       Then call <CODE
CLASS="FUNCTION"
>PQconnectPoll(conn)</CODE
> again.
       Conversely, if <CODE
CLASS="FUNCTION"
>PQconnectPoll(conn)</CODE
> last returned
       <TT
CLASS="SYMBOL"
>PGRES_POLLING_WRITING</TT
>, wait until the socket is ready
       to write, then call <CODE
CLASS="FUNCTION"
>PQconnectPoll(conn)</CODE
> again.
       If you have yet to call
       <CODE
CLASS="FUNCTION"
>PQconnectPoll</CODE
>, i.e., just after the call to
       <CODE
CLASS="FUNCTION"
>PQconnectStart</CODE
>, behave as if it last returned
       <TT
CLASS="SYMBOL"
>PGRES_POLLING_WRITING</TT
>.  Continue this loop until
       <CODE
CLASS="FUNCTION"
>PQconnectPoll(conn)</CODE
> returns
       <TT
CLASS="SYMBOL"
>PGRES_POLLING_FAILED</TT
>, indicating the connection procedure
       has failed, or <TT
CLASS="SYMBOL"
>PGRES_POLLING_OK</TT
>, indicating the connection
       has been successfully made.
      </P
><P
>       At any time during connection, the status of the connection can be
       checked by calling <CODE
CLASS="FUNCTION"
>PQstatus</CODE
>. If this gives <TT
CLASS="SYMBOL"
>CONNECTION_BAD</TT
>, then the
       connection procedure has failed; if it gives <CODE
CLASS="FUNCTION"
>CONNECTION_OK</CODE
>, then the
       connection is ready.  Both of these states are equally detectable
       from the return value of <CODE
CLASS="FUNCTION"
>PQconnectPoll</CODE
>, described above. Other states might also occur
       during (and only during) an asynchronous connection procedure. These
       indicate the current stage of the connection procedure and might be useful
       to provide feedback to the user for example. These statuses are:

       <P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="SYMBOL"
>CONNECTION_STARTED</TT
></DT
><DD
><P
>           Waiting for connection to be made.
          </P
></DD
><DT
><TT
CLASS="SYMBOL"
>CONNECTION_MADE</TT
></DT
><DD
><P
>           Connection OK; waiting to send.
          </P
></DD
><DT
><TT
CLASS="SYMBOL"
>CONNECTION_AWAITING_RESPONSE</TT
></DT
><DD
><P
>           Waiting for a response from the server.
          </P
></DD
><DT
><TT
CLASS="SYMBOL"
>CONNECTION_AUTH_OK</TT
></DT
><DD
><P
>           Received authentication; waiting for backend start-up to finish.
          </P
></DD
><DT
><TT
CLASS="SYMBOL"
>CONNECTION_SSL_STARTUP</TT
></DT
><DD
><P
>           Negotiating SSL encryption.
          </P
></DD
><DT
><TT
CLASS="SYMBOL"
>CONNECTION_SETENV</TT
></DT
><DD
><P
>           Negotiating environment-driven parameter settings.
          </P
></DD
></DL
></DIV
><P>

       Note that, although these constants will remain (in order to maintain
       compatibility), an application should never rely upon these occurring in a
       particular order, or at all, or on the status always being one of these
       documented values. An application might do something like this:
</P><PRE
CLASS="PROGRAMLISTING"
>switch(PQstatus(conn))
{
        case CONNECTION_STARTED:
            feedback = "Connecting...";
            break;

        case CONNECTION_MADE:
            feedback = "Connected to server...";
            break;
.
.
.
        default:
            feedback = "Connecting...";
}</PRE
><P>
      </P
><P
>       The <TT
CLASS="LITERAL"
>connect_timeout</TT
> connection parameter is ignored
       when using <CODE
CLASS="FUNCTION"
>PQconnectPoll</CODE
>; it is the application's
       responsibility to decide whether an excessive amount of time has elapsed.
       Otherwise, <CODE
CLASS="FUNCTION"
>PQconnectStart</CODE
> followed by a
       <CODE
CLASS="FUNCTION"
>PQconnectPoll</CODE
> loop is equivalent to
       <CODE
CLASS="FUNCTION"
>PQconnectdb</CODE
>.
      </P
><P
>       Note that if <CODE
CLASS="FUNCTION"
>PQconnectStart</CODE
> returns a non-null pointer, you must call
       <CODE
CLASS="FUNCTION"
>PQfinish</CODE
> when you are finished with it, in order to dispose of
       the structure and any associated memory blocks. This must be done even if
       the connection attempt fails or is abandoned.
      </P
></DD
><DT
><CODE
CLASS="FUNCTION"
>PQconndefaults</CODE
><A
NAME="AEN30563"
></A
></DT
><DD
><P
>       Returns the default connection options.
</P><PRE
CLASS="SYNOPSIS"
>PQconninfoOption *PQconndefaults(void);

typedef struct
{
    char   *keyword;   /* The keyword of the option */
    char   *envvar;    /* Fallback environment variable name */
    char   *compiled;  /* Fallback compiled in default value */
    char   *val;       /* Option's current value, or NULL */
    char   *label;     /* Label for field in connect dialog */
    char   *dispchar;  /* Character to display for this field
                          in a connect dialog. Values are:
                          ""        Display entered value as is
                          "*"       Password field - hide value
                          "D"       Debug option - don't show by default */
    int     dispsize;  /* Field size in characters for dialog */
} PQconninfoOption;</PRE
><P>
      </P
><P
>       Returns a connection options array.  This can be used to determine
       all possible <CODE
CLASS="FUNCTION"
>PQconnectdb</CODE
> options and their
       current default values.  The return value points to an array of
       <TT
CLASS="STRUCTNAME"
>PQconninfoOption</TT
> structures, which ends
       with an entry having a null <TT
CLASS="STRUCTFIELD"
>keyword</TT
> pointer.  The
       null pointer is returned if memory could not be allocated. Note that
       the current default values (<TT
CLASS="STRUCTFIELD"
>val</TT
> fields)
       will depend on environment variables and other context.  Callers
       must treat the connection options data as read-only.
      </P
><P
>       After processing the options array, free it by passing it to
       <CODE
CLASS="FUNCTION"
>PQconninfoFree</CODE
>.  If this is not done, a small amount of memory
       is leaked for each call to <CODE
CLASS="FUNCTION"
>PQconndefaults</CODE
>.
      </P
></DD
><DT
><CODE
CLASS="FUNCTION"
>PQfinish</CODE
><A
NAME="AEN30579"
></A
></DT
><DD
><P
>       Closes  the  connection to the server.  Also frees
       memory used by the <TT
CLASS="STRUCTNAME"
>PGconn</TT
> object.
       </P><PRE
CLASS="SYNOPSIS"
>        void PQfinish(PGconn *conn);
       </PRE
><P>
      </P
><P
>       Note that even if the server connection attempt fails (as
       indicated by <CODE
CLASS="FUNCTION"
>PQstatus</CODE
>), the application should call <CODE
CLASS="FUNCTION"
>PQfinish</CODE
>
       to free the memory used by the <TT
CLASS="STRUCTNAME"
>PGconn</TT
> object.
       The <TT
CLASS="STRUCTNAME"
>PGconn</TT
> pointer must not be used again after
       <CODE
CLASS="FUNCTION"
>PQfinish</CODE
> has been called.
      </P
></DD
><DT
><CODE
CLASS="FUNCTION"
>PQreset</CODE
><A
NAME="AEN30594"
></A
></DT
><DD
><P
>       Resets the communication channel to the server.
       </P><PRE
CLASS="SYNOPSIS"
>        void PQreset(PGconn *conn);
       </PRE
><P>
      </P
><P
>       This function will close the connection
       to the server and attempt to  reestablish  a  new
       connection to the same server, using all the same
       parameters previously used.  This might be useful for
       error recovery if a working connection is lost.
      </P
></DD
><DT
><CODE
CLASS="FUNCTION"
>PQresetStart</CODE
><A
NAME="AEN30603"
></A
><BR><CODE
CLASS="FUNCTION"
>PQresetPoll</CODE
><A
NAME="AEN30607"
></A
></DT
><DD
><P
>       Reset the communication channel to the server, in a nonblocking manner.

       </P><PRE
CLASS="SYNOPSIS"
>        int PQresetStart(PGconn *conn);
       </PRE
><P>
       </P><PRE
CLASS="SYNOPSIS"
>        PostgresPollingStatusType PQresetPoll(PGconn *conn);
       </PRE
><P>
      </P
><P
>       These functions will close the connection to the server and attempt to
       reestablish a new connection to the same server, using all the same
       parameters previously used. This can be useful for error recovery if a
       working connection is lost. They differ from <CODE
CLASS="FUNCTION"
>PQreset</CODE
> (above) in that they
       act in a nonblocking manner. These functions suffer from the same
       restrictions as <CODE
CLASS="FUNCTION"
>PQconnectStart</CODE
> and <CODE
CLASS="FUNCTION"
>PQconnectPoll</CODE
>.
      </P
><P
>       To initiate a connection reset, call
       <CODE
CLASS="FUNCTION"
>PQresetStart</CODE
>. If it returns 0, the reset has
       failed. If it returns 1, poll the reset using
       <CODE
CLASS="FUNCTION"
>PQresetPoll</CODE
> in exactly the same way as you
       would create the connection using <CODE
CLASS="FUNCTION"
>PQconnectPoll</CODE
>.
      </P
></DD
></DL
></DIV
><P>
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="libpq.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="libpq-status.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><SPAN
CLASS="APPLICATION"
>libpq</SPAN
> - C Library</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="libpq.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Connection Status Functions</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>