From ca6616beac6219180a633d0fa70089d6d43904a4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 21 Dec 2015 20:35:12 +0000 Subject: Add baskslash escaping support to sql parser --- libdbpp/sqlParse.ll | 5 +++++ libdbpp/unittests/stringParse.sql | 1 + libdbpp/unittests/testConnection.cpp | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/libdbpp/sqlParse.ll b/libdbpp/sqlParse.ll index 7649445..0661abc 100644 --- a/libdbpp/sqlParse.ll +++ b/libdbpp/sqlParse.ll @@ -24,6 +24,7 @@ term ; any ({other}|{space}) quote ' quote_apos '' +quote_esc \\. dolq_start [A-Za-z\200-\377_] dolq_cont [A-Za-z\200-\377_0-9] dollarquote \$({dolq_start}{dolq_cont}*)?\$ @@ -92,6 +93,10 @@ scriptdir "$SCRIPTDIR" statement += YYText(); } +{quote_esc} { + statement += YYText(); +} + {any} { statement += YYText(); } diff --git a/libdbpp/unittests/stringParse.sql b/libdbpp/unittests/stringParse.sql index e764da9..736400b 100644 --- a/libdbpp/unittests/stringParse.sql +++ b/libdbpp/unittests/stringParse.sql @@ -1 +1,2 @@ INSERT INTO dollarQuotes(a) VALUES('apos''trophe'); +INSERT INTO name(t, i) VALUES('fancy string '' \' \r \n', 7); diff --git a/libdbpp/unittests/testConnection.cpp b/libdbpp/unittests/testConnection.cpp index b9cabdf..86ca2a8 100644 --- a/libdbpp/unittests/testConnection.cpp +++ b/libdbpp/unittests/testConnection.cpp @@ -82,6 +82,8 @@ BOOST_AUTO_TEST_CASE( parse ) BOOST_AUTO_TEST_CASE( parse2 ) { auto mock = DB::ConnectionPtr(DB::ConnectionFactory::createNew("MockDb", "doesn't matter")); + auto mockdb = boost::dynamic_pointer_cast(mock); + BOOST_REQUIRE(mockdb); std::fstream s; s.open((rootDir / "dollarQuote.sql").string()); @@ -95,6 +97,8 @@ BOOST_AUTO_TEST_CASE( parse2 ) s.open((rootDir / "stringParse.sql").string()); mock->executeScript(s, rootDir); s.close(); + BOOST_REQUIRE_EQUAL(4, mockdb->executed.size()); + BOOST_REQUIRE_EQUAL("INSERT INTO name(t, i) VALUES('fancy string '' \\' \\r \\n', 7)", mockdb->executed[3]); BOOST_REQUIRE_THROW({ s.open((rootDir / "unterminatedComment.sql").string()); -- cgit v1.2.3