From 7b2039ed1d8fc7b67c1e59ab6eae2e9e81404c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Fri, 22 Mar 2019 19:15:45 +1100 Subject: [PATCH] Fix parsing bug #1967 --- lib/MySQL_Session.cpp | 7 ++++++- lib/set_parser.cpp | 2 +- test/set_parser_test/setparsertest.cpp | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 423770fb25..49788cba3d 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -1777,7 +1777,12 @@ bool MySQL_Session::handler_again___status_SETTING_TIME_ZONE(int *_rc) { char *query=NULL; unsigned long query_length=0; if (myconn->async_state_machine==ASYNC_IDLE) { - char *q=(char *)"SET TIME_ZONE='%s'"; + char *q = NULL; + if (myconn->options.time_zone[0]=='@') { + q=(char *)"SET TIME_ZONE=%s"; + } else { + q=(char *)"SET TIME_ZONE='%s'"; + } query=(char *)malloc(strlen(q)+strlen(myconn->options.time_zone)); sprintf(query,q,myconn->options.time_zone); query_length=strlen(query); diff --git a/lib/set_parser.cpp b/lib/set_parser.cpp index cc86aaf025..a249a8116c 100644 --- a/lib/set_parser.cpp +++ b/lib/set_parser.cpp @@ -35,7 +35,7 @@ std::map> SetParser::parse() { #define VAR "(\\w+)" #define SPACES " *" //#define VAR_VALUE "((?:[\\w/\\d:\\+\\-]|,)+)" -#define VAR_VALUE "((?:CONCAT\\((?:REPLACE\\()+@@sql_mode,(?:(?:'|\\w|,| |\"|\\))+(?:\\)))|(?:[\\w/\\d:\\+\\-]|,)+|(?:)))" +#define VAR_VALUE "((?:CONCAT\\((?:REPLACE\\()+@@sql_mode,(?:(?:'|\\w|,| |\"|\\))+(?:\\)))|(?:[@\\w/\\d:\\+\\-]|,)+|(?:)))" const string pattern="(?:" NAMES SPACES QUOTES NAME_VALUE QUOTES "(?: +COLLATE +" QUOTES NAME_VALUE QUOTES "|)" "|" SESSION VAR SPACES "(?:|:)=" SPACES QUOTES VAR_VALUE QUOTES ") *,? *"; re2::RE2 re(pattern, *opt2); diff --git a/test/set_parser_test/setparsertest.cpp b/test/set_parser_test/setparsertest.cpp index 1fbf0e4fee..437b6164a1 100644 --- a/test/set_parser_test/setparsertest.cpp +++ b/test/set_parser_test/setparsertest.cpp @@ -111,6 +111,7 @@ static Test time_zone[] = { { "SET @@time_zone = '+00:00'", { Expected("time_zone", {"+00:00"}) } }, { "SET @@time_zone = \"Europe/Paris\"", { Expected("time_zone", {"Europe/Paris"}) } }, { "SET @@time_zone = \"+00:00\"", { Expected("time_zone", {"+00:00"}) } }, + { "SET @@time_zone = @OLD_TIME_ZONE", { Expected("time_zone", {"@OLD_TIME_ZONE"}) } }, }; TEST(TestParse, SET_TIME_ZONE) {