From 97f48ca194a5fcd4bea46ef87278e640c448f481 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 1 Dec 2017 01:06:35 +0000 Subject: Internalise some of the core functionality of the SQL parser --- libdbpp/connection.cpp | 5 +---- libdbpp/sqlParse.h | 4 +++- 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 -- cgit v1.2.3