diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-08-21 16:27:34 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-08-21 16:27:34 +0200 |
commit | e84fa8e3b8defe24a00e14ba046e8e71b438ce0b (patch) | |
tree | 2d17fab73f0bbb1a96f365e38ecbd63e033af36f /odb/mysql/database.cxx | |
parent | 47d344f31f7a1a980d807c142e0a36b09db3b1f3 (diff) |
Add odb::connection class
This abstract class represents a connection to the database. One can
use it to start a transaction or to execute a native statement out
of a transaction.
Before we had concrete connection classes in the database runtime
libraries (e.g., odb::mysql::connection). Now these classes derive
from odb::connection.
Diffstat (limited to 'odb/mysql/database.cxx')
-rw-r--r-- | odb/mysql/database.cxx | 48 |
1 files changed, 4 insertions, 44 deletions
diff --git a/odb/mysql/database.cxx b/odb/mysql/database.cxx index 31d6c7b..dc78bce 100644 --- a/odb/mysql/database.cxx +++ b/odb/mysql/database.cxx @@ -5,12 +5,9 @@ #include <sstream> -#include <odb/mysql/mysql.hxx> #include <odb/mysql/database.hxx> -#include <odb/mysql/transaction.hxx> #include <odb/mysql/connection.hxx> #include <odb/mysql/connection-factory.hxx> -#include <odb/mysql/error.hxx> #include <odb/mysql/exceptions.hxx> #include <odb/mysql/details/options.hxx> @@ -211,48 +208,11 @@ namespace odb details::options::print_usage (os); } - unsigned long long database:: - execute (const char* s, std::size_t n) + odb::connection* database:: + connection_ () { - if (!transaction::has_current ()) - throw not_in_transaction (); - - connection_type& c (transaction::current ().connection ()); - c.clear (); - - MYSQL* h (c.handle ()); - - if (mysql_real_query (h, s, static_cast<unsigned long> (n))) - translate_error (c); - - // Get the affected row count, if any. If the statement has a result - // set (e.g., SELECT), we first need to call mysql_store_result(). - // - unsigned long long r (0); - - if (mysql_field_count (h) == 0) - r = static_cast<unsigned long long> (mysql_affected_rows (h)); - else - { - if (MYSQL_RES* rs = mysql_store_result (h)) - { - r = static_cast<unsigned long long> (mysql_num_rows (rs)); - mysql_free_result (rs); - } - else - translate_error (c); - } - - return r; - } - - transaction_impl* database:: - begin () - { - if (transaction::has_current ()) - throw already_in_transaction (); - - return new transaction_impl (*this); + connection_ptr c (factory_->connect ()); + return c.release (); } } } |