Skip to content

Commit

Permalink
Fix creating tables in sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokkonaut committed May 7, 2019
1 parent 35b4708 commit 13b6945
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/main/java/com/griefcraft/sql/PhysDB.java
Expand Up @@ -657,13 +657,33 @@ public void setInternal(String key, String value) {
}
}

private boolean hasInternalTable() throws SQLException {
PreparedStatement statement = null;
if (getType() == Type.SQLite) {
statement = prepare("SELECT name FROM sqlite_master WHERE name = ?");
} else if (getType() == Type.MySQL) {
statement = prepare("SHOW TABLES LIKE ?");
} else {
return false;
}
statement.setString(1, prefix + "internal");
ResultSet set = statement.executeQuery();
boolean hasTable = set.next();
set.close();
return hasTable;
}

/**
* Load the database internal version
*
* @return
*/
public int loadDatabaseVersion() {
try {
if (!hasInternalTable()) {
return -1;
}

PreparedStatement statement = prepare("SELECT value FROM " + prefix + "internal WHERE name = ?");
statement.setString(1, "version");

Expand All @@ -688,7 +708,7 @@ public int loadDatabaseVersion() {

// ok
statement.executeUpdate();
} catch (SQLException ex) {
} catch (Exception ex) {
}
}

Expand All @@ -702,6 +722,10 @@ public int loadDatabaseVersion() {
*/
public int loadEntityLockingDatabaseVersion() {
try {
if (!hasInternalTable()) {
return -1;
}

PreparedStatement statement = prepare("SELECT value FROM " + prefix + "internal WHERE name = ?");
statement.setString(1, "entityversion");

Expand All @@ -726,7 +750,7 @@ public int loadEntityLockingDatabaseVersion() {

// ok
statement.executeUpdate();
} catch (SQLException ex) {
} catch (Exception ex) {
}
}

Expand Down

0 comments on commit 13b6945

Please sign in to comment.