From 1c6155aeaf587dfdd959472c8ed71785ee54f1d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 9 Feb 2016 23:26:01 +0100 Subject: DB: add boolean storeConfig(String config), String loadConfig() --- core/src/ch/asynk/rustanddust/util/DB.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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); -- cgit v1.1-2-g2b99