summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2018-03-13 21:27:04 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2018-03-13 21:27:04 +0000
commit8715f47325daf65fe12cb42bcf3fa33820e51c57 (patch)
treea22730f2e9b1c7f9deb647aa202f87ec6a2a93ef
parentAdd fwd headers to reduce the compile overheads of simple clients. (diff)
downloadlibdbpp-1.1.4.1.tar.bz2
libdbpp-1.1.4.1.tar.xz
libdbpp-1.1.4.1.zip
Fix up SQL parsing in the presense of empty single-line commentslibdbpp-1.1.4.1
-rw-r--r--libdbpp/sqlParse.ll8
-rw-r--r--libdbpp/unittests/parseTest.sql9
-rw-r--r--libdbpp/unittests/testParse.cpp16
3 files changed, 32 insertions, 1 deletions
diff --git a/libdbpp/sqlParse.ll b/libdbpp/sqlParse.ll
index 835ce20..41d337a 100644
--- a/libdbpp/sqlParse.ll
+++ b/libdbpp/sqlParse.ll
@@ -13,10 +13,11 @@
%}
space [ \t\n\r\f]
+linespace [ \t]
non_newline [^\r\n]
mcomment_start ("/*"{space}*)
mcomment_stop ({space}*"*/")
-lcomment_start ({space}*"--"{space}*)
+lcomment_start ({space}*"--"{linespace}*)
other .
term ;
any ({other}|{space})
@@ -71,6 +72,11 @@ scriptdir "$SCRIPTDIR"
yy_pop_state();
}
+<LCOMMENT>[\r\n]+ {
+ Comment(comment);
+ yy_pop_state();
+}
+
<INITIAL>{term} {
// Random terminator
}
diff --git a/libdbpp/unittests/parseTest.sql b/libdbpp/unittests/parseTest.sql
index 6a3df82..5e1fbcd 100644
--- a/libdbpp/unittests/parseTest.sql
+++ b/libdbpp/unittests/parseTest.sql
@@ -4,6 +4,15 @@ CREATE TABLE name (
primary key(i)
);
-- Single line comment
+--
+ --
+ --
+--
+
+/* Comment */
+ /**/
+ /* */
+ /**/
INSERT INTO name(t, i) VALUES('string', 3);
/*
Multi line
diff --git a/libdbpp/unittests/testParse.cpp b/libdbpp/unittests/testParse.cpp
index 093cc7d..b5f3d65 100644
--- a/libdbpp/unittests/testParse.cpp
+++ b/libdbpp/unittests/testParse.cpp
@@ -56,6 +56,22 @@ BOOST_AUTO_TEST_CASE( parse )
p.Execute();
BOOST_REQUIRE_EQUAL(p.executed.size(), 3);
BOOST_REQUIRE_EQUAL(p.executed[1], "INSERT INTO name(t, i) VALUES('string', 3)");
+ auto cs = {
+ "Single line comment",
+ "",
+ "",
+ "",
+ "",
+ "Comment",
+ "",
+ "",
+ "",
+ "Multi line\n\t comment",
+ "! Stupid MySQL terminates",
+ "! comments with a ;",
+ "! Because reasons",
+ };
+ BOOST_CHECK_EQUAL_COLLECTIONS(p.comments.begin(), p.comments.end(), cs.begin(), cs.end());
}
BOOST_AUTO_TEST_CASE( parseDollarQuote )