From fdc6400308deb7ebe73bf08652d0d37a0a2c698f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Wed, 12 May 2021 18:37:55 +0200 Subject: [PATCH] Mofidied 'set_testing' tests to support queries of the shape 'sql_mode=CONCAT(@@sql_mode,'VALUE')' #3442 --- test/tap/tests/set_testing-multi-t.cpp | 46 ++++++++++++++++++++++++-- test/tap/tests/set_testing-t.cpp | 46 ++++++++++++++++++++++++-- test/tap/tests/set_testing-t.csv | 1 + 3 files changed, 89 insertions(+), 4 deletions(-) diff --git a/test/tap/tests/set_testing-multi-t.cpp b/test/tap/tests/set_testing-multi-t.cpp index cf6dfafcf..4ef96d3c3 100644 --- a/test/tap/tests/set_testing-multi-t.cpp +++ b/test/tap/tests/set_testing-multi-t.cpp @@ -12,7 +12,10 @@ #include #include #include + #include "json.hpp" +#include "re2/re2.h" +#include "re2/regexp.h" #include "tap.h" #include "utils.h" @@ -571,9 +574,48 @@ void * my_conn_thread(void *arg) { fprintf(stderr, "Variable %s->%s in proxysql resultset was not found.\nmysql data : %s\nproxysql data: %s\ncsv data %s\n", el.value().dump().c_str(), el.key().c_str(), mysql_vars.dump().c_str(), proxysql_vars.dump().c_str(), vars.dump().c_str()); + bool verified_special_sqlmode = false; + bool special_sqlmode = false; + + if (el.key() == "sql_mode") { + if (!el.value().is_string()) { + diag("Invalid value for 'sql_mode' found. Provided value should be of 'string' type"); + exit(EXIT_FAILURE); + } + + std::string str_val { el.value() }; + + re2::RE2::Options options(RE2::Quiet); + options.set_case_sensitive(false); + options.set_longest_match(false); + re2::RE2 concat_re("^CONCAT\\((|@@|@@session\\.)SQL_MODE,\"(.*)\"\\)", options); + re2::StringPiece sp_input(str_val); + + std::string f_match {}; + std::string s_match {}; + + re2::RE2::Consume(&sp_input, concat_re, &f_match, &s_match); + + if (!s_match.empty()) { + special_sqlmode = true; + + // remove the initial 'comma' if exists + if (s_match[0] == ',') { + s_match = s_match.substr(1, std::string::npos); + } + + std::string k_str_val { k.value() }; + verified_special_sqlmode = + strcasestr(k_str_val.c_str(), s_match.c_str()) != NULL; + } + } + if ( - (el.key() != "session_track_gtids" && (k.value() != el.value() || s.value() != el.value())) || - (el.key() == "session_track_gtids" && !check_session_track_gtids(el.value(), s.value(), k.value())) + (special_sqlmode == true && verified_special_sqlmode == false) || + (special_sqlmode == false && + (el.key() != "session_track_gtids" && (k.value() != el.value() || s.value() != el.value())) || + (el.key() == "session_track_gtids" && !check_session_track_gtids(el.value(), s.value(), k.value())) + ) ) { __sync_fetch_and_add(&g_failed, 1); testPassed = false; diff --git a/test/tap/tests/set_testing-t.cpp b/test/tap/tests/set_testing-t.cpp index c50e73213..7568382c7 100644 --- a/test/tap/tests/set_testing-t.cpp +++ b/test/tap/tests/set_testing-t.cpp @@ -22,7 +22,10 @@ #include #include #include + #include "json.hpp" +#include "re2/re2.h" +#include "re2/regexp.h" #include "tap.h" #include "utils.h" @@ -565,9 +568,48 @@ void * my_conn_thread(void *arg) { fprintf(stderr, "Variable %s->%s in proxysql resultset was not found.\nmysql data : %s\nproxysql data: %s\ncsv data %s\n", el.value().dump().c_str(), el.key().c_str(), mysql_vars.dump().c_str(), proxysql_vars.dump().c_str(), vars.dump().c_str()); + bool verified_special_sqlmode = false; + bool special_sqlmode = false; + + if (el.key() == "sql_mode") { + if (!el.value().is_string()) { + diag("Invalid value for 'sql_mode' found. Provided value should be of 'string' type"); + exit(EXIT_FAILURE); + } + + std::string str_val { el.value() }; + + re2::RE2::Options options(RE2::Quiet); + options.set_case_sensitive(false); + options.set_longest_match(false); + re2::RE2 concat_re("^CONCAT\\((|@@|@@session\\.)SQL_MODE,\"(.*)\"\\)", options); + re2::StringPiece sp_input(str_val); + + std::string f_match {}; + std::string s_match {}; + + re2::RE2::Consume(&sp_input, concat_re, &f_match, &s_match); + + if (!s_match.empty()) { + special_sqlmode = true; + + // remove the initial 'comma' if exists + if (s_match[0] == ',') { + s_match = s_match.substr(1, std::string::npos); + } + + std::string k_str_val { k.value() }; + verified_special_sqlmode = + strcasestr(k_str_val.c_str(), s_match.c_str()) != NULL; + } + } + if ( - (el.key() != "session_track_gtids" && (k.value() != el.value() || s.value() != el.value())) || - (el.key() == "session_track_gtids" && !check_session_track_gtids(el.value(), s.value(), k.value())) + (special_sqlmode == true && verified_special_sqlmode == false) || + (special_sqlmode == false && + (el.key() != "session_track_gtids" && (k.value() != el.value() || s.value() != el.value())) || + (el.key() == "session_track_gtids" && !check_session_track_gtids(el.value(), s.value(), k.value())) + ) ) { __sync_fetch_and_add(&g_failed, 1); testPassed = false; diff --git a/test/tap/tests/set_testing-t.csv b/test/tap/tests/set_testing-t.csv index 408c90d36..6a4776fcb 100644 --- a/test/tap/tests/set_testing-t.csv +++ b/test/tap/tests/set_testing-t.csv @@ -91,3 +91,4 @@ "SET time_zone='+04:00', sql_mode='NO_ENGINE_SUBSTITUTION', max_join_size=10000; SET CHARACTER SET 'latin1'", "{'time_zone':'+04:00', 'sql_mode':'NO_ENGINE_SUBSTITUTION', 'max_join_size':'10000', 'character_set_results':'latin1', 'character_set_client':'latin1'}", "['character_set_connection', 'collation_connection']" "SET time_zone='+04:00', sql_mode='NO_ENGINE_SUBSTITUTION', max_join_size=10000; SET CHARSET 'latin1'", "{'time_zone':'+04:00', 'sql_mode':'NO_ENGINE_SUBSTITUTION', 'max_join_size':'10000', 'character_set_results':'latin1', 'character_set_client':'latin1'}", "['character_set_connection', 'collation_connection']" "SET session_track_gtids=ALL_GTIDS", "{'session_track_gtids':'ALL_GTIDS'}" +"SET sql_safe_updates=1, session_track_schema=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES')", "{'sql_safe_updates':'ON', 'sql_mode':'concat(@@sql_mode,\',STRICT_TRANS_TABLES\')'}"