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 | 5694c0a4529334756f2b914ad67408df199551dc (patch) | |
tree | 38daa2e27d6049ca7a808af642eb82a29c9d2886 /odb/sqlite/connection.cxx | |
parent | 1bf4678c29b6e51396c18582b270254d1bd2cddc (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/sqlite/connection.cxx')
-rw-r--r-- | odb/sqlite/connection.cxx | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/odb/sqlite/connection.cxx b/odb/sqlite/connection.cxx index 91b430a..d90c301 100644 --- a/odb/sqlite/connection.cxx +++ b/odb/sqlite/connection.cxx @@ -11,6 +11,7 @@ #include <odb/sqlite/database.hxx> #include <odb/sqlite/connection.hxx> +#include <odb/sqlite/transaction.hxx> #include <odb/sqlite/statement.hxx> #include <odb/sqlite/statement-cache.hxx> #include <odb/sqlite/error.hxx> @@ -38,7 +39,10 @@ namespace odb connection:: connection (database_type& db, int extra_flags) - : db_ (db), unlock_cond_ (unlock_mutex_), statements_ (0) + : odb::connection (db), + db_ (db), + unlock_cond_ (unlock_mutex_), + statements_ (0) { int f (db.flags () | extra_flags); const string& n (db.name ()); @@ -65,6 +69,43 @@ namespace odb statement_cache_.reset (new statement_cache_type (*this)); } + transaction_impl* connection:: + begin () + { + if (transaction::has_current ()) + throw already_in_transaction (); + + return new transaction_impl ( + connection_ptr (inc_ref (this)), transaction_impl::deferred); + } + + transaction_impl* connection:: + begin_immediate () + { + if (transaction::has_current ()) + throw already_in_transaction (); + + return new transaction_impl ( + connection_ptr (inc_ref (this)), transaction_impl::immediate); + } + + transaction_impl* connection:: + begin_exclusive () + { + if (transaction::has_current ()) + throw already_in_transaction (); + + return new transaction_impl ( + connection_ptr (inc_ref (this)), transaction_impl::exclusive); + } + + unsigned long long connection:: + execute (const char* s, std::size_t n) + { + simple_statement st (*this, s, n); + return st.execute (); + } + inline void connection_unlock_callback (void** args, int n) { |