summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-02-09 23:26:01 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-02-09 23:26:01 +0100
commit1c6155aeaf587dfdd959472c8ed71785ee54f1d2 (patch)
tree81f90baf2a197da0033080ddd4f2e6d1439381a2 /core/src/ch/asynk/rustanddust
parentbcd63319edac1643c6a66b47e4f833158a3b3155 (diff)
downloadRustAndDust-1c6155aeaf587dfdd959472c8ed71785ee54f1d2.zip
RustAndDust-1c6155aeaf587dfdd959472c8ed71785ee54f1d2.tar.gz
DB: add boolean storeConfig(String config), String loadConfig()
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 50a20a2..4006d86 100644
--- a/core/src/ch/asynk/rustanddust/util/DB.java
+++ b/core/src/ch/asynk/rustanddust/util/DB.java
@@ -56,6 +56,8 @@ public class DB
+ " foreign key (_g) references games(_id)"
+ ");";
+ 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,firstname,lastname) values ('%s','%s','%s','%s');";
private static final String GET_PLAYER_ID = "select _id from players where hash='%s';";
private static final String UPDATE_BATTLE = "insert or replace into battles values (%d,'%s');";
@@ -93,6 +95,30 @@ public class DB
return hash;
}
+ public boolean storeConfig(String config)
+ {
+ try {
+ db.execSQL(String.format(INSERT_CONFIG, config));
+ } catch (SQLiteGdxException e) {
+ RustAndDust.error("storeConfig");
+ return false;
+ }
+ return true;
+ }
+
+ public String loadConfig()
+ {
+ String ret = null;
+ try {
+ DatabaseCursor cursor = db.rawQuery(GET_CONFIG);
+ if (cursor.getCount() > 0) {
+ cursor.next();
+ ret = cursor.getString(0);
+ }
+ } catch (SQLiteGdxException e) { RustAndDust.error("loadConfig"); }
+ return ret;
+ }
+
public String storePlayer(String gmail, String firstname, String lastname)
{
String hash = getDigest(gmail + firstname + lastname);