From eb38f61fb1c490f7fe28f3ea95b3bfe6aea2ae36 Mon Sep 17 00:00:00 2001 From: Kaige Ye Date: Fri, 13 Aug 2021 21:44:01 +0800 Subject: [PATCH 1/2] add query-attributes options to mysql client --- client/mysql.cc | 7 +++++++ include/mysql.h | 1 + include/sql_common.h | 1 + sql-common/client.cc | 11 ++++++++++- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/client/mysql.cc b/client/mysql.cc index c76536f29f2c..5912215f22a2 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -164,6 +164,7 @@ static bool ignore_errors = false, wait_flag = false, quick = false, show_warnings = false, executing_query = false, interrupted_query = false, ignore_spaces = false, sigint_received = false, opt_syslog = false, opt_binhex = false; +static bool opt_query_attributes = true; static bool opt_binary_as_hex_set_explicitly = false; static bool debug_info_flag, debug_check_flag; static bool column_types_flag; @@ -1911,6 +1912,11 @@ static struct my_option my_long_options[] = { "when processing output from mysqlbinlog that may contain blobs.", &opt_binary_mode, &opt_binary_mode, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr}, + {"query-attributes", 0, + "Enable/Disable query attributes in server/client protocol. " + "Query attributes is enabled by default. Disable with --disable-query-attributes.", + &opt_query_attributes, &opt_query_attributes, nullptr, GET_BOOL, NO_ARG, 1, 0, 0, + nullptr, 0, nullptr}, {"connect-expired-password", 0, "Notify the server that this client is prepared to handle expired " "password sandbox mode.", @@ -4633,6 +4639,7 @@ static bool init_connection_options(MYSQL *mysql) { if (opt_bind_addr) mysql_options(mysql, MYSQL_OPT_BIND, opt_bind_addr); if (opt_compress) mysql_options(mysql, MYSQL_OPT_COMPRESS, NullS); + if (!opt_query_attributes) mysql_options(mysql, MYSQL_OPT_QUERY_ATTRIBUTES, NullS); if (opt_compress_algorithm) mysql_options(mysql, MYSQL_OPT_COMPRESSION_ALGORITHMS, opt_compress_algorithm); diff --git a/include/mysql.h b/include/mysql.h index 4700d74b8534..c84b8bef9970 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -210,6 +210,7 @@ enum mysql_option { MYSQL_OPT_TLS_CIPHERSUITES, MYSQL_OPT_COMPRESSION_ALGORITHMS, MYSQL_OPT_ZSTD_COMPRESSION_LEVEL, + MYSQL_OPT_QUERY_ATTRIBUTES, MYSQL_OPT_LOAD_DATA_LOCAL_DIR }; diff --git a/include/sql_common.h b/include/sql_common.h index d8dd5c727c2e..66049ee0a36b 100644 --- a/include/sql_common.h +++ b/include/sql_common.h @@ -144,6 +144,7 @@ struct st_mysql_options_extention { char *tls_version; /* TLS version option */ long ssl_ctx_flags; /* SSL ctx options flag */ unsigned int ssl_mode; + bool disable_query_attributes; unsigned int retry_count; unsigned int ssl_fips_mode; /* SSL fips mode for enforced encryption.*/ char *tls_ciphersuites; diff --git a/sql-common/client.cc b/sql-common/client.cc index b8050f2b1a7a..cf6f0e62c511 100644 --- a/sql-common/client.cc +++ b/sql-common/client.cc @@ -4138,6 +4138,11 @@ static void cli_calculate_client_flag(MYSQL *mysql, const char *db, mysql->client_flag &= ~CLIENT_SSL; mysql->options.extension->ssl_mode = SSL_MODE_DISABLED; } + + if (mysql->options.extension && + mysql->options.extension->disable_query_attributes) { + mysql->client_flag &= ~CLIENT_QUERY_ATTRIBUTES; + } } /** @@ -7288,7 +7293,7 @@ static int mysql_prepare_com_query_parameters(MYSQL *mysql, MYSQL_EXTENSION *ext = MYSQL_EXTENSION_PTR(mysql); assert(ext); bool send_named_params = - (mysql->server_capabilities & CLIENT_QUERY_ATTRIBUTES) != 0; + (mysql->client_flag & mysql->server_capabilities & CLIENT_QUERY_ATTRIBUTES) != 0; *pret_data = nullptr; *pret_data_length = 0; if (send_named_params) { @@ -8005,6 +8010,10 @@ int STDCALL mysql_options(MYSQL *mysql, enum mysql_option option, case MYSQL_REPORT_DATA_TRUNCATION: mysql->options.report_data_truncation = *static_cast(arg); break; + case MYSQL_OPT_QUERY_ATTRIBUTES: + ENSURE_EXTENSIONS_PRESENT(&mysql->options); + mysql->options.extension->disable_query_attributes = true; + break; case MYSQL_OPT_RECONNECT: mysql->reconnect = *static_cast(arg); break; From ec8f6a05314f2b53f0c9201e706ad38885e6b5d1 Mon Sep 17 00:00:00 2001 From: Kaige Ye Date: Sun, 15 Aug 2021 20:37:59 +0800 Subject: [PATCH 2/2] fix abi_check --- include/mysql.h.pp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/mysql.h.pp b/include/mysql.h.pp index 39ebd0fcb93e..70b73edcfaa8 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -448,6 +448,7 @@ MYSQL_OPT_TLS_CIPHERSUITES, MYSQL_OPT_COMPRESSION_ALGORITHMS, MYSQL_OPT_ZSTD_COMPRESSION_LEVEL, + MYSQL_OPT_QUERY_ATTRIBUTES, MYSQL_OPT_LOAD_DATA_LOCAL_DIR }; struct st_mysql_options_extention;