mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 15:16:45 +01:00
Fix #1320
This commit is contained in:
parent
6ee2d7d823
commit
5a47f9fa86
@ -900,14 +900,22 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
*/
|
*/
|
||||||
private void checkStructure() {
|
private void checkStructure() {
|
||||||
|
|
||||||
Statement statement = null;
|
PreparedStatement statement = null;
|
||||||
|
Statement createStatement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
connection = connectionPool.getConnection(POOL_FETCH_TIMEOUT);
|
connection = connectionPool.getConnection(POOL_FETCH_TIMEOUT);
|
||||||
statement = connection.createStatement();
|
statement = connection.prepareStatement("SELECT table_name FROM INFORMATION_SCHEMA.TABLES"
|
||||||
|
+ " WHERE table_schema = ?"
|
||||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "users` ("
|
+ " AND table_name = ?");
|
||||||
|
statement.setString(1, Config.getInstance().getMySQLDatabaseName());
|
||||||
|
statement.setString(2, tablePrefix + "users");
|
||||||
|
resultSet = statement.executeQuery();
|
||||||
|
if (!resultSet.next()) {
|
||||||
|
createStatement = connection.createStatement();
|
||||||
|
createStatement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "users` ("
|
||||||
+ "`id` int(10) unsigned NOT NULL AUTO_INCREMENT,"
|
+ "`id` int(10) unsigned NOT NULL AUTO_INCREMENT,"
|
||||||
+ "`user` varchar(40) NOT NULL,"
|
+ "`user` varchar(40) NOT NULL,"
|
||||||
+ "`uuid` varchar(36) NULL DEFAULT NULL,"
|
+ "`uuid` varchar(36) NULL DEFAULT NULL,"
|
||||||
@ -915,12 +923,28 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
+ "PRIMARY KEY (`id`),"
|
+ "PRIMARY KEY (`id`),"
|
||||||
+ "UNIQUE KEY `user` (`user`),"
|
+ "UNIQUE KEY `user` (`user`),"
|
||||||
+ "UNIQUE KEY `uuid` (`uuid`)) DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;");
|
+ "UNIQUE KEY `uuid` (`uuid`)) DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;");
|
||||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "huds` ("
|
createStatement.close();
|
||||||
|
}
|
||||||
|
resultSet.close();
|
||||||
|
statement.setString(1, Config.getInstance().getMySQLDatabaseName());
|
||||||
|
statement.setString(2, tablePrefix + "huds");
|
||||||
|
resultSet = statement.executeQuery();
|
||||||
|
if (!resultSet.next()) {
|
||||||
|
createStatement = connection.createStatement();
|
||||||
|
createStatement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "huds` ("
|
||||||
+ "`user_id` int(10) unsigned NOT NULL,"
|
+ "`user_id` int(10) unsigned NOT NULL,"
|
||||||
+ "`mobhealthbar` varchar(50) NOT NULL DEFAULT '" + Config.getInstance().getMobHealthbarDefault() + "',"
|
+ "`mobhealthbar` varchar(50) NOT NULL DEFAULT '" + Config.getInstance().getMobHealthbarDefault() + "',"
|
||||||
+ "PRIMARY KEY (`user_id`)) "
|
+ "PRIMARY KEY (`user_id`)) "
|
||||||
+ "DEFAULT CHARSET=latin1;");
|
+ "DEFAULT CHARSET=latin1;");
|
||||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "cooldowns` ("
|
createStatement.close();
|
||||||
|
}
|
||||||
|
resultSet.close();
|
||||||
|
statement.setString(1, Config.getInstance().getMySQLDatabaseName());
|
||||||
|
statement.setString(2, tablePrefix + "cooldowns");
|
||||||
|
resultSet = statement.executeQuery();
|
||||||
|
if (!resultSet.next()) {
|
||||||
|
createStatement = connection.createStatement();
|
||||||
|
createStatement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "cooldowns` ("
|
||||||
+ "`user_id` int(10) unsigned NOT NULL,"
|
+ "`user_id` int(10) unsigned NOT NULL,"
|
||||||
+ "`taming` int(32) unsigned NOT NULL DEFAULT '0',"
|
+ "`taming` int(32) unsigned NOT NULL DEFAULT '0',"
|
||||||
+ "`mining` int(32) unsigned NOT NULL DEFAULT '0',"
|
+ "`mining` int(32) unsigned NOT NULL DEFAULT '0',"
|
||||||
@ -936,7 +960,15 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
+ "`blast_mining` int(32) unsigned NOT NULL DEFAULT '0',"
|
+ "`blast_mining` int(32) unsigned NOT NULL DEFAULT '0',"
|
||||||
+ "PRIMARY KEY (`user_id`)) "
|
+ "PRIMARY KEY (`user_id`)) "
|
||||||
+ "DEFAULT CHARSET=latin1;");
|
+ "DEFAULT CHARSET=latin1;");
|
||||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "skills` ("
|
createStatement.close();
|
||||||
|
}
|
||||||
|
resultSet.close();
|
||||||
|
statement.setString(1, Config.getInstance().getMySQLDatabaseName());
|
||||||
|
statement.setString(2, tablePrefix + "skills");
|
||||||
|
resultSet = statement.executeQuery();
|
||||||
|
if (!resultSet.next()) {
|
||||||
|
createStatement = connection.createStatement();
|
||||||
|
createStatement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "skills` ("
|
||||||
+ "`user_id` int(10) unsigned NOT NULL,"
|
+ "`user_id` int(10) unsigned NOT NULL,"
|
||||||
+ "`taming` int(10) unsigned NOT NULL DEFAULT '0',"
|
+ "`taming` int(10) unsigned NOT NULL DEFAULT '0',"
|
||||||
+ "`mining` int(10) unsigned NOT NULL DEFAULT '0',"
|
+ "`mining` int(10) unsigned NOT NULL DEFAULT '0',"
|
||||||
@ -953,7 +985,15 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
+ "`alchemy` int(10) unsigned NOT NULL DEFAULT '0',"
|
+ "`alchemy` int(10) unsigned NOT NULL DEFAULT '0',"
|
||||||
+ "PRIMARY KEY (`user_id`)) "
|
+ "PRIMARY KEY (`user_id`)) "
|
||||||
+ "DEFAULT CHARSET=latin1;");
|
+ "DEFAULT CHARSET=latin1;");
|
||||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "experience` ("
|
createStatement.close();
|
||||||
|
}
|
||||||
|
resultSet.close();
|
||||||
|
statement.setString(1, Config.getInstance().getMySQLDatabaseName());
|
||||||
|
statement.setString(2, tablePrefix + "experience");
|
||||||
|
resultSet = statement.executeQuery();
|
||||||
|
if (!resultSet.next()) {
|
||||||
|
createStatement = connection.createStatement();
|
||||||
|
createStatement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "experience` ("
|
||||||
+ "`user_id` int(10) unsigned NOT NULL,"
|
+ "`user_id` int(10) unsigned NOT NULL,"
|
||||||
+ "`taming` int(10) unsigned NOT NULL DEFAULT '0',"
|
+ "`taming` int(10) unsigned NOT NULL DEFAULT '0',"
|
||||||
+ "`mining` int(10) unsigned NOT NULL DEFAULT '0',"
|
+ "`mining` int(10) unsigned NOT NULL DEFAULT '0',"
|
||||||
@ -970,21 +1010,34 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
+ "`alchemy` int(10) unsigned NOT NULL DEFAULT '0',"
|
+ "`alchemy` int(10) unsigned NOT NULL DEFAULT '0',"
|
||||||
+ "PRIMARY KEY (`user_id`)) "
|
+ "PRIMARY KEY (`user_id`)) "
|
||||||
+ "DEFAULT CHARSET=latin1;");
|
+ "DEFAULT CHARSET=latin1;");
|
||||||
|
createStatement.close();
|
||||||
|
}
|
||||||
|
resultSet.close();
|
||||||
|
statement.close();
|
||||||
|
|
||||||
for (UpgradeType updateType : UpgradeType.values()) {
|
for (UpgradeType updateType : UpgradeType.values()) {
|
||||||
checkDatabaseStructure(connection, updateType);
|
checkDatabaseStructure(connection, updateType);
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMO.p.getLogger().info("Killing orphans");
|
mcMMO.p.getLogger().info("Killing orphans");
|
||||||
statement.executeUpdate("DELETE FROM `" + tablePrefix + "experience` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "users` `u` WHERE `" + tablePrefix + "experience`.`user_id` = `u`.`id`)");
|
createStatement = connection.createStatement();
|
||||||
statement.executeUpdate("DELETE FROM `" + tablePrefix + "huds` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "users` `u` WHERE `" + tablePrefix + "huds`.`user_id` = `u`.`id`)");
|
createStatement.executeUpdate("DELETE FROM `" + tablePrefix + "experience` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "users` `u` WHERE `" + tablePrefix + "experience`.`user_id` = `u`.`id`)");
|
||||||
statement.executeUpdate("DELETE FROM `" + tablePrefix + "cooldowns` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "users` `u` WHERE `" + tablePrefix + "cooldowns`.`user_id` = `u`.`id`)");
|
createStatement.executeUpdate("DELETE FROM `" + tablePrefix + "huds` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "users` `u` WHERE `" + tablePrefix + "huds`.`user_id` = `u`.`id`)");
|
||||||
statement.executeUpdate("DELETE FROM `" + tablePrefix + "skills` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "users` `u` WHERE `" + tablePrefix + "skills`.`user_id` = `u`.`id`)");
|
createStatement.executeUpdate("DELETE FROM `" + tablePrefix + "cooldowns` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "users` `u` WHERE `" + tablePrefix + "cooldowns`.`user_id` = `u`.`id`)");
|
||||||
|
createStatement.executeUpdate("DELETE FROM `" + tablePrefix + "skills` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "users` `u` WHERE `" + tablePrefix + "skills`.`user_id` = `u`.`id`)");
|
||||||
}
|
}
|
||||||
catch (SQLException ex) {
|
catch (SQLException ex) {
|
||||||
printErrors(ex);
|
printErrors(ex);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
if (resultSet != null) {
|
||||||
|
try {
|
||||||
|
resultSet.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
if (statement != null) {
|
if (statement != null) {
|
||||||
try {
|
try {
|
||||||
statement.close();
|
statement.close();
|
||||||
@ -993,6 +1046,14 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (createStatement != null) {
|
||||||
|
try {
|
||||||
|
createStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
try {
|
try {
|
||||||
connection.close();
|
connection.close();
|
||||||
|
Loading…
Reference in New Issue
Block a user