diff options
-rw-r--r-- | libdbpp/connection.cpp | 13 | ||||
-rw-r--r-- | libdbpp/connection.h | 10 | ||||
-rw-r--r-- | libdbpp/sqlParse.h | 38 | ||||
-rw-r--r-- | libdbpp/sqlParse.ll | 2 | ||||
-rw-r--r-- | libdbpp/unittests/testConnection.cpp | 8 |
5 files changed, 35 insertions, 36 deletions
diff --git a/libdbpp/connection.cpp b/libdbpp/connection.cpp index 6c36d45..b58a0e1 100644 --- a/libdbpp/connection.cpp +++ b/libdbpp/connection.cpp @@ -23,10 +23,9 @@ DB::Connection::~Connection() } void -DB::Connection::execute(const std::string & sql) const +DB::Connection::execute(const std::string & sql) { - auto cmd = ModifyCommandPtr(newModifyCommand(sql)); - cmd->execute(true); + modify(sql)->execute(true); } @@ -43,7 +42,7 @@ DB::Connection::modify(const std::string & sql) } void -DB::Connection::executeScript(std::istream & f, const boost::filesystem::path & s) const +DB::Connection::executeScript(std::istream & f, const boost::filesystem::path & s) { if (!f.good()) { throw SqlParseException("Script stream not in good state.", 0); @@ -53,19 +52,19 @@ DB::Connection::executeScript(std::istream & f, const boost::filesystem::path & } void -DB::Connection::savepoint(const std::string & sp) const +DB::Connection::savepoint(const std::string & sp) { execute("SAVEPOINT " + sp); } void -DB::Connection::rollbackToSavepoint(const std::string & sp) const +DB::Connection::rollbackToSavepoint(const std::string & sp) { execute("ROLLBACK TO SAVEPOINT " + sp); } void -DB::Connection::releaseSavepoint(const std::string & sp) const +DB::Connection::releaseSavepoint(const std::string & sp) { execute("RELEASE SAVEPOINT " + sp); } diff --git a/libdbpp/connection.h b/libdbpp/connection.h index f92be3d..3c0627a 100644 --- a/libdbpp/connection.h +++ b/libdbpp/connection.h @@ -97,11 +97,11 @@ namespace DB { /// Test to see if a transaction is currently open. virtual bool inTx() const = 0; /// Create a named save point. - virtual void savepoint(const std::string &) const; + virtual void savepoint(const std::string &); /// Rollback to a named save point. - virtual void rollbackToSavepoint(const std::string &) const; + virtual void rollbackToSavepoint(const std::string &); /// Release a named save point. - virtual void releaseSavepoint(const std::string &) const; + virtual void releaseSavepoint(const std::string &); /// Test server connection availability. virtual void ping() const = 0; /// @cond @@ -110,11 +110,11 @@ namespace DB { /// @endcond /// Straight up execute a statement (no access to result set) - virtual void execute(const std::string & sql) const; + virtual void execute(const std::string & sql); /// 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) const; + 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) const = 0; /// Create a new select command with the given SQL [smart pointer]. diff --git a/libdbpp/sqlParse.h b/libdbpp/sqlParse.h index d56bce9..87b1303 100644 --- a/libdbpp/sqlParse.h +++ b/libdbpp/sqlParse.h @@ -26,25 +26,25 @@ namespace DB { const unsigned int line; }; -/// @cond -class SqlParse : public yyFlexLexer { - public: - SqlParse(std::istream &, const boost::filesystem::path &, const Connection *); - int yylex() override; - - void Comment(const std::string &) const; - void Statement(const std::string &) const; - - protected: - void LexerError(const char *) override; - - private: - const DB::Connection * conn; - const boost::filesystem::path scriptDir; - std::string comment; - std::string statement; -}; -/// @endcond + /// @cond + class SqlParse : public yyFlexLexer { + public: + SqlParse(std::istream &, const boost::filesystem::path &, Connection *); + int yylex() override; + + void Comment(const std::string &) const; + void Statement(const std::string &) const; + + protected: + void LexerError(const char *) override; + + private: + DB::Connection * const conn; + const boost::filesystem::path scriptDir; + std::string comment; + std::string statement; + }; + /// @endcond } diff --git a/libdbpp/sqlParse.ll b/libdbpp/sqlParse.ll index 684b996..f33f311 100644 --- a/libdbpp/sqlParse.ll +++ b/libdbpp/sqlParse.ll @@ -142,7 +142,7 @@ namespace DB { return stringf("Error parsing SQL script: %s at line %u", reason, line); } - SqlParse::SqlParse(std::istream & f, const boost::filesystem::path & s, const Connection * c) : + SqlParse::SqlParse(std::istream & f, const boost::filesystem::path & s, Connection * c) : yyFlexLexer(&f, NULL), conn(c), scriptDir(s) diff --git a/libdbpp/unittests/testConnection.cpp b/libdbpp/unittests/testConnection.cpp index bc1a71b..a5fc1a6 100644 --- a/libdbpp/unittests/testConnection.cpp +++ b/libdbpp/unittests/testConnection.cpp @@ -23,7 +23,7 @@ class MockDb : public DB::Connection { DB::BulkDeleteStyle bulkDeleteStyle() const { return DB::BulkDeleteUsingUsing; } DB::BulkUpdateStyle bulkUpdateStyle() const { return DB::BulkUpdateUsingJoin; } - void execute(const std::string & sql) const { + void execute(const std::string & sql) override { executed.push_back(sql); } DB::SelectCommand * newSelectCommand(const std::string &) const { return nullptr; } @@ -61,9 +61,9 @@ BOOST_AUTO_TEST_CASE( create ) BOOST_AUTO_TEST_CASE( resolve ) { - auto pq = DB::ConnectionFactory::createNew("postgresql", "user=postgres dbname=postgres"); - BOOST_REQUIRE(pq); - delete pq; + auto libname = DB::Connection::resolvePlugin(typeid(DB::Connection), "postgresql"); + BOOST_REQUIRE(libname); + BOOST_REQUIRE_EQUAL("libdbpp-postgresql.so", *libname); BOOST_REQUIRE_THROW(DB::ConnectionFactory::createNew("otherdb", "doesn't matter"), AdHoc::LoadLibraryException); } |