Use mariadb protocol if using its connector

MariaDB enforces this to ensure the selection of the correct driver.

Fixes #724
This commit is contained in:
games647
2022-02-09 12:57:07 +01:00
parent 3665e15920
commit d581b34005
2 changed files with 13 additions and 4 deletions

View File

@ -231,7 +231,7 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
databaseConfig.setUsername(config.get("username", ""));
databaseConfig.setPassword(config.getString("password"));
storage = new MySQLStorage(this, host, port, database, databaseConfig, useSSL);
storage = new MySQLStorage(this, driver, host, port, database, databaseConfig, useSSL);
}
try {

View File

@ -5,13 +5,22 @@ import com.zaxxer.hikari.HikariConfig;
public class MySQLStorage extends SQLStorage {
public MySQLStorage(FastLoginCore<?, ?, ?> core, String host, int port, String database, HikariConfig config,
boolean useSSL) {
public MySQLStorage(FastLoginCore<?, ?, ?> core, String driver, String host, int port, String database,
HikariConfig config,boolean useSSL) {
super(core,
"mysql://" + host + ':' + port + '/' + database,
buildJDBCUrl(driver, host, port, database),
setParams(config, useSSL));
}
private static String buildJDBCUrl(String driver, String host, int port, String database) {
String protocol = "mysql";
if (driver.contains("mariadb")) {
protocol = "mariadb";
}
return protocol + "://" + host + ':' + port + '/' + database;
}
private static HikariConfig setParams(HikariConfig config, boolean useSSL) {
// Require SSL on the server if requested in config - this will also verify certificate
// Those values are deprecated in favor of sslMode