Skip to content

Commit

Permalink
Merge pull request #3461 from sysown/v2.x-3460
Browse files Browse the repository at this point in the history
Closes #3460: Fix failing test 'set_character_set'
  • Loading branch information
JavierJF authored May 26, 2021
2 parents bd3e96a + 7a6b8ca commit 3831a5e
Showing 1 changed file with 46 additions and 9 deletions.
55 changes: 46 additions & 9 deletions test/tap/tests/set_character_set-t.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
/**
* @file set_character_set-t.cpp
* @brief This test checks the proper behavior for 'SET CHARACTER SET'.
* @details The test performs several 'SET' operations in sequence for testing the correct behavior
* for 'SET CHARACTER SET', this are:
*
* 1. SET NAMES 'utf8'.
* 2. SET CHARACTER SET 'latin1'.
* 3. SET NAMES 'latin1'.
*
* After each of the operations several checks are performed for the following variables:
*
* * character_set_client
* * character_set_connection
* * character_set_results
* * character_set_database
*
* This checks are performed by means of the query:
*
* ```
* SELECT variable_value FROM global_variables WHERE variable_name='%s'
* ```
*
* For checking that this variables has changed or keep their values properly.
*
* NOTE: After "SET CHARACTER SET 'latin1'" has been issued, no checks are performed for
* 'character_set_connection' since, due to multiplexing and ProxySQL explicitely forgetting
* the value for 'character_set_connection' and 'collation_connection' (for more context
* see MySQL_Variables::client_set_value),the value for it is **unknown** and depends entirely
* of the backend connection selected. For more context see #3460.
*/

#include <cstdlib>
#include <cstdio>
#include <cstring>
Expand All @@ -16,13 +48,13 @@ int main(int argc, char** argv) {
if(cl.getEnv())
return exit_status();

plan(12);
plan(11);
diag("Testing SET CHARACTER SET");

MYSQL* mysql = mysql_init(NULL);
if (!mysql)
return exit_status();

if (mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "utf8")) {
fprintf(stderr, "File %s, line %d, Error: %s\n",
__FILE__, __LINE__, mysql_error(mysql));
Expand Down Expand Up @@ -92,11 +124,16 @@ int main(int argc, char** argv) {
show_variable(mysql, var_charset_database, var_value);
ok(var_value.compare("utf8") == 0, "Database character set is not changed. Actual %s", var_value.c_str()); // ok_6

show_variable(mysql, var_charset_connection, var_value);
ok(var_value.compare(db_charset_value) == 0, "Connection character set same as database charset. Actual %s", var_value.c_str()); // ok_7
/*
* NOTE: This check was disabled because trying to check 'character_set_connection' after issuing 'SET CHARACTER SET',
* when multiplexing is enabled is invalid, since the value is unknown. Check file top for more details.
*
* show_variable(mysql, var_charset_connection, var_value);
* ok(var_value.compare(db_charset_value) == 0, "Connection character set same as database charset. Actual %s", var_value.c_str()); // ok_
*/

show_variable(mysql, var_charset_results, var_value);
ok(var_value.compare("latin1") == 0, "Results character set is changed. Actual %s", var_value.c_str()); // ok_8
ok(var_value.compare("latin1") == 0, "Results character set is changed. Actual %s", var_value.c_str()); // ok_7

if (mysql_query(mysql, "set names latin1")) {
fprintf(stderr, "SET NAMES : Error: %s\n",
Expand All @@ -105,16 +142,16 @@ int main(int argc, char** argv) {
}

show_variable(mysql, var_charset_client, var_value);
ok(var_value.compare("latin1") == 0, "Client character set is correct. Actual %s", var_value.c_str()); // ok_9
ok(var_value.compare("latin1") == 0, "Client character set is correct. Actual %s", var_value.c_str()); // ok_8

show_variable(mysql, var_charset_connection, var_value);
ok(var_value.compare("latin1") == 0, "Set names changed connection character set. Actual %s", var_value.c_str()); // ok_10
ok(var_value.compare("latin1") == 0, "Set names changed connection character set. Actual %s", var_value.c_str()); // ok_9

show_variable(mysql, var_charset_results, var_value);
ok(var_value.compare("latin1") == 0, "Results character set is correct. Actual %s", var_value.c_str()); // ok_11
ok(var_value.compare("latin1") == 0, "Results character set is correct. Actual %s", var_value.c_str()); // ok_10

show_variable(mysql, var_charset_database, var_value);
ok(var_value.compare("utf8") == 0, "Database character set is not changed by set names. Actual %s", var_value.c_str()); // ok_12
ok(var_value.compare("utf8") == 0, "Database character set is not changed by set names. Actual %s", var_value.c_str()); // ok_11

mysql_close(mysql);

Expand Down

0 comments on commit 3831a5e

Please sign in to comment.