Skip to content

Commit

Permalink
[CONJ-597] default collation if server doesn't use utf8-like collatio…
Browse files Browse the repository at this point in the history
…n will be automatically set to utf8mb4 (was utf8mb3)
  • Loading branch information
rusher committed Apr 25, 2018
1 parent 8dfbde6 commit aa67c7b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -952,14 +952,26 @@ public boolean checkIfMaster() throws SQLException {
return isMasterConnection();
}

/**
* Default collation used for string exchanges with server
* (always use utf8)
*
* @param serverLanguage server default collation
* @return
*/
private byte decideLanguage(int serverLanguage) {
//force UTF8mb4 if possible, UTF8 if not.
if (serverLanguage == 45 //utf8mb4_general_ci
|| serverLanguage == 46 //utf8mb4_bin
|| (serverLanguage >= 224 && serverLanguage <= 247)) {
return (byte) serverLanguage;
} else if (serverLanguage == 33 //utf8_general_ci
|| serverLanguage == 83 //utf8_bin
|| serverLanguage == 223 //utf8_general_mysql500_ci
|| (serverLanguage >= 192 && serverLanguage <= 215)) {
return (byte) serverLanguage;
}
return 33; //utf8_general_ci
return (byte) 224; //UTF8MB4_UNICODE_CI;

}

Expand Down
6 changes: 1 addition & 5 deletions src/test/java/org/mariadb/jdbc/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -526,22 +526,18 @@ public void verificationEd25519AuthPlugin() throws Throwable {
try {
stmt.execute("CREATE USER verificationEd25519AuthPlugin@'%' IDENTIFIED "
+ "VIA ed25519 USING 'ZIgUREUg5PVgQ6LskhXmO+eZLS0nC8be6HPjYWR4YJY'");
stmt.execute("CREATE USER verificationEd25519AuthPlugin@'localhost' IDENTIFIED "
+ "VIA ed25519 USING 'ZIgUREUg5PVgQ6LskhXmO+eZLS0nC8be6HPjYWR4YJY'");
} catch (SQLException sqle) {
//already existing
}
stmt.execute("GRANT ALL on " + database + ".* to verificationEd25519AuthPlugin@'%'");
stmt.execute("GRANT ALL on " + database + ".* to verificationEd25519AuthPlugin@'localhost'");

String url = "jdbc:mariadb://" + hostname + ((port == 0) ? "" : ":" + port) + "/" + database
+ "?user=verificationEd25519AuthPlugin&password=secret";
+ "?user=verificationEd25519AuthPlugin&password=secret&debug=true";

try (Connection connection = openNewConnection(url)) {
//must have succeed
}
stmt.execute("drop user verificationEd25519AuthPlugin@'%'");
stmt.execute("drop user verificationEd25519AuthPlugin@'localhost'");
}


Expand Down

0 comments on commit aa67c7b

Please sign in to comment.