MXS-2899: Update charset only when successful

By updating the server charset only when we successfully query it, the
charset will not change due to network connectivity problems.
This commit is contained in:
Markus Mäkelä 2020-02-26 07:43:40 +02:00
parent 0614a44a4d
commit e180c20055
No known key found for this signature in database
GPG Key ID: 5CE746D557ACC499
3 changed files with 9 additions and 11 deletions

View File

@ -158,10 +158,11 @@ void mxs_mysql_set_log_statements(bool enable);
bool mxs_mysql_get_log_statements();
/**
* Get default server character set
* Update default server character set from @@global.character_set_server
*
* @return The numeric identifier of `@@global.character_set_server`
* @param mysql The connection handle
* @param server The server to modify
*/
uint8_t mxs_mysql_get_character_set(MYSQL* mysql);
void mxs_update_server_charset(MYSQL* mysql, SERVER* server);
MXS_END_DECLS

View File

@ -208,7 +208,7 @@ MYSQL* mxs_mysql_real_connect(MYSQL* con, SERVER* server, const char* user, cons
if (mysql)
{
/** Copy the server charset */
server->charset = mxs_mysql_get_character_set(mysql);
mxs_update_server_charset(mysql, server);
if (listener && mysql_get_ssl_cipher(con) == NULL)
{
@ -437,16 +437,15 @@ bool mxs_mysql_get_log_statements()
return this_unit.log_statements;
}
uint8_t mxs_mysql_get_character_set(MYSQL* mysql)
void mxs_update_server_charset(MYSQL* mysql, SERVER* server)
{
uint8_t charset = 8; // Default is latin1 with the ID 8
const char* CHARSET_QUERY =
"SELECT co.id FROM information_schema.collations AS co "
"JOIN information_schema.character_sets AS cs "
"ON (co.collation_name = cs.default_collate_name) "
"WHERE cs.character_set_name=@@global.character_set_server;";
if (mysql_query(mysql, CHARSET_QUERY) == 0)
if (mxs_mysql_query(mysql, CHARSET_QUERY) == 0)
{
if (auto res = mysql_use_result(mysql))
{
@ -454,13 +453,11 @@ uint8_t mxs_mysql_get_character_set(MYSQL* mysql)
{
if (row[0])
{
charset = atoi(row[0]);
server->charset = atoi(row[0]);
}
}
mysql_free_result(res);
}
}
return charset;
}

View File

@ -701,7 +701,7 @@ static bool check_server_permissions(SERVICE* service,
}
/** Copy the server charset */
server->charset = mxs_mysql_get_character_set(mysql);
mxs_update_server_charset(mysql, server);
if (server->version_string[0] == 0)
{