Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Fix a database issue (#73) causing multiple currencies to function im…
Browse files Browse the repository at this point in the history
…properly
  • Loading branch information
Flibio committed May 10, 2018
1 parent 74672f0 commit 68628ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ name=EconomyLite
owner=Flibio
inceptionYear=2015
currentYear=2018
version=2.14.1
version=2.14.2
apiVersion=7.1.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,34 @@ public PlayerServiceCommon(SqlManager manager, boolean h2) {
this.log = EconomyLite.getConfigManager().getValue(Boolean.class, false, "debug-logging");
if (manager.initialTestConnection()) {
manager.executeUpdate("CREATE TABLE IF NOT EXISTS economyliteplayers(uuid VARCHAR(36), balance DECIMAL(11,2), currency VARCHAR(1024))");
manager.executeUpdate("ALTER TABLE economyliteplayers ADD UNIQUE (uuid)");
}
repair();
// Create caches
balCache = CacheManager.create(logger, 64, 360);
exCache = CacheManager.create(logger, 128, 360);
topCache = CacheManager.create(logger, 16, 30);
}

public boolean repair() {
ResultSet rs = manager.executeQuery("show index from economyliteplayers where Column_name='uuid'").get();
try {
rs.next();
rs.getString(1);
logger.info("Repairing the database...");
} catch (Exception e) {
logger.debug("Database repairs not necessary!");
return false;
}
logger.info("Renaming database...");
manager.executeUpdate("RENAME TABLE economyliteplayers TO economyliteplayersold");
logger.info("Recreating database...");
manager.executeUpdate("CREATE TABLE economyliteplayers AS SELECT * FROM economyliteplayersold");
logger.info("Dropping database...");
manager.executeUpdate("DROP TABLE economyliteplayersold");
logger.info("Repairs complete!");
return true;
}

public boolean isWorking() {
return manager.testConnection();
}
Expand Down

0 comments on commit 68628ae

Please sign in to comment.