diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-12-01 01:06:35 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-12-01 01:06:35 +0000 |
commit | 97f48ca194a5fcd4bea46ef87278e640c448f481 (patch) | |
tree | e9956d9d00e8d07a2b582b410bcefbdd736d666a | |
parent | Split SqlParse's statement execution into a separate class (diff) | |
download | libdbpp-97f48ca194a5fcd4bea46ef87278e640c448f481.tar.bz2 libdbpp-97f48ca194a5fcd4bea46ef87278e640c448f481.tar.xz libdbpp-97f48ca194a5fcd4bea46ef87278e640c448f481.zip |
Internalise some of the core functionality of the SQL parser
-rw-r--r-- | libdbpp/connection.cpp | 5 | ||||
-rw-r--r-- | libdbpp/sqlParse.h | 4 | ||||
-rw-r--r-- | libdbpp/sqlParse.ll | 9 |
3 files changed, 13 insertions, 5 deletions
diff --git a/libdbpp/connection.cpp b/libdbpp/connection.cpp index 6bb846e..3d954a6 100644 --- a/libdbpp/connection.cpp +++ b/libdbpp/connection.cpp @@ -110,11 +110,8 @@ DB::Connection::inTx() const void DB::Connection::executeScript(std::istream & f, const boost::filesystem::path & s) { - if (!f.good()) { - throw SqlParseException("Script stream not in good state.", 0); - } DB::SqlExecuteScript p(f, s, this); - while (p.yylex()) ; + p.Execute(); } void diff --git a/libdbpp/sqlParse.h b/libdbpp/sqlParse.h index 1a8c46d..5ab5143 100644 --- a/libdbpp/sqlParse.h +++ b/libdbpp/sqlParse.h @@ -30,7 +30,8 @@ namespace DB { class DLL_PUBLIC SqlParse : public yyFlexLexer { public: SqlParse(std::istream &, const boost::filesystem::path &); - int yylex() override; + + void Execute(); virtual void Comment(const std::string &) const = 0; virtual void Statement(const std::string &) const = 0; @@ -39,6 +40,7 @@ namespace DB { void LexerError(const char *) override; private: + int yylex() override; const boost::filesystem::path scriptDir; std::string comment; std::string statement; diff --git a/libdbpp/sqlParse.ll b/libdbpp/sqlParse.ll index 8df4895..18210ac 100644 --- a/libdbpp/sqlParse.ll +++ b/libdbpp/sqlParse.ll @@ -147,6 +147,15 @@ namespace DB { yyFlexLexer(&f, NULL), scriptDir(s) { + if (!f.good()) { + throw SqlParseException("Script stream not in good state.", 0); + } + } + + void + SqlParse::Execute() + { + while (yylex()) ; } void |