Skip to content

Commit

Permalink
Update code samples according to current API (#85)
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
mloskot committed Mar 8, 2013
1 parent b87d8fb commit e01d834
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 117 deletions.
75 changes: 45 additions & 30 deletions doc/backends.html
Expand Up @@ -104,14 +104,13 @@ <h2>Backends reference</h2>
class standard_into_type_backend
{
public:
standard_into_type_backend() {}
virtual ~standard_into_type_backend() {}

virtual void define_by_pos(int &amp; position,
void * data, exchange_type type) = 0;
virtual void define_by_pos(int&amp; position, void* data, exchange_type type) = 0;

virtual void pre_fetch() = 0;
virtual void post_fetch(bool gotData, bool calledFromFetch,
indicator * ind) = 0;
virtual void post_fetch(bool gotData, bool calledFromFetch, indicator* ind) = 0;

virtual void clean_up() = 0;
};
Expand Down Expand Up @@ -160,13 +159,13 @@ <h2>Backends reference</h2>
class vector_into_type_backend
{
public:
vector_into_type_backend() {}
virtual ~vector_into_type_backend() {}

virtual void define_by_pos(int &amp; position,
void * data, exchange_type type) = 0;
virtual void define_by_pos(int&amp; position, void* data, exchange_type type) = 0;

virtual void pre_fetch() = 0;
virtual void post_fetch(bool gotData, indicator * ind) = 0;
virtual void post_fetch(bool gotData, indicator* ind) = 0;

virtual void resize(std::size_t sz) = 0;
virtual std::size_t size() = 0;
Expand Down Expand Up @@ -194,13 +193,13 @@ <h2>Backends reference</h2>
public:
virtual ~standard_use_type_backend() {}

virtual void bind_by_pos(int &amp; position,
void * data, exchange_type type, bool readOnly) = 0;
virtual void bind_by_name(std::string const &amp; name,
void * data, exchange_type type, bool readOnly) = 0;
virtual void bind_by_pos(int&amp; position,
void* data, exchange_type type, bool readOnly) = 0;
virtual void bind_by_name(std::string const&amp; name,
void* data, exchange_type type, bool readOnly) = 0;

virtual void pre_use(indicator const * ind) = 0;
virtual void post_use(bool gotData, indicator * ind) = 0;
virtual void pre_use(indicator const* ind) = 0;
virtual void post_use(bool gotData, indicator* ind) = 0;

virtual void clean_up() = 0;
};
Expand Down Expand Up @@ -236,12 +235,12 @@ <h2>Backends reference</h2>
public:
virtual ~vector_use_type_backend() {}

virtual void bind_by_pos(int &amp; position,
void * data, exchange_type type) = 0;
virtual void bind_by_name(std::string const &amp; name,
void * data, exchange_type type) = 0;
virtual void bind_by_pos(int&amp; position,
void* data, exchange_type type) = 0;
virtual void bind_by_name(std::string const&amp; name,
void* data, exchange_type type) = 0;

virtual void pre_use(indicator const * ind) = 0;
virtual void pre_use(indicator const* ind) = 0;

virtual std::size_t size() = 0;

Expand All @@ -262,29 +261,36 @@ <h2>Backends reference</h2>
class statement_backend
{
public:
statement_backend() {}
virtual ~statement_backend() {}

virtual void alloc() = 0;
virtual void clean_up() = 0;

virtual void prepare(std::string const &amp; query, statement_type eType) = 0;
virtual void prepare(std::string const&amp; query, statement_type eType) = 0;

enum exec_fetch_result
{
ef_success,
ef_no_data
};

enum exec_fetch_result { ef_success, ef_no_data };
virtual exec_fetch_result execute(int number) = 0;
virtual exec_fetch_result fetch(int number) = 0;

virtual long long get_affected_rows() = 0;
virtual int get_number_of_rows() = 0;

virtual std::string rewrite_for_procedure_call(std::string const &amp; query) = 0;
virtual std::string rewrite_for_procedure_call(std::string const&amp; query) = 0;

virtual int prepare_for_describe() = 0;
virtual void describe_column(int colNum, data_type &amp; dtype,
std::string &amp; column_name) = 0;
virtual void describe_column(int colNum, data_type&amp; dtype,
std::string&amp; column_name) = 0;

virtual standard_into_type_backend * make_into_type_backend() = 0;
virtual standard_use_type_backend * make_use_type_backend() = 0;
virtual vector_into_type_backend * make_vector_into_type_backend() = 0;
virtual vector_use_type_backend * make_vector_use_type_backend() = 0;
virtual standard_into_type_backend* make_into_type_backend() = 0;
virtual standard_use_type_backend* make_use_type_backend() = 0;
virtual vector_into_type_backend* make_vector_into_type_backend() = 0;
virtual vector_use_type_backend* make_vector_use_type_backend() = 0;
};
</pre>

Expand All @@ -307,6 +313,8 @@ <h2>Backends reference</h2>
<li><code>fetch</code> - Called to fetch next bunch of rows; number
is positive and determines the requested number of rows (more than 1 is
used only for bulk operations).</li>
<li><code>get_affected_rows</code> - Called to determine the actual
number of rows affected by data modifying statement.</li>
<li><code>get_number_of_rows</code> - Called to determine the actual
number of rows retrieved by the previous call to <code>execute</code>
or <code>fetch</code>.</li>
Expand Down Expand Up @@ -383,6 +391,9 @@ <h2>Backends reference</h2>
virtual void commit() = 0;
virtual void rollback() = 0;

virtual bool get_next_sequence_value(session&amp;, std::string const&amp;, long&amp;);
virtual bool get_last_insert_id(session&amp;, std::string const&amp;, long&amp;);

virtual std::string get_backend_name() const = 0;

virtual statement_backend * make_statement_backend() = 0;
Expand All @@ -397,6 +408,10 @@ <h2>Backends reference</h2>
<li><code>begin</code>, <code>commit</code>, <code>rollback</code>
- Forward-called when the same functions of <code>session</code> are
called by user.</li>
<li><code>get_next_sequence_value</code>, <code>get_last_insert_id</code>
- Called to retrieve sequences or auto-generated values and every backend should
define at least one of them to allow the code using auto-generated values to work.
</li>
<li><code>make_statement_backend</code>, <code>make_rowid_backend</code>,
<code>make_blob_backend</code> - Called to create respective
implementations for the <code>statement</code>, <code>rowid</code>
Expand All @@ -410,7 +425,7 @@ <h2>Backends reference</h2>
virtual ~backend_factory() {}

virtual details::session_backend * make_session(
std::string const &amp; connectString) const = 0;
std::string const&amp; connectString) const = 0;
};
</pre>

