diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2016-02-29 12:50:35 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-02-29 12:50:35 +0100 |
commit | a39a6c5802856c7b7246eb9631ef04f75a021675 (patch) | |
tree | 5b80b26ad0bf91d236261918c8ea4f1354cac015 /core/src/ch/asynk/rustanddust | |
parent | fc1cec6a65c5567533557ef19d8f2ad5a80e0bf3 (diff) | |
download | RustAndDust-a39a6c5802856c7b7246eb9631ef04f75a021675.zip RustAndDust-a39a6c5802856c7b7246eb9631ef04f75a021675.tar.gz |
DB: get ready for schema update
Diffstat (limited to 'core/src/ch/asynk/rustanddust')
-rw-r--r-- | core/src/ch/asynk/rustanddust/util/DB.java | 26 |
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 { |