diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 14f568e0a..e72851fa3 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -23,6 +23,11 @@ #define EXPMARIA +static inline char is_digit(char c) { + if(c >= '0' && c <= '9') + return 1; + return 0; +} static inline char is_normal_char(char c) { if(c >= 'a' && c <= 'z') return 1; @@ -918,6 +923,15 @@ void MySQL_Session::generate_proxysql_internal_session_json(json &j) { j["transaction_persistent"] = transaction_persistent; j["conn"]["sql_mode"] = ( client_myds->myconn->options.sql_mode ? client_myds->myconn->options.sql_mode : "") ; j["conn"]["time_zone"] = ( client_myds->myconn->options.time_zone ? client_myds->myconn->options.time_zone : "") ; + j["conn"]["isolation_level"] = ( client_myds->myconn->options.isolation_level ? client_myds->myconn->options.isolation_level : "") ; + j["conn"]["character_set_results"] = ( client_myds->myconn->options.character_set_results ? client_myds->myconn->options.character_set_results : "") ; + j["conn"]["session_track_gtids"] = ( client_myds->myconn->options.session_track_gtids ? client_myds->myconn->options.session_track_gtids : "") ; + j["conn"]["sql_auto_is_null"] = ( client_myds->myconn->options.sql_auto_is_null ? client_myds->myconn->options.sql_auto_is_null : "") ; + j["conn"]["sql_select_limit"] = ( client_myds->myconn->options.sql_select_limit ? client_myds->myconn->options.sql_select_limit : "") ; + j["conn"]["sql_safe_updates"] = ( client_myds->myconn->options.sql_safe_updates ? client_myds->myconn->options.sql_safe_updates : "") ; + j["conn"]["collation_connection"] = ( client_myds->myconn->options.collation_connection ? client_myds->myconn->options.collation_connection : "") ; + j["conn"]["net_write_timeout"] = ( client_myds->myconn->options.net_write_timeout ? client_myds->myconn->options.net_write_timeout : "") ; + j["conn"]["max_join_size"] = ( client_myds->myconn->options.max_join_size ? client_myds->myconn->options.max_join_size : "") ; j["conn"]["charset"] = client_myds->myconn->options.charset; j["conn"]["sql_log_bin"] = client_myds->myconn->options.sql_log_bin; j["conn"]["autocommit"] = client_myds->myconn->options.autocommit; @@ -962,6 +976,15 @@ void MySQL_Session::generate_proxysql_internal_session_json(json &j) { j["backends"][i]["conn"]["sql_mode"] = ( _myconn->options.sql_mode ? _myconn->options.sql_mode : "") ; j["backends"][i]["conn"]["sql_mode_sent"] = _myds->myconn->options.sql_mode_sent; j["backends"][i]["conn"]["time_zone"] = ( _myconn->options.time_zone ? _myconn->options.time_zone : "") ; + j["backends"][i]["conn"]["isolation_level"] = ( _myconn->options.isolation_level ? _myconn->options.isolation_level : "") ; + j["backends"][i]["conn"]["character_set_results"] = ( _myconn->options.character_set_results ? _myconn->options.character_set_results : "") ; + j["backends"][i]["conn"]["session_track_gtids"] = ( _myconn->options.session_track_gtids ? _myconn->options.session_track_gtids : "") ; + j["backends"][i]["conn"]["sql_auto_is_null"] = ( _myconn->options.sql_auto_is_null ? _myconn->options.sql_auto_is_null : "") ; + j["backends"][i]["conn"]["sql_select_limit"] = ( _myconn->options.sql_select_limit ? _myconn->options.sql_select_limit : "") ; + j["backends"][i]["conn"]["sql_safe_updates"] = ( _myconn->options.sql_safe_updates ? _myconn->options.sql_safe_updates : "") ; + j["backends"][i]["conn"]["collation_connection"] = ( _myconn->options.collation_connection ? _myconn->options.collation_connection : "") ; + j["backends"][i]["conn"]["net_write_timeout"] = ( _myconn->options.net_write_timeout ? _myconn->options.net_write_timeout : "") ; + j["backends"][i]["conn"]["max_join_size"] = ( _myconn->options.max_join_size ? _myconn->options.max_join_size : "") ; //j["backend"][i]["conn"]["charset"] = _myds->myconn->options.charset; // not used for backend j["backends"][i]["conn"]["sql_log_bin"] = _myconn->options.sql_log_bin; j["backends"][i]["conn"]["init_connect"] = ( _myconn->options.init_connect ? _myconn->options.init_connect : ""); @@ -3678,6 +3701,7 @@ handler_again: if (handler_again___verify_backend_time_zone()) { goto handler_again; } +/* if (handler_again___verify_backend_isolation_level()) { goto handler_again; } @@ -3705,6 +3729,7 @@ handler_again: if (handler_again___verify_backend_max_join_size()) { goto handler_again; } +*/ } if (status==PROCESSING_STMT_EXECUTE) { CurrentQuery.mysql_stmt=myconn->local_stmts->find_backend_stmt_by_global_id(CurrentQuery.stmt_global_id); @@ -5230,6 +5255,80 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C exit_after_SetParse = true; } } + } else if (var == "sql_auto_is_null") { + std::string value1 = *values; + proxy_debug(PROXY_DEBUG_MYSQL_COM, 5, "Processing SET sql_auto_is_null value %s\n", value1.c_str()); + int __tmp_value = -1; + if ( + (strcasecmp(value1.c_str(),(char *)"0")==0) || + (strcasecmp(value1.c_str(),(char *)"false")==0) || + (strcasecmp(value1.c_str(),(char *)"off")==0) + ) { + __tmp_value = 0; + } else { + if ( + (strcasecmp(value1.c_str(),(char *)"1")==0) || + (strcasecmp(value1.c_str(),(char *)"true")==0) || + (strcasecmp(value1.c_str(),(char *)"on")==0) + ) { + __tmp_value = 1; + } + } + if (__tmp_value >= 0) { + proxy_debug(PROXY_DEBUG_MYSQL_COM, 7, "Processing SET sql_auto_is_null value %s\n", value1.c_str()); + uint32_t sql_auto_is_null_int=SpookyHash::Hash32(value1.c_str(),value1.length(),10); + if (client_myds->myconn->options.sql_auto_is_null_int != sql_auto_is_null_int) { + client_myds->myconn->options.sql_auto_is_null_int = sql_auto_is_null_int; + if (client_myds->myconn->options.sql_auto_is_null) { + free(client_myds->myconn->options.sql_auto_is_null); + } + proxy_debug(PROXY_DEBUG_MYSQL_COM, 5, "Changing connection sql_auto_is_null to %s\n", value1.c_str()); + client_myds->myconn->options.sql_auto_is_null=strdup(value1.c_str()); + } + } else { +#ifdef DEBUG + string nqn = string((char *)CurrentQuery.QueryPointer,CurrentQuery.QueryLength); + proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 5, "Locking hostgroup for query %s\n", nqn.c_str()); +#endif + *lock_hostgroup = true; + } + } else if (var == "sql_safe_updates") { + std::string value1 = *values; + proxy_debug(PROXY_DEBUG_MYSQL_COM, 5, "Processing SET sql_safe_updates value %s\n", value1.c_str()); + int __tmp_value = -1; + if ( + (strcasecmp(value1.c_str(),(char *)"0")==0) || + (strcasecmp(value1.c_str(),(char *)"false")==0) || + (strcasecmp(value1.c_str(),(char *)"off")==0) + ) { + __tmp_value = 0; + } else { + if ( + (strcasecmp(value1.c_str(),(char *)"1")==0) || + (strcasecmp(value1.c_str(),(char *)"true")==0) || + (strcasecmp(value1.c_str(),(char *)"on")==0) + ) { + __tmp_value = 1; + } + } + if (__tmp_value >= 0) { + proxy_debug(PROXY_DEBUG_MYSQL_COM, 7, "Processing SET sql_safe_updates value %s\n", value1.c_str()); + uint32_t sql_safe_updates_int=SpookyHash::Hash32(value1.c_str(),value1.length(),10); + if (client_myds->myconn->options.sql_safe_updates_int != sql_safe_updates_int) { + client_myds->myconn->options.sql_safe_updates_int = sql_safe_updates_int; + if (client_myds->myconn->options.sql_safe_updates) { + free(client_myds->myconn->options.sql_safe_updates); + } + proxy_debug(PROXY_DEBUG_MYSQL_COM, 5, "Changing connection sql_safe_updates to %s\n", value1.c_str()); + client_myds->myconn->options.sql_safe_updates=strdup(value1.c_str()); + } + } else { +#ifdef DEBUG + string nqn = string((char *)CurrentQuery.QueryPointer,CurrentQuery.QueryLength); + proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 5, "Locking hostgroup for query %s\n", nqn.c_str()); +#endif + *lock_hostgroup = true; + } } else if (var == "autocommit") { std::string value1 = *values; std::size_t found_at = value1.find("@"); @@ -5326,18 +5425,131 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C string nqn = string((char *)CurrentQuery.QueryPointer,CurrentQuery.QueryLength); proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 5, "Locking hostgroup for query %s\n", nqn.c_str()); #endif + *lock_hostgroup = true; + } + } else if (var == "max_join_size") { + std::string value1 = *values; + int vl = strlen(value1.c_str()); + const char *v = value1.c_str(); + bool only_digit_chars = true; + for (int i=0; imyconn->options.max_join_size_int != max_join_size_int) { + client_myds->myconn->options.max_join_size_int = max_join_size_int; + if (client_myds->myconn->options.max_join_size) { + free(client_myds->myconn->options.max_join_size); + } + proxy_debug(PROXY_DEBUG_MYSQL_COM, 5, "Changing connection max_join_size to %s\n", value1.c_str()); + client_myds->myconn->options.max_join_size=strdup(value1.c_str()); + } + } else { +#ifdef DEBUG + string nqn = string((char *)CurrentQuery.QueryPointer,CurrentQuery.QueryLength); + proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 5, "Locking hostgroup for query %s\n", nqn.c_str()); +#endif + *lock_hostgroup = true; + } + } else if (var == "net_write_timeout") { + std::string value1 = *values; + int vl = strlen(value1.c_str()); + const char *v = value1.c_str(); + bool only_digit_chars = true; + for (int i=0; imyconn->options.net_write_timeout_int != net_write_timeout_int) { + client_myds->myconn->options.net_write_timeout_int = net_write_timeout_int; + if (client_myds->myconn->options.net_write_timeout) { + free(client_myds->myconn->options.net_write_timeout); + } + proxy_debug(PROXY_DEBUG_MYSQL_COM, 5, "Changing connection net_write_timeout to %s\n", value1.c_str()); + client_myds->myconn->options.net_write_timeout=strdup(value1.c_str()); + } + } else { +#ifdef DEBUG + string nqn = string((char *)CurrentQuery.QueryPointer,CurrentQuery.QueryLength); + proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 5, "Locking hostgroup for query %s\n", nqn.c_str()); +#endif + *lock_hostgroup = true; + } + } else if (var == "sql_select_limit") { + std::string value1 = *values; + int vl = strlen(value1.c_str()); + const char *v = value1.c_str(); + bool only_digit_chars = true; + for (int i=0; imyconn->options.sql_select_limit_int != sql_select_limit_int) { + client_myds->myconn->options.sql_select_limit_int = sql_select_limit_int; + if (client_myds->myconn->options.sql_select_limit) { + free(client_myds->myconn->options.sql_select_limit); + } + proxy_debug(PROXY_DEBUG_MYSQL_COM, 5, "Changing connection sql_select_limit to %s\n", value1.c_str()); + client_myds->myconn->options.sql_select_limit=strdup(value1.c_str()); + } + } else { +#ifdef DEBUG + string nqn = string((char *)CurrentQuery.QueryPointer,CurrentQuery.QueryLength); + proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 5, "Locking hostgroup for query %s\n", nqn.c_str()); +#endif + *lock_hostgroup = true; + } + } else if (var == "collation_connection") { + std::string value1 = *values; + int vl = strlen(value1.c_str()); + const char *v = value1.c_str(); + bool only_normal_chars = true; + for (int i=0; imyconn->options.collation_connection_int != collation_connection_int) { + client_myds->myconn->options.collation_connection_int = collation_connection_int; + if (client_myds->myconn->options.collation_connection) { + free(client_myds->myconn->options.collation_connection); + } + proxy_debug(PROXY_DEBUG_MYSQL_COM, 5, "Changing connection collation_connection to %s\n", value1.c_str()); + client_myds->myconn->options.collation_connection=strdup(value1.c_str()); + } + } else { +#ifdef DEBUG + string nqn = string((char *)CurrentQuery.QueryPointer,CurrentQuery.QueryLength); + proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 5, "Locking hostgroup for query %s\n", nqn.c_str()); +#endif + *lock_hostgroup = true; } } else if (var == "character_set_results") { std::string value1 = *values; int vl = strlen(value1.c_str()); const char *v = value1.c_str(); - bool only_nomal_chars = true; - for (int i=0; imyconn->options.character_set_results_int != character_set_results_int) { @@ -5353,6 +5565,7 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C string nqn = string((char *)CurrentQuery.QueryPointer,CurrentQuery.QueryLength); proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 5, "Locking hostgroup for query %s\n", nqn.c_str()); #endif + *lock_hostgroup = true; } } else if (var == "names") { std::string value1 = *values++;