diff options
-rw-r--r-- | odb/sqlite/statement.cxx | 79 | ||||
-rw-r--r-- | odb/sqlite/statement.hxx | 47 |
2 files changed, 91 insertions, 35 deletions
diff --git a/odb/sqlite/statement.cxx b/odb/sqlite/statement.cxx index e1f4fb6..8d5c94b 100644 --- a/odb/sqlite/statement.cxx +++ b/odb/sqlite/statement.cxx @@ -3,9 +3,6 @@ // copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file -#include <cstring> // std::memcpy -#include <cassert> - #include <odb/tracer.hxx> #include <odb/exceptions.hxx> // object_not_persistent @@ -31,13 +28,13 @@ namespace odb } void statement:: - init (const char* s, std::size_t n) + init (const char* text, std::size_t text_size) { int e; sqlite3_stmt* stmt (0); while ((e = sqlite3_prepare_v2 (conn_.handle (), - s, - static_cast<int> (n), + text, + static_cast<int> (text_size), &stmt, 0)) == SQLITE_LOCKED) { @@ -223,15 +220,24 @@ namespace odb // generic_statement:: - generic_statement (connection& conn, const string& s) - : statement (conn, s), + generic_statement (connection& conn, const string& text) + : statement (conn, text), result_set_ (stmt_ ? sqlite3_column_count (stmt_) != 0: false) { } generic_statement:: - generic_statement (connection& conn, const char* s, std::size_t n) - : statement (conn, s, n), + generic_statement (connection& conn, const char* text) + : statement (conn, text), + result_set_ (stmt_ ? sqlite3_column_count (stmt_) != 0: false) + { + } + + generic_statement:: + generic_statement (connection& conn, + const char* text, + std::size_t text_size) + : statement (conn, text, text_size), result_set_ (stmt_ ? sqlite3_column_count (stmt_) != 0: false) { } @@ -285,18 +291,31 @@ namespace odb select_statement:: select_statement (connection& conn, - const string& s, + const string& text, binding& param, binding& result) - : statement (conn, s), param_ (¶m), result_ (result) + : statement (conn, text), param_ (¶m), result_ (result) { } select_statement:: select_statement (connection& conn, - const string& s, + const char* text, + binding& param, binding& result) - : statement (conn, s), param_ (0), result_ (result) + : statement (conn, text), param_ (¶m), result_ (result) + { + } + + select_statement:: + select_statement (connection& conn, const string& text, binding& result) + : statement (conn, text), param_ (0), result_ (result) + { + } + + select_statement:: + select_statement (connection& conn, const char* text, binding& result) + : statement (conn, text), param_ (0), result_ (result) { } @@ -380,8 +399,14 @@ namespace odb // insert_statement:: - insert_statement (connection& conn, const string& s, binding& param) - : statement (conn, s), param_ (param) + insert_statement (connection& conn, const string& text, binding& param) + : statement (conn, text), param_ (param) + { + } + + insert_statement:: + insert_statement (connection& conn, const char* text, binding& param) + : statement (conn, text), param_ (param) { } @@ -438,10 +463,14 @@ namespace odb // update_statement:: - update_statement (connection& conn, - const string& s, - binding& param) - : statement (conn, s), param_ (param) + update_statement (connection& conn, const string& text, binding& param) + : statement (conn, text), param_ (param) + { + } + + update_statement:: + update_statement (connection& conn, const char* text, binding& param) + : statement (conn, text), param_ (param) { } @@ -482,8 +511,14 @@ namespace odb // delete_statement:: - delete_statement (connection& conn, const string& s, binding& param) - : statement (conn, s), param_ (param) + delete_statement (connection& conn, const string& text, binding& param) + : statement (conn, text), param_ (param) + { + } + + delete_statement:: + delete_statement (connection& conn, const char* text, binding& param) + : statement (conn, text), param_ (param) { } diff --git a/odb/sqlite/statement.hxx b/odb/sqlite/statement.hxx index 4f1e3fd..a9b11a0 100644 --- a/odb/sqlite/statement.hxx +++ b/odb/sqlite/statement.hxx @@ -11,7 +11,8 @@ #include <sqlite3.h> #include <string> -#include <cstddef> // std::size_t +#include <cstddef> // std::size_t +#include <cstring> // std::strlen, std::memcpy #include <cassert> #include <odb/forward.hxx> @@ -69,16 +70,22 @@ namespace odb } protected: - statement (connection& conn, const std::string& statement) + statement (connection& conn, const std::string& text) : conn_ (conn) { - init (statement.c_str (), statement.size () + 1); + init (text.c_str (), text.size ()); } - statement (connection& conn, const char* statement, std::size_t n) + statement (connection& conn, const char* text) : conn_ (conn) { - init (statement, n); + init (text, std::strlen (text)); + } + + statement (connection& conn, const char* text, std::size_t text_size) + : conn_ (conn) + { + init (text, text_size); } protected: @@ -146,7 +153,7 @@ namespace odb private: void - init (const char* statement, std::size_t n); + init (const char* text, std::size_t text_size); // Doubly-linked list of active/uncached statements. // @@ -193,8 +200,9 @@ namespace odb class LIBODB_SQLITE_EXPORT generic_statement: public statement { public: - generic_statement (connection&, const std::string& statement); - generic_statement (connection&, const char* statement, std::size_t n); + generic_statement (connection&, const std::string& text); + generic_statement (connection&, const char* text); + generic_statement (connection&, const char* text, std::size_t text_size); unsigned long long execute (); @@ -211,14 +219,21 @@ namespace odb { public: select_statement (connection& conn, - const std::string& statement, + const std::string& text, + binding& param, + binding& result); + + select_statement (connection& conn, + const char* text, binding& param, binding& result); select_statement (connection& conn, - const std::string& statement, + const std::string& text, binding& result); + select_statement (connection& conn, const char* text, binding& result); + // Common select interface expected by the generated code. // public: @@ -284,9 +299,11 @@ namespace odb { public: insert_statement (connection& conn, - const std::string& statement, + const std::string& text, binding& param); + insert_statement (connection& conn, const char* text, binding& param); + // Return true if successful and false if the row is a duplicate. // All other errors are reported by throwing exceptions. // @@ -308,9 +325,11 @@ namespace odb { public: update_statement (connection& conn, - const std::string& statement, + const std::string& text, binding& param); + update_statement (connection& conn, const char* text, binding& param); + unsigned long long execute (); @@ -326,9 +345,11 @@ namespace odb { public: delete_statement (connection& conn, - const std::string& statement, + const std::string& text, binding& param); + delete_statement (connection& conn, const char* text, binding& param); + unsigned long long execute (); |