From d4fed248bd153bb001d1da69604d18edf7fb9f24 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 1 Jan 2017 18:43:02 +0000 Subject: API change to pass command options through --- libdbpp/command.h | 5 +++++ libdbpp/connection.cpp | 12 ++++++------ libdbpp/connection.h | 11 ++++++----- libdbpp/unittests/mockdb.cpp | 6 +++--- libdbpp/unittests/mockdb.h | 6 +++--- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/libdbpp/command.h b/libdbpp/command.h index f8ca7f8..eaca8a9 100644 --- a/libdbpp/command.h +++ b/libdbpp/command.h @@ -21,6 +21,11 @@ namespace DB { ParameterOutOfRange(); }; + class DLL_PUBLIC CommandOptions { + public: + virtual ~CommandOptions() = default; + }; + /// Represents the basics of any command to be executed against a database. class DLL_PUBLIC Command { public: diff --git a/libdbpp/connection.cpp b/libdbpp/connection.cpp index 98fc89b..12a952e 100644 --- a/libdbpp/connection.cpp +++ b/libdbpp/connection.cpp @@ -29,22 +29,22 @@ DB::Connection::~Connection() } void -DB::Connection::execute(const std::string & sql) +DB::Connection::execute(const std::string & sql, const CommandOptions * opts) { - modify(sql)->execute(true); + modify(sql, opts)->execute(true); } DB::SelectCommandPtr -DB::Connection::select(const std::string & sql) +DB::Connection::select(const std::string & sql, const CommandOptions * opts) { - return DB::SelectCommandPtr(newSelectCommand(sql)); + return DB::SelectCommandPtr(newSelectCommand(sql, opts)); } DB::ModifyCommandPtr -DB::Connection::modify(const std::string & sql) +DB::Connection::modify(const std::string & sql, const CommandOptions * opts) { - return DB::ModifyCommandPtr(newModifyCommand(sql)); + return DB::ModifyCommandPtr(newModifyCommand(sql, opts)); } void diff --git a/libdbpp/connection.h b/libdbpp/connection.h index 5beb80f..4b75c18 100644 --- a/libdbpp/connection.h +++ b/libdbpp/connection.h @@ -16,6 +16,7 @@ namespace AdHoc { namespace DB { class Command; + class CommandOptions; class SelectCommand; class ModifyCommand; class TablePatch; @@ -110,19 +111,19 @@ namespace DB { /// @endcond /// Straight up execute a statement (no access to result set) - virtual void execute(const std::string & sql); + virtual void execute(const std::string & sql, const CommandOptions * = nullptr); /// Execute a script from a stream. /// @param f the script. /// @param s the location of the script. virtual void executeScript(std::istream & f, const boost::filesystem::path & s); /// Create a new select command with the given SQL. - virtual SelectCommand * newSelectCommand(const std::string & sql) = 0; + virtual SelectCommand * newSelectCommand(const std::string & sql, const CommandOptions * = nullptr) = 0; /// Create a new select command with the given SQL [smart pointer]. - virtual boost::shared_ptr select(const std::string & sql); + virtual boost::shared_ptr select(const std::string & sql, const CommandOptions * = nullptr); /// Create a new modify command with the given SQL. - virtual ModifyCommand * newModifyCommand(const std::string & sql) = 0; + virtual ModifyCommand * newModifyCommand(const std::string & sql, const CommandOptions * = nullptr) = 0; /// Create a new modify command with the given SQL [smart pointer]. - virtual boost::shared_ptr modify(const std::string & sql); + virtual boost::shared_ptr modify(const std::string & sql, const CommandOptions * = nullptr); /// Begin a bulk upload operation. /// @param table the target table. diff --git a/libdbpp/unittests/mockdb.cpp b/libdbpp/unittests/mockdb.cpp index 6ae6810..cf29e01 100644 --- a/libdbpp/unittests/mockdb.cpp +++ b/libdbpp/unittests/mockdb.cpp @@ -38,7 +38,7 @@ MockDb::bulkUpdateStyle() const } void -MockDb::execute(const std::string & sql) +MockDb::execute(const std::string & sql, const DB::CommandOptions *) { if (sql.substr(0, 3) == "Not") { throw DB::Error(); @@ -47,13 +47,13 @@ MockDb::execute(const std::string & sql) } DB::SelectCommand * -MockDb::newSelectCommand(const std::string &) +MockDb::newSelectCommand(const std::string &, const DB::CommandOptions *) { return nullptr; } DB::ModifyCommand * -MockDb::newModifyCommand(const std::string &) +MockDb::newModifyCommand(const std::string &, const DB::CommandOptions *) { return nullptr; } diff --git a/libdbpp/unittests/mockdb.h b/libdbpp/unittests/mockdb.h index cd6fb26..b67dfe4 100644 --- a/libdbpp/unittests/mockdb.h +++ b/libdbpp/unittests/mockdb.h @@ -15,9 +15,9 @@ class MockDb : public DB::Connection { DB::BulkDeleteStyle bulkDeleteStyle() const override; DB::BulkUpdateStyle bulkUpdateStyle() const override; - void execute(const std::string & sql) override; - DB::SelectCommand * newSelectCommand(const std::string &) override; - DB::ModifyCommand * newModifyCommand(const std::string &) override; + void execute(const std::string & sql, const DB::CommandOptions *) override; + DB::SelectCommand * newSelectCommand(const std::string &, const DB::CommandOptions *) override; + DB::ModifyCommand * newModifyCommand(const std::string &, const DB::CommandOptions *) override; mutable std::vector executed; }; -- cgit v1.2.3