diff options
-rw-r--r-- | libdbpp/command.cpp | 8 | ||||
-rw-r--r-- | libdbpp/command.h | 6 | ||||
-rw-r--r-- | libdbpp/unittests/Jamfile.jam | 1 | ||||
-rw-r--r-- | libdbpp/unittests/testConnection.cpp | 19 |
4 files changed, 32 insertions, 2 deletions
diff --git a/libdbpp/command.cpp b/libdbpp/command.cpp index c6d7a7c..a687ccc 100644 --- a/libdbpp/command.cpp +++ b/libdbpp/command.cpp @@ -1,4 +1,10 @@ #include "command.h" +#include "connection.h" +#include <factory.impl.h> + +INSTANTIATEFACTORY(DB::CommandOptions, std::size_t, const DB::CommandOptionsMap &); +NAMEDFACTORY("", DB::CommandOptions, DB::CommandOptionsFactory); +PLUGINRESOLVER(DB::CommandOptions, DB::Connection::resolvePlugin); DB::Command::Command(const std::string & s) : sql(s) @@ -17,7 +23,7 @@ DB::ParameterOutOfRange::ParameterOutOfRange() { } -DB::CommandOptions::CommandOptions(std::size_t h) : +DB::CommandOptions::CommandOptions(std::size_t h, const CommandOptionsMap &) : hash(h) { } diff --git a/libdbpp/command.h b/libdbpp/command.h index 2a7f9ae..aaadfa9 100644 --- a/libdbpp/command.h +++ b/libdbpp/command.h @@ -5,6 +5,7 @@ #include <boost/date_time/posix_time/posix_time_types.hpp> #include <boost/shared_ptr.hpp> #include <visibility.h> +#include <factory.h> #include <type_traits> #include "error.h" @@ -21,12 +22,14 @@ namespace DB { ParameterOutOfRange(); }; + typedef std::map<std::string, std::string> CommandOptionsMap; + /// Represents the basic options that can be passed when creating new commands. class DLL_PUBLIC CommandOptions { public: CommandOptions() = default; /// Constructor which populates the hash value only. - CommandOptions(std::size_t hash); + CommandOptions(std::size_t hash, const CommandOptionsMap & = CommandOptionsMap()); virtual ~CommandOptions() = default; /// An (optional) hash of the SQL statement. @@ -103,6 +106,7 @@ namespace DB { void bindParamS(unsigned int, char * const); }; typedef boost::shared_ptr<Command> CommandPtr; + typedef AdHoc::Factory<CommandOptions, std::size_t, const CommandOptionsMap &> CommandOptionsFactory; } #endif diff --git a/libdbpp/unittests/Jamfile.jam b/libdbpp/unittests/Jamfile.jam index 54c4afc..5aec066 100644 --- a/libdbpp/unittests/Jamfile.jam +++ b/libdbpp/unittests/Jamfile.jam @@ -16,6 +16,7 @@ run <library>..//dbppcore <library>..//adhocutil <library>boost_utf + <library>dbpp-local-postgresql <dependency>parseTest.sql <dependency>unterminatedComment.sql <dependency>unterminatedString.sql diff --git a/libdbpp/unittests/testConnection.cpp b/libdbpp/unittests/testConnection.cpp index f1df3b0..a1ab9f6 100644 --- a/libdbpp/unittests/testConnection.cpp +++ b/libdbpp/unittests/testConnection.cpp @@ -3,6 +3,7 @@ #include <factory.h> #include <connection.h> +#include <pq-command.h> #include <definedDirs.h> #include <fstream> #include <vector> @@ -162,3 +163,21 @@ BOOST_AUTO_TEST_CASE( savepoints ) delete mock; } +BOOST_AUTO_TEST_CASE( commandOptions ) +{ + auto optsDefault = DB::CommandOptionsFactory::createNew("", 1234, {}); + BOOST_REQUIRE(optsDefault); + BOOST_REQUIRE(optsDefault->hash); + BOOST_REQUIRE_EQUAL(1234, *optsDefault->hash); +} + +BOOST_AUTO_TEST_CASE( commandOptionsPq ) +{ + auto optsBase = DB::CommandOptionsFactory::createNew("postgresql", 1234, {}); + BOOST_REQUIRE(optsBase); + auto optsPq = dynamic_cast<PQ::CommandOptions *>(optsBase); + BOOST_REQUIRE(optsPq); + BOOST_REQUIRE(optsBase->hash); + BOOST_REQUIRE_EQUAL(1234, *optsBase->hash); +} + |