diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-01-01 18:43:02 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-01-01 18:43:02 +0000 |
commit | d4fed248bd153bb001d1da69604d18edf7fb9f24 (patch) | |
tree | 2294dd43ed272ed24ea1b9f89f5bba855d248a5f | |
parent | Add utility for creating a temporary mock database via the command line (diff) | |
download | libdbpp-d4fed248bd153bb001d1da69604d18edf7fb9f24.tar.bz2 libdbpp-d4fed248bd153bb001d1da69604d18edf7fb9f24.tar.xz libdbpp-d4fed248bd153bb001d1da69604d18edf7fb9f24.zip |
API change to pass command options through
-rw-r--r-- | libdbpp/command.h | 5 | ||||
-rw-r--r-- | libdbpp/connection.cpp | 12 | ||||
-rw-r--r-- | libdbpp/connection.h | 11 | ||||
-rw-r--r-- | libdbpp/unittests/mockdb.cpp | 6 | ||||
-rw-r--r-- | 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<SelectCommand> select(const std::string & sql); + virtual boost::shared_ptr<SelectCommand> 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<ModifyCommand> modify(const std::string & sql); + virtual boost::shared_ptr<ModifyCommand> 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<std::string> executed; }; |