Skip to content

Commit

Permalink
Document connection_parameters class.
Browse files Browse the repository at this point in the history
Document the new session ctor taking connection_parameters and the class
itself in the references page.
  • Loading branch information
vadz committed Mar 9, 2013
1 parent 4081c57 commit 4212775
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
4 changes: 2 additions & 2 deletions doc/backends/odbc.html
Expand Up @@ -274,11 +274,11 @@ <h4 id="get_connection_string">get_connection_string()</h4>

<h3 id="options">Configuration options</h3>

<p>This backend supports <code>ODBC_OPTION_DRIVER_COMPLETE</code> option which can be passed to it via <code>connection_parameters</code> class. The value of this option is passed to <code>SQLDriverConnect()</code> function as "driver completion" parameter and so must be one of <code>SQL_DRIVER_XXX</code> values, in the string form. The default value of this option is <code>SQL_DRIVER_PROMPT</code> meaning that the driver will query the user for the user name and/or the password if they are not stored together with the connection. If this is undesirable for some reason, you can use <code>SQL_DRIVER_NOPROMPT</code> value for this option to suppress showing the message box:</p>
<p>This backend supports <code>odbc_option_driver_complete</code> option which can be passed to it via <code>connection_parameters</code> class. The value of this option is passed to <code>SQLDriverConnect()</code> function as "driver completion" parameter and so must be one of <code>SQL_DRIVER_XXX</code> values, in the string form. The default value of this option is <code>SQL_DRIVER_PROMPT</code> meaning that the driver will query the user for the user name and/or the password if they are not stored together with the connection. If this is undesirable for some reason, you can use <code>SQL_DRIVER_NOPROMPT</code> value for this option to suppress showing the message box:</p>

<pre class="example">
connection_parameters parameters("odbc", "DSN=mydb");
parameters.set_option(ODBC_OPTION_DRIVER_COMPLETE, "0" /* SQL_DRIVER_NOPROMPT */);
parameters.set_option(odbc_option_driver_complete, "0" /* SQL_DRIVER_NOPROMPT */);
session sql(parameters);
</pre>

Expand Down
12 changes: 12 additions & 0 deletions doc/connections.html
Expand Up @@ -54,6 +54,14 @@ <h3>Connecting to the database</h3>

<p>The last two constructors described above try to locate the shared library with the name <code>libsoci_ABC.so</code> (or <code>libsoci_ABC.dll</code> on Windows), where ABC is the backend name. In the above examples, the expected library name will be <code>libsoci_postgresql.so</code> for Unix-like systems.</p>

<p>The most general form of the constructor takes a single object of <code>connection_parameters</code> type which contains a pointer to the backend to use, the connection string and also any connection options. Using this constructor is the only way to pass any non-default options to the backend. For example, to suppress any interactive prompts when using ODBC backend you could do:</p>
<pre class="example">
connection_parameters parameters("odbc", "DSN=mydb");
parameters.set_option(odbc_option_driver_complete, "0" /* SQL_DRIVER_NOPROMPT */);
session sql(parameters);
</pre>
Notice that you need to <code>#include &lt;soci-odbc.h&gt;</code> to obtain the option name declaration. The existing options are described in the backend-specific part of the documentation.

<div class="note">
<p><span class="note">Environment configuration:</span></p>
<p>The <code>SOCI_BACKENDS_PATH</code> environment variable defines the set of paths where the shared libraries will be searched for. There can be many paths, separated by colons, and they are used from left to right until the library with the appropriate name is found. If this variable is not set or is empty, the current directory is used as a default path for dynamically loaded backends.</p>
Expand Down Expand Up @@ -86,6 +94,10 @@ <h3>Connecting to the database</h3>

// or:
sql.open("postgresql://dbname=mydb");

// or also:
connection_parameters parameters("postgresql", "dbname=mydb");
sql.open(parameters);
</pre>

<p>The rules for backend naming are the same as with the constructors described above.</p>
Expand Down
39 changes: 38 additions & 1 deletion doc/reference.html
Expand Up @@ -14,6 +14,7 @@ <h2>Client interface reference</h2>
<div class="navigation">
<a href="#commontypes">commonly used types</a><br />
<a href="#session">class session</a><br />
<a href="#parameters">class connection_parameters</a><br />
<a href="#pool">class connection_pool</a><br />
<a href="#transaction">class transaction</a><br />
<a href="#into">function into</a><br />
Expand Down Expand Up @@ -75,6 +76,7 @@ <h3 id="session">class session</h3>
{
public:
session();
explicit session(connection_parameters const &amp; parameters);
session(backend_factory const &amp; factory, std::string const &amp; connectString);
session(std::string const &amp; backendName, std::string const &amp; connectString);
explicit session(std::string const &amp; connectString);
Expand Down Expand Up @@ -121,7 +123,9 @@ <h3 id="session">class session</h3>
<ul>
<li>Various constructors. The default one creates the session in the disconnected state.
The others expect the backend factory object, or the backend name, or the URL-like
composed connection string. The last constructor creates a session proxy associated
composed connection string or the special parameters object containing both the backend
and the connection string as well as possibly other connection options.
The last constructor creates a session proxy associated
with the session that is available in the given pool and releases it back to the pool
when its lifetime ends. Example:
<pre class="example">
Expand Down Expand Up @@ -198,6 +202,39 @@ <h3 id="session">class session</h3>
<p>See <a href="basics.html">Connections and simple queries</a> for more
examples.</p>

<h3 id="parameters">class connection_parameters</h3>

<p>The <code>connection_parameters</code> class is a simple container for the backend pointer, connection string and any other connection options. It is used together with <code>session</code> constructor and <code>open()</code> method.</p>

<pre class="example">
class connection_parameters
{
public:
connection_parameters();
connection_parameters(backend_factory const &amp; factory, std::string const &amp; connectString);
connection_parameters(std::string const &amp; backendName, std::string const &amp; connectString);
explicit connection_parameters(std::string const &amp; fullConnectString);

void set_option(const char * name, std::string const &amp; value);
bool get_option(const char * name, std::string &amp; value) const
};
</pre>

<p>The methods of this class are:</p>
<ul>
<li>Default constructor is rarely used as it creates an uninitialized
object and the only way to initialize it later is to assign another, valid,
connection_parameters object to this one.</li>
<li>The other constructors correspond to the similar constructors of the
<code>session</code> class and specify both the backend, either as a
pointer to it or by name, and the connection string.</li>
<li><code>set_option</code> can be used to set the value of an option with
the given name. Currently all option values are strings, so if you need to
set a numeric option you need to convert it to a string first. If an option
with the given name had been already set before, its old value is
overwritten.</li>
</ul>

<h3 id="pool">class connection_pool</h3>

<p>The <code>connection_pool</code> class encapsulates the thread-safe pool of connections
Expand Down

0 comments on commit 4212775

Please sign in to comment.