diff options
-rw-r--r-- | libdbpp/connection.cpp | 2 | ||||
-rw-r--r-- | libdbpp/sqlParse.h | 20 | ||||
-rw-r--r-- | libdbpp/sqlParse.ll | 13 |
3 files changed, 25 insertions, 10 deletions
diff --git a/libdbpp/connection.cpp b/libdbpp/connection.cpp index 12a952e..6bb846e 100644 --- a/libdbpp/connection.cpp +++ b/libdbpp/connection.cpp @@ -113,7 +113,7 @@ DB::Connection::executeScript(std::istream & f, const boost::filesystem::path & if (!f.good()) { throw SqlParseException("Script stream not in good state.", 0); } - DB::SqlParse p(f, s, this); + DB::SqlExecuteScript p(f, s, this); while (p.yylex()) ; } diff --git a/libdbpp/sqlParse.h b/libdbpp/sqlParse.h index 4e01482..1a8c46d 100644 --- a/libdbpp/sqlParse.h +++ b/libdbpp/sqlParse.h @@ -27,23 +27,33 @@ namespace DB { }; /// @cond - class SqlParse : public yyFlexLexer { + class DLL_PUBLIC SqlParse : public yyFlexLexer { public: - SqlParse(std::istream &, const boost::filesystem::path &, Connection *); + SqlParse(std::istream &, const boost::filesystem::path &); int yylex() override; - void Comment(const std::string &) const; - void Statement(const std::string &) const; + virtual void Comment(const std::string &) const = 0; + virtual void Statement(const std::string &) const = 0; protected: void LexerError(const char *) override; private: - DB::Connection * const conn; const boost::filesystem::path scriptDir; std::string comment; std::string statement; }; + + class DLL_PUBLIC SqlExecuteScript : public SqlParse { + public: + SqlExecuteScript(std::istream &, const boost::filesystem::path &, Connection *); + + void Comment(const std::string &) const override; + void Statement(const std::string &) const override; + + private: + DB::Connection * const conn; + }; /// @endcond } diff --git a/libdbpp/sqlParse.ll b/libdbpp/sqlParse.ll index 3037c0a..8df4895 100644 --- a/libdbpp/sqlParse.ll +++ b/libdbpp/sqlParse.ll @@ -143,9 +143,8 @@ namespace DB { return SqlParseExceptionMsg::get(reason, line); } - SqlParse::SqlParse(std::istream & f, const boost::filesystem::path & s, Connection * c) : + SqlParse::SqlParse(std::istream & f, const boost::filesystem::path & s) : yyFlexLexer(&f, NULL), - conn(c), scriptDir(s) { } @@ -156,13 +155,19 @@ namespace DB { throw std::runtime_error(msg); } + SqlExecuteScript::SqlExecuteScript(std::istream & f, const boost::filesystem::path & s, DB::Connection * c) : + SqlParse(f, s), + conn(c) + { + } + void - SqlParse::Comment(const std::string &) const + SqlExecuteScript::Comment(const std::string &) const { } void - SqlParse::Statement(const std::string & text) const + SqlExecuteScript::Statement(const std::string & text) const { conn->execute(text); } |