[MDEV-18281] COM_RESET_CONNECTION change the connection encoding Created: 2019-01-17  Updated: 2019-02-02  Resolved: 2019-02-02

Status: Closed
Project: MariaDB Server
Component/s: Protocol
Affects Version/s: 10.2.21, 10.3.12
Fix Version/s: 10.2.22, 10.3.13

Type: Bug Priority: Major
Reporter: Diego Dupin Assignee: Vladislav Vaintroub
Resolution: Fixed Votes: 2
Labels: None


 Description   

When creating a connection, a connector indicates the charset to use for communication in initial handshake packet.

After a COM_RESET_CONNECTION connection charset is reinitialized not to the one indicated in initial handshake packet, but to another value, character_set_server.

example to reproduced :

public void test() throws SQLException {
    try (Connection connection = DriverManager.getConnection("jdbc:mariadb://localhost:3306/testj?user=root&useResetConnection=true")) {
      Statement stmt = connection.createStatement();
      showCharacterVariables(stmt);
      ((MariaDbConnection)connection).reset();
 
      showCharacterVariables(stmt);
    }
  }
 
  public void showCharacterVariables(Statement stmt) throws SQLException {
    ResultSet rs = stmt.executeQuery("SHOW VARIABLES LIKE 'character_%'");
    while (rs.next()) {
      System.out.println(rs.getString(1) + " " + rs.getString(2));
    }
    System.out.println("----------------------------------------------");
  }

returns :

character_set_client utf8mb4
character_set_connection utf8mb4
character_set_database latin1
character_set_filesystem binary
character_set_results utf8mb4
character_set_server latin1
character_set_system utf8
character_sets_dir c:\Program Files\MariaDB 10.2\share\charsets\
----------------------------------------------
character_set_client latin1
character_set_connection latin1
character_set_database latin1
character_set_filesystem binary
character_set_results latin1
character_set_server utf8
character_set_system utf8
character_sets_dir c:\Program Files\MariaDB 10.2\share\charsets\
----------------------------------------------

Initial charset transmitted during initial-handshake-packet must be saved and reapplyed, not character_set_server value.
another part that is less important, but resetting connection normally would reset the database to the one set in the same handshake packet



 Comments   
Comment by Sylvain Leroux [ 2019-01-29 ]

I can confirm the problem. I've posted a reproducible use case on StackOverflow before finding this issue:
https://stackoverflow.com/questions/54428189/inconsistent-character-encoding-in-results-when-querying-mariadb-from-node

Generated at Thu Feb 08 08:42:54 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.