Expand All @@ -432,8 +447,8 @@ <h2>Backends reference</h2>
<pre class="example">
struct postgresql_backend_factory : backend_factory
{
virtual postgresql_session_backend * make_session(
std::string const &amp; connectString) const;
virtual postgresql_session_backend* make_session(
std::string const&amp; connectString) const;
};

extern postgresql_backend_factory const postgresql;
Expand Down
116 changes: 61 additions & 55 deletions doc/backends/odbc.html
Expand Up @@ -34,7 +34,7 @@ <h2>ODBC Backend Reference</h2>
<a href="#native">Accessing the Native Database API</a><br />
<a href="#extensions">Backend-specific Extensions</a><br />
<div class="navigation-indented">
<a href="#odbc_soci_error">ODBCSOCIError</a><br />
<a href="#odbc_soci_error">odbc_soci_error</a><br />
</div>
<a href="#options">Configuration options</a><br />
</div>
Expand All @@ -49,9 +49,13 @@ <h4 id="tested">Tested Platforms</h4>
<table border="1" cellpadding="5" cellspacing="0">
<tbody>
<tr><th>ODBC version</th><th>Operating System</th><th>Compiler</th></tr>
<tr><td>3</td><td>Linux (Ubuntu 12.04)</td><td>g++ 4.6.3</td></tr>
<tr><td>3</td><td>Linux (Ubuntu 12.04)</td><td>clang 3.2</td></tr>
<tr><td>3.8</td><td>Windows 8</td><td>Visual Studio 2012</td></tr>
<tr><td>3</td><td>Windows 7</td><td>Visual Studio 2010</td></tr>
<tr><td>3</td><td>Windows XP</td><td>Visual Studio 2005 (express)</td></tr>
<tr><td>3</td><td>Windows XP</td><td>Visual C++ 8.0 Professional</td></tr>
<tr><td>3</td><td>Windows XP</td><td>(cygwin) g++ 3.3.4</td></tr>
<tr><td>3</td><td>Windows XP</td><td>g++ 3.3.4 (Cygwin)</td></tr>
</tbody>
</table>

