Improve charset selection

The charset sent in the handshake is now done with the following
priorities:

* First Master server
* Last Slave server
* First Running server or Down server whose charset is known

The change is that server in the Down state to which we've successfully
connected to can also be used as the charset source. This, in addition
with an "empty" default charset, helps avoid the use of the default latin1
charset unless absolutely necessary.
This commit is contained in:
Markus Mäkelä
2020-03-11 23:46:35 +02:00
parent caf3b4cf75
commit 291d2e987f
3 changed files with 17 additions and 8 deletions

View File

@ -235,17 +235,18 @@ uint8_t get_charset(SERVER_REF* servers)
for (SERVER_REF* s = servers; s; s = s->next)
{
if (server_ref_is_active(s))
if (server_ref_is_active(s) && s->server->charset)
{
// The reference is active and we've queried the charset it uses
if (s->server->is_master())
{
// Master found, stop searching
rval = s->server->charset;
break;
}
else if (s->server->is_slave() || (s->server->is_running() && rval == 0))
else if (s->server->is_slave() || rval == 0)
{
// Slaves precede Running servers
// Slaves precede Running servers and server that are Down but whose charset is known
rval = s->server->charset;
}
}