diff --git a/lib/set_parser.cpp b/lib/set_parser.cpp index a57890a83..4b4be6ec3 100644 --- a/lib/set_parser.cpp +++ b/lib/set_parser.cpp @@ -116,6 +116,9 @@ VALGRIND_ENABLE_ERROR_REPORTING; std::transform(key.begin(), key.end(), key.begin(), ::tolower); result[key] = op; } + if (input.size() != 0) { + result = {}; + } delete opt2; return result; } @@ -366,7 +369,14 @@ VALGRIND_ENABLE_ERROR_REPORTING; std::transform(key.begin(), key.end(), key.begin(), ::tolower); result[key] = op; } - + if (input.size() != 0) { +#ifdef PARSERDEBUG + if (verbosity > 0) { + cout << "Failed to parse: " << input << endl; + } +#endif + result = {}; + } //delete opt2; return result; } diff --git a/test/tap/tests/setparser_test2.cpp b/test/tap/tests/setparser_test2.cpp index 56b7e4e4e..215d8b8d7 100644 --- a/test/tap/tests/setparser_test2.cpp +++ b/test/tap/tests/setparser_test2.cpp @@ -13,6 +13,7 @@ void TestParse(const Test* tests, int ntests, const std::string& title) { data[it->var] = it->values; } + cout << "Processing query: " << tests[i].query << endl; SetParser parser(tests[i].query); std::map> result = parser.parse1(); @@ -40,6 +41,7 @@ int main(int argc, char** argv) { p += arraysize(various); p += arraysize(multiple); p += arraysize(Set1_v1); + p += arraysize(syntax_errors); p *= 2; plan(p); TestParse(sql_mode, arraysize(sql_mode), "sql_mode"); @@ -49,6 +51,7 @@ int main(int argc, char** argv) { TestParse(names, arraysize(names), "names"); TestParse(various, arraysize(various), "various"); TestParse(multiple, arraysize(multiple), "multiple"); - TestParse(multiple, arraysize(Set1_v1), "Set1_v1"); + TestParse(Set1_v1, arraysize(Set1_v1), "Set1_v1"); + TestParse(syntax_errors, arraysize(syntax_errors), "syntax_errors"); return exit_status(); } diff --git a/test/tap/tests/setparser_test3.cpp b/test/tap/tests/setparser_test3.cpp index 20ced5f33..b184b6d0e 100644 --- a/test/tap/tests/setparser_test3.cpp +++ b/test/tap/tests/setparser_test3.cpp @@ -19,6 +19,7 @@ void TestParse(const Test* tests, int ntests, const std::string& title) { //std::map> result = parser.parse1(); //std::map> result = parser.parse1v2(); + cout << "Processing query: " << tests[i].query << endl; parser->set_query(tests[i].query); std::map> result = parser->parse1v2(); @@ -46,6 +47,7 @@ int main(int argc, char** argv) { p += arraysize(various); p += arraysize(multiple); p += arraysize(Set1_v2); + p += arraysize(syntax_errors); p *= 2; plan(p); parser = new SetParser("", 1); @@ -56,6 +58,7 @@ int main(int argc, char** argv) { TestParse(names, arraysize(names), "names"); TestParse(various, arraysize(various), "various"); TestParse(multiple, arraysize(multiple), "multiple"); - TestParse(multiple, arraysize(Set1_v2), "Set1_v2"); + TestParse(Set1_v2, arraysize(Set1_v2), "Set1_v2"); + TestParse(syntax_errors, arraysize(syntax_errors), "syntax_errors"); return exit_status(); } diff --git a/test/tap/tests/setparser_test_common.h b/test/tap/tests/setparser_test_common.h index 9c8e50d96..15b76a3d8 100644 --- a/test/tap/tests/setparser_test_common.h +++ b/test/tap/tests/setparser_test_common.h @@ -106,18 +106,27 @@ static Test sql_mode[] = { static Test Set1_v1[] = { { "SET sql_mode=(SELECT CONCAT(@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'))", {} }, // parse1v2 SHOULD process it { "SET sql_mode = 'TRADITIONAL', NAMES 'utf8 COLLATE 'unicode_ci'", { Expected("sql_mode", {"TRADITIONAL"}), Expected("names", {"utf8", "unicode_ci"}) } }, // FIXME: this should return an error + { "SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO'), ',NO_ENGINE_SUBSTITUTION'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 3600", + { + Expected("names", {"utf8"}), + Expected("sql_mode", {"CONCAT(CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO'), ',NO_ENGINE_SUBSTITUTION')"}), + Expected("sql_auto_is_null", {"0"}), + Expected("wait_timeout", {"3600"}) } }, // v2 is not able to parse this, because it can process only up to 4 functions }; static Test Set1_v2[] = { //{ "SET sql_mode=(SELECT CONCAT(@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'))", {} }, // parse1v2 SHOULD process it //{ "SET sql_mode = 'TRADITIONAL', NAMES 'utf8 COLLATE 'unicode_ci'", { Expected("sql_mode", {"TRADITIONAL"}), Expected("names", {"utf8", "unicode_ci"}) } }, // FIXME: this should return an error + { "SET sql_mode='TRADITIONAL' , whatever = , autocommit=1", {} }, // v1 is not able to process this + { "SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO'), ',NO_ENGINE_SUBSTITUTION'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 3600", + {} }, // v2 is not able to parse this, because it can process only up to 4 functions +}; + +static Test syntax_errors[] = { + { "SET sql_mode='TRADITIONAL' , whatever", {} }, + { "SET sql_mode='TRADITIONAL' , whatever = ", {} }, }; -/* -TEST(TestParse, SET_SQL_MODE) { - TestParse(sql_mode, arraysize(sql_mode), "sql_mode"); -} -*/ static Test time_zone[] = { { "SET @@time_zone = 'Europe/Paris'", { Expected("time_zone", {"Europe/Paris"}) } }, { "SET @@time_zone = '+00:00'", { Expected("time_zone", {"+00:00"}) } }, @@ -125,14 +134,10 @@ static Test time_zone[] = { { "SET @@time_zone = \"+00:00\"", { Expected("time_zone", {"+00:00"}) } }, { "SET @@time_zone = @OLD_TIME_ZONE", { Expected("time_zone", {"@OLD_TIME_ZONE"}) } }, { "SET @@TIME_ZONE = @OLD_TIME_ZONE", { Expected("time_zone", {"@OLD_TIME_ZONE"}) } }, + { "SET @@TIME_ZONE := 'SYSTEM'", { Expected("time_zone", {"SYSTEM"}) } }, + { "SET time_zone := 'SYSTEM'", { Expected("time_zone", {"SYSTEM"}) } }, }; -/* -TEST(TestParse, SET_TIME_ZONE) { - TestParse(time_zone, arraysize(time_zone), "time_zone"); -} -*/ - static Test session_track_gtids[] = { { "SET @@session_track_gtids = OFF", { Expected("session_track_gtids", {"OFF"}) } }, { "SET @@session_track_gtids = OWN_GTID", { Expected("session_track_gtids", {"OWN_GTID"}) } }, @@ -145,12 +150,6 @@ static Test session_track_gtids[] = { { "SET SESSION session_track_gtids = ALL_GTIDS", { Expected("session_track_gtids", {"ALL_GTIDS"}) } }, }; -/* -TEST(TestParse, SET_SESSION_TRACK_GTIDS) { - TestParse(session_track_gtids, arraysize(session_track_gtids), "session_track_gtids"); -} -*/ - static Test character_set_results[] = { { "SET @@character_set_results = utf8", { Expected("character_set_results", {"utf8"}) } }, { "SET @@character_set_results = NULL", { Expected("character_set_results", {"NULL"}) } },