Skip to content

Commit

Permalink
Fix parsing bug #1967
Browse files Browse the repository at this point in the history
  • Loading branch information
renecannao committed Mar 22, 2019
1 parent 8ac314e commit 7b2039e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/MySQL_Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/set_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ std::map<std::string,std::vector<string>> 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);
Expand Down
1 change: 1 addition & 0 deletions test/set_parser_test/setparsertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7b2039e

Please sign in to comment.