From fa3f14db14671b4c37c400880d097b17aa12b824 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 29 Apr 2021 11:55:45 +0200 Subject: Move begin/commit/rollback statements to connection --- odb/sqlite/connection.cxx | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'odb/sqlite/connection.cxx') diff --git a/odb/sqlite/connection.cxx b/odb/sqlite/connection.cxx index cdd4c20..57ce860 100644 --- a/odb/sqlite/connection.cxx +++ b/odb/sqlite/connection.cxx @@ -25,6 +25,8 @@ odb_sqlite_connection_unlock_callback (void**, int); namespace odb { + using namespace details; + namespace sqlite { connection:: @@ -105,6 +107,12 @@ namespace odb db.foreign_keys () ? 22 : 23); st.execute (); + // String lengths include '\0', as per the SQLite manual suggestion. + // + begin_.reset (new (shared) generic_statement (*this, "BEGIN", 6)); + commit_.reset (new (shared) generic_statement (*this, "COMMIT", 7)); + rollback_.reset (new (shared) generic_statement (*this, "ROLLBACK", 9)); + // Create statement cache. // statement_cache_.reset (new statement_cache_type (*this)); @@ -119,6 +127,44 @@ namespace odb clear_prepared_map (); } + generic_statement& connection:: + begin_statement () + { + return static_cast (*begin_); + } + + generic_statement& connection:: + begin_immediate_statement () + { + if (!begin_immediate_) + begin_immediate_.reset ( + new (shared) generic_statement (*this, "BEGIN IMMEDIATE", 16)); + + return static_cast (*begin_immediate_); + } + + generic_statement& connection:: + begin_exclusive_statement () + { + if (!begin_exclusive_) + begin_exclusive_.reset ( + new (shared) generic_statement (*this, "BEGIN EXCLUSIVE", 16)); + + return static_cast (*begin_exclusive_); + } + + generic_statement& connection:: + commit_statement () + { + return static_cast (*commit_); + } + + generic_statement& connection:: + rollback_statement () + { + return static_cast (*rollback_); + } + transaction_impl* connection:: begin () { -- cgit v1.1