Expand All @@ -65,76 +69,76 @@ <h4 id="connecting">Connecting to the Database</h4>
using the <code>ODBC</code> backend factory together with a connection string:</p>

<pre class="example">
BackEndFactory const &amp;backEnd = odbc;
Session sql(backEnd, "filedsn=c:\\my.dsn");
backend_factory const&amp; backEnd = odbc;
session sql(backEnd, "filedsn=c:\\my.dsn");
</pre>

<p>or simply:</p>

<pre class="example">
Session sql(odbc, "filedsn=c:\\my.dsn");
session sql(odbc, "filedsn=c:\\my.dsn");
</pre>

<p>The set of parameters used in the connection string for ODBC is the same as accepted by the <code><a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbcsql/od_odbc_d_4x4k.asp">SQLDriverConnect</a></code> function from the ODBC library.</p>

<p>Once you have created a <code>Session</code> object as shown above, you can use it to access the database, for example:</p>
<p>Once you have created a <code>session</code> object as shown above, you can use it to access the database, for example:</p>
<pre class="example">
int count;
sql &lt;&lt; "select count(*) from invoices", into(count);
</pre>

<p>(See the <a href="../basics.html">SOCI basics</a> and <a href="../exchange.html">exchanging data</a> documentation for general information on using the <code>Session</code> class.)</p>
<p>(See the <a href="../basics.html">SOCI basics</a> and <a href="../exchange.html">exchanging data</a> documentation for general information on using the <code>session</code> class.)</p>

<h3 id="support">SOCI Feature Support</h3>
<h4 id="dynamic">Dynamic Binding</h4>

<p>The ODBC backend supports the use of the SOCI <code>Row</code> class, which facilitates retrieval of data whose type is not known at compile time.</p>
<p>The ODBC backend supports the use of the SOCI <code>row</code> class, which facilitates retrieval of data whose type is not known at compile time.</p>

<p>When calling <code>Row::get&lt;T&gt;()</code>, the type you should pass as T depends upon the underlying database type.<br/> For the ODBC backend, this type mapping is:</p>
<p>When calling <code>row::get&lt;T&gt;()</code>, the type you should pass as T depends upon the underlying database type.<br/> For the ODBC backend, this type mapping is:</p>

<table border="1" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<th>ODBC Data Type</th>
<th>SOCI Data Type</th>
<th><code>Row::get&lt;T&gt;</code> specializations</th>
<th><code>row::get&lt;T&gt;</code> specializations</th>
</tr>
<tr>
<td>SQL_DOUBLE
, SQL_DECIMAL
, SQL_REAL
, SQL_FLOAT
, SQL_NUMERIC
</td>
<td><code>eDouble</code></td>
, SQL_DECIMAL
, SQL_REAL
, SQL_FLOAT
, SQL_NUMERIC
</td>
<td><code>dt_double</code></td>
<td><code>double</code></td>
</tr>
<tr>
<td>SQL_TINYINT
, SQL_SMALLINT
, SQL_INTEGER
, SQL_BIGINT</td>
<td><code>eInteger</code></td>
, SQL_SMALLINT
, SQL_INTEGER
, SQL_BIGINT</td>
<td><code>dt_integer</code></td>
<td><code>int</code></td>
</tr>
<tr>
<td>SQL_CHAR, SQL_VARCHAR</td>
<td><code>eString</code></td>
<td><code>dt_string</code></td>
<td><code>std::string</code></td>
</tr>
<tr>
<td>SQL_TYPE_DATE
, SQL_TYPE_TIME
, SQL_TYPE_TIMESTAMP</td>
<td><code>eDate</code></td>
, SQL_TYPE_TIME
, SQL_TYPE_TIMESTAMP</td>
<td><code>dt_date</code></td>
<td><code>std::tm</code><code></code></td>
</tr>
</tbody>
</table>

<p>Not all ODBC drivers support all datatypes</p>

<p>(See the <a href="../exchange.html#dynamic">dynamic resultset binding</a> documentation for general information on using the <code>Row</code> class.)</p>
<p>(See the <a href="../exchange.html#dynamic">dynamic resultset binding</a> documentation for general information on using the <code>row</code> class.)</p>

