From 4b26dad975cd774ada951be302c713d777262403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sun, 7 Aug 2022 23:57:08 +0000 Subject: [PATCH] Wrong value of NO_BACKSLASH_ESCAPES was sent to client This is an enhancement of PR #3926 , fixing the typo and adding the testing for it. --- lib/MySQL_Session.cpp | 4 +- test/tap/tests/generate_set_session_csv.cpp | 2 + test/tap/tests/set_testing-240-t.cpp | 53 +++++++++++++++++---- test/tap/tests/set_testing.h | 3 ++ 4 files changed, 52 insertions(+), 10 deletions(-) diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 6f9cddfbb..7cf969444 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -5672,8 +5672,8 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C auto values = std::begin(it->second); if (var == "sql_mode") { std::string value1 = *values; - if (strcasecmp(value1.c_str(),"NO_BACKSLASH_ESCAPE") != 0) { - // client is setting NO_BACKSLASH_ESCAPE in sql_mode + if (strcasestr(value1.c_str(),"NO_BACKSLASH_ESCAPES") != NULL) { + // client is setting NO_BACKSLASH_ESCAPES in sql_mode // Because we will reply with an OK packet without // first setting sql_mode to the backend (this is // by design) we need to set no_backslash_escapes diff --git a/test/tap/tests/generate_set_session_csv.cpp b/test/tap/tests/generate_set_session_csv.cpp index db9bfc7ba..48e5e4e63 100644 --- a/test/tap/tests/generate_set_session_csv.cpp +++ b/test/tap/tests/generate_set_session_csv.cpp @@ -253,6 +253,8 @@ int main() { vars["time_zone"]->add(std::vector {"'-11:10'", "`-11:33`", "\"-04:56\""}); vars["sql_mode"] = new variable("sql_mode", true, false, false); vars["sql_mode"]->add(std::vector {"'traditional'", "TRADITIONAL", "''"}); + vars["sql_mode"]->add(std::vector {"'NO_BACKSLASH_ESCAPES'", "NO_BACKSLASH_ESCAPES"}); + vars["sql_mode"]->add(std::vector {"'TRADITIONAL,NO_BACKSLASH_ESCAPES'", "\"NO_BACKSLASH_ESCAPES,TRADITIONAL\""}); vars["sql_mode"]->add(std::vector {"'PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'", "\"PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION\""}); vars["sql_mode"]->add(std::vector {"ALLOW_INVALID_DATES", "'ALLOW_INVALID_DATES'", "\"ALLOW_INVALID_DATES\""}); vars["sql_mode"]->add(std::vector {"NO_ENGINE_SUBSTITUTION", "'NO_ENGINE_SUBSTITUTION'", "\"NO_ENGINE_SUBSTITUTION\""}); diff --git a/test/tap/tests/set_testing-240-t.cpp b/test/tap/tests/set_testing-240-t.cpp index a056dfe8b..3c49db497 100644 --- a/test/tap/tests/set_testing-240-t.cpp +++ b/test/tap/tests/set_testing-240-t.cpp @@ -33,9 +33,11 @@ -int queries_per_connections=1; -unsigned int num_threads=1; -int count=0; +int queries_per_connections=10; +//unsigned int num_threads=1; +//unsigned int num_threads=5; +unsigned int num_threads=20; +int count=20; char *username=NULL; char *password=NULL; char *host=(char *)"localhost"; @@ -45,7 +47,7 @@ char *schema=(char *)"information_schema"; int silent = 0; int sysbench = 0; int local=0; -int queries=0; +int queries=3000; int uniquequeries=0; int histograms=-1; @@ -95,6 +97,7 @@ void * my_conn_thread(void *arg) { unsigned int select_ERR=0; int i, j; MYSQL **mysqlconns=(MYSQL **)malloc(sizeof(MYSQL *)*count); + bool set_sql_mode[count]; std::vector varsperconn(count); if (mysqlconns==NULL) { @@ -119,6 +122,7 @@ void * my_conn_thread(void *arg) { exit(EXIT_FAILURE); } mysqlconns[i]=mysql; + set_sql_mode[i]=false; __sync_add_and_fetch(&status_connections,1); } __sync_fetch_and_add(&connect_phase_completed,1); @@ -126,17 +130,19 @@ void * my_conn_thread(void *arg) { while(__sync_fetch_and_add(&connect_phase_completed,0) != num_threads) { } MYSQL *mysql=NULL; + int mysql_idx = 0; json vars; std::string paddress = ""; for (j=0; jthread_id, testCases[r2].command.c_str()); + if (set_sql_mode[mysql_idx] == false) { + // first time we set sql_mode + if (strcasestr(c.c_str(),"NO_BACKSLASH_ESCAPES") != NULL) { + if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES) { + } else { + diag("Line %d: ERROR with NO_BACKSLASH_ESCAPES . connections mysql[%p] proxysql[%s], thread_id [%lu], command [%s]", __LINE__, mysql, paddress.c_str(), mysql->thread_id, testCases[r2].command.c_str()); + exit(EXIT_FAILURE); + } + } else { + if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES) { + diag("Line %d: ERROR with NO_BACKSLASH_ESCAPES . connections mysql[%p] proxysql[%s], thread_id [%lu], command [%s]", __LINE__, mysql, paddress.c_str(), mysql->thread_id, testCases[r2].command.c_str()); + exit(EXIT_FAILURE); + } else { + } + } + set_sql_mode[mysql_idx] = 1; +// diag("Setting set_sql_mode=true . New value = %s . For: connections mysql[%p] proxysql[%s], thread_id [%lu], command [%s]" , (set_sql_mode[mysql_idx] == true ? "true" : "false") , mysql, paddress.c_str(), mysql->thread_id, testCases[r2].command.c_str()); + } else { + if (strcasestr(c.c_str(),"NO_BACKSLASH_ESCAPES") != NULL) { + if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES) { + } else { + diag("Line %d: ERROR with NO_BACKSLASH_ESCAPES . connections mysql[%p] proxysql[%s], thread_id [%lu], command [%s]", __LINE__, mysql, paddress.c_str(), mysql->thread_id, testCases[r2].command.c_str()); + exit(EXIT_FAILURE); + } + } + } + } } } @@ -413,9 +448,11 @@ int main(int argc, char *argv[]) { return exit_status(); } +/* num_threads = 10; queries_per_connections = 10; count = 10; +*/ username = cl.username; password = cl.password; host = cl.host; @@ -447,7 +484,7 @@ int main(int argc, char *argv[]) { MYSQL_QUERY(proxysql_admin, "UPDATE mysql_query_rules SET destination_hostgroup=101 WHERE destination_hostgroup=1"); MYSQL_QUERY(proxysql_admin, "LOAD MYSQL QUERY RULES TO RUNTIME"); - queries = 3000; + //queries = 3000; //queries = testCases.size(); plan(queries * num_threads); diff --git a/test/tap/tests/set_testing.h b/test/tap/tests/set_testing.h index 39cdfac38..4ebbb8d55 100644 --- a/test/tap/tests/set_testing.h +++ b/test/tap/tests/set_testing.h @@ -106,6 +106,9 @@ int readTestCasesJSON(const std::string& fileName) { } } testCases.push_back({newbuf, vars, reset_vars}); + if (i%5000 == 0) { + fprintf(stderr,"Read %d tests...\n", i); + } } fclose(fp);