Fix renaming of database tables.

https://github.com/BentoBoxWorld/BentoBox/issues/1536
This commit is contained in:
tastybento 2020-10-08 16:03:57 -07:00
parent 4609881542
commit 9f1d610dfd
2 changed files with 4 additions and 2 deletions

View File

@ -83,7 +83,8 @@ public class SQLDatabaseHandler<T> extends AbstractJSONDatabaseHandler<T> {
protected void createSchema() {
if (sqlConfig.renameRequired()) {
// Transition from the old table name
try (PreparedStatement pstmt = connection.prepareStatement(sqlConfig.getRenameTableSQL())) {
String sql = sqlConfig.getRenameTableSQL().replace("[oldTableName]", sqlConfig.getOldTableName()).replace("[tableName]", sqlConfig.getTableName());
try (PreparedStatement pstmt = connection.prepareStatement(sql)) {
pstmt.execute();
} catch (SQLException e) {
plugin.logError("Could not rename " + sqlConfig.getOldTableName() + " for data object " + dataObject.getCanonicalName() + " " + e.getMessage());

View File

@ -64,7 +64,8 @@ public class SQLiteDatabaseHandler<T> extends SQLDatabaseHandler<T> {
try (ResultSet resultSet = pstmt.executeQuery()) {
if (resultSet.next() && resultSet.getBoolean(1)) {
// Transition from the old table name
try (PreparedStatement pstmt2 = getConnection().prepareStatement(getSqlConfig().getRenameTableSQL())) {
String sql = getSqlConfig().getRenameTableSQL().replace("[oldTableName]", getSqlConfig().getOldTableName().replace("[tableName]", getSqlConfig().getTableName()));
try (PreparedStatement pstmt2 = getConnection().prepareStatement(sql)) {
pstmt2.execute();
} catch (SQLException e) {
plugin.logError("Could not rename " + getSqlConfig().getOldTableName() + " for data object " + dataObject.getCanonicalName() + " " + e.getMessage());