summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk/rustanddust')
-rw-r--r--core/src/ch/asynk/rustanddust/util/DB.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/core/src/ch/asynk/rustanddust/util/DB.java b/core/src/ch/asynk/rustanddust/util/DB.java
index a6ad9fd..0855f3f 100644
--- a/core/src/ch/asynk/rustanddust/util/DB.java
+++ b/core/src/ch/asynk/rustanddust/util/DB.java
@@ -61,6 +61,7 @@ public class DB
+ ");";
private static final String FEED_CONFIG = " insert or ignore into config values(\"version\", " + DB_SCHEMA_VERSION + ");";
+ private static final String CHECK_VERSION = "select (value=%d) from config where key='version';";
private static final String INSERT_CONFIG = "insert or replace into config(key, value) values ('options','%s');";
private static final String GET_CONFIG = "select value from config where key='options';";
private static final String INSERT_PLAYER = "insert or ignore into players(hash,gmail,name) values ('%s','%s','%s');";
@@ -98,6 +99,15 @@ public class DB
db.openOrCreateDatabase();
} catch (SQLiteGdxException e) { RustAndDust.error("openOrCreateDatabase"); }
+ Boolean version = checkVersion();
+ if(version == null)
+ createTables();
+ else if (version == false)
+ System.err.println("TODO update schema");
+ }
+
+ private void createTables()
+ {
try {
exec(TBL_CFG_CRT);
exec(TBL_PLAYERS_CRT);
@@ -121,6 +131,22 @@ public class DB
return hash;
}
+ public Boolean checkVersion()
+ {
+ Boolean ret = false;
+ try {
+ DatabaseCursor cursor = query(String.format(CHECK_VERSION, DB_SCHEMA_VERSION ));
+ if (cursor.getCount() > 0) {
+ cursor.next();
+ ret = (cursor.getInt(0) == 1);
+ }
+ } catch (SQLiteGdxException e) {
+ RustAndDust.error("checkVersion");
+ return null;
+ }
+ return ret;
+ }
+
public boolean storeConfig(String config)
{
try {