<h4 id="bindingbyname">Binding by Name</h4>

Expand Down Expand Up @@ -165,25 +169,25 @@ <h4 id="bulk">Bulk Operations</h4>
<th>Bulk Insert</th>
</tr>
<tr>
<td>MS SQL Server 2005</td>
<td>YES</td>
<td>YES</td>
</tr>
<td>MS SQL Server 2005</td>
<td>YES</td>
<td>YES</td>
</tr>
<tr>
<td>MS Access 2003</td>
<td>YES</td>
<td>NO</td>
</tr>
<td>MS Access 2003</td>
<td>YES</td>
<td>NO</td>
</tr>
<tr>
<td>PostgresQL 8.1</td>
<td>YES</td>
<td>YES</td>
</tr>
<td>PostgresQL 8.1</td>
<td>YES</td>
<td>YES</td>
</tr>
<tr>
<td>MySQL 4.1</td>
<td>NO</td>
<td>NO</td>
</tr>
<td>MySQL 4.1</td>
<td>NO</td>
<td>NO</td>
</tr>
</tbody>
</table>

Expand Down Expand Up @@ -220,27 +224,28 @@ <h3 id="native">Acessing the native database API</h3>
<th>Concrete Class</th>
</tr>
<tr>
<td><code>SessionBackEnd* Session::getBackEnd()</code></td>
<td><code>ODBCSessionBackEnd</code></td>
<td><code>session_backend* session::get_backend()</code></td>
<td><code>odbc_statement_backend</code></td>
</tr>
<tr>
<td><code>StatementBackEnd* Statement::getBackEnd()</code></td>
<td><code>ODBCStatementBackEnd</code></td>
<td><code>statement_backend* statement::get_backend()</code></td>
<td><code>odbc_statement_backend</code></td>
</tr>
<tr>
<td><code>RowIDBackEnd* RowID::getBackEnd()</code></td>
<td><code>ODBCRowIDBackEnd</code></td>
<td><code>rowid_backend* rowid::get_backend()</code></td>
<td><code>odbc_rowid_backend</code></td>
</tr>
</tbody>
</table>


<h3 id="extensions">Backend-specific extensions</h3>
<h4 id="odbc_soci_error">ODBCSOCIError</h4>
<h4 id="odbc_soci_error">odbc_soci_error</h4>

<p>The ODBC backend can throw instances of class <code>ODBCSOCIError</code>,
which is publicly derived from <code>SOCIError</code> and has
additional public members containing the ODBC error code, the Native database error code, and the message returned from ODBC:</p>
<p>The ODBC backend can throw instances of class <code>odbc_soci_error</code>,
which is publicly derived from <code>soci_error</code> and has
additional public members containing the ODBC error code, the Native database
error code, and the message returned from ODBC:</p>

<pre class="example">
int main()
Expand All @@ -249,12 +254,12 @@ <h4 id="odbc_soci_error">ODBCSOCIError</h4>
{
// regular code
}
catch (SOCI::ODBCSOCIError const &amp; e)
catch (soci::odbc_soci_error const&amp; e)
{
cerr &lt;&lt; "ODBC Error Code: " &lt;&lt; e.odbcErrorCode() &lt;&lt; endl
&lt;&lt; "Native Error Code: " &lt;&lt; e.nativeErrorCode() &lt;&lt; endl
cerr &lt;&lt; "ODBC Error Code: " &lt;&lt; e.odbc_error_code() &lt;&lt; endl
&lt;&lt; "Native Error Code: " &lt;&lt; e.native_error_code() &lt;&lt; endl
&lt;&lt; "SOCI Message: " &lt;&lt; e.what() &lt;&lt; std::endl
&lt;&lt; "ODBC Message: " &lt;&lt; e.odbcErrorMessage() &lt;&lt; endl;
&lt;&lt; "ODBC Message: " &lt;&lt; e.odbc_error_message() &lt;&lt; endl;
}
catch (exception const &amp;e)
{
Expand All @@ -271,6 +276,7 @@ <h3 id="options">Configuration options</h3>

<p>None</p>

<p class="copyright">Copyright &copy; 2013 Mateusz Loskot</p>
<p class="copyright">Copyright &copy; 2004-2006 Maciej Sobczak, Stephen Hutton, David Courtney</p>
</body>
</html>

0 comments on commit e01d834

Please sign in to comment.