From 5694c0a4529334756f2b914ad67408df199551dc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 21 Aug 2011 16:27:34 +0200 Subject: 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. --- odb/sqlite/connection.cxx | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'odb/sqlite/connection.cxx') 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 #include +#include #include #include #include @@ -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) { -- cgit v1.1