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.
pull/3939/head
René Cannaò 4 years ago
parent 524e664190
commit 4b26dad975

@ -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

@ -253,6 +253,8 @@ int main() {
vars["time_zone"]->add(std::vector<std::string> {"'-11:10'", "`-11:33`", "\"-04:56\""});
vars["sql_mode"] = new variable("sql_mode", true, false, false);
vars["sql_mode"]->add(std::vector<std::string> {"'traditional'", "TRADITIONAL", "''"});
vars["sql_mode"]->add(std::vector<std::string> {"'NO_BACKSLASH_ESCAPES'", "NO_BACKSLASH_ESCAPES"});
vars["sql_mode"]->add(std::vector<std::string> {"'TRADITIONAL,NO_BACKSLASH_ESCAPES'", "\"NO_BACKSLASH_ESCAPES,TRADITIONAL\""});
vars["sql_mode"]->add(std::vector<std::string> {"'PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'", "\"PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION\""});
vars["sql_mode"]->add(std::vector<std::string> {"ALLOW_INVALID_DATES", "'ALLOW_INVALID_DATES'", "\"ALLOW_INVALID_DATES\""});
vars["sql_mode"]->add(std::vector<std::string> {"NO_ENGINE_SUBSTITUTION", "'NO_ENGINE_SUBSTITUTION'", "\"NO_ENGINE_SUBSTITUTION\""});

@ -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<json> 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; j<queries; j++) {
int fr = fastrand();
int fr = rand();
int r1=fr%count;
//int r2=fastrand()%testCases.size();
int r2=rand()%testCases.size();
if (j%queries_per_connections==0) {
mysql=mysqlconns[r1];
vars = varsperconn[r1];
mysql_idx=r1;
mysql=mysqlconns[mysql_idx];
vars = varsperconn[mysql_idx];
}
if (strcmp(username,(char *)"root")) {
if (strstr(testCases[r2].command.c_str(),"database")) {
@ -162,6 +168,35 @@ void * my_conn_thread(void *arg) {
mysql_free_result(result);
select_OK++;
__sync_fetch_and_add(&g_select_OK,1);
if (strcasestr(c.c_str(),"sql_mode") != NULL) {
// diag("Line %d: Debug NO_BACKSLASH_ESCAPES , set_sql_mode=%s , connections mysql[%p] proxysql[%s], thread_id [%lu], command [%s]", __LINE__, (set_sql_mode[mysql_idx] == true ? "true" : "false") , mysql, paddress.c_str(), mysql->thread_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);

@ -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);

Loading…
Cancel
Save