diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2016-02-01 09:54:51 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-02-01 09:54:51 +0100 |
commit | a96d53218420e9dd879bf65a2b963ea8d3126640 (patch) | |
tree | 1ba2b3669e2fb0fa416507729af29ffb05909b1d /core | |
parent | 2004d5349da5c9997942fa44717d0b8829673e48 (diff) | |
download | RustAndDust-a96d53218420e9dd879bf65a2b963ea8d3126640.zip RustAndDust-a96d53218420e9dd879bf65a2b963ea8d3126640.tar.gz |
DB: add loadState(int)
Diffstat (limited to 'core')
-rw-r--r-- | core/src/ch/asynk/rustanddust/DB.java | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/core/src/ch/asynk/rustanddust/DB.java b/core/src/ch/asynk/rustanddust/DB.java index dc41870..e2218c9 100644 --- a/core/src/ch/asynk/rustanddust/DB.java +++ b/core/src/ch/asynk/rustanddust/DB.java @@ -63,6 +63,7 @@ public class DB private static final String GET_GAME_ID = "select _id from games where _p1=%d and _p2=%d and _b=%d;"; private static final String INSERT_TURN = "insert into turns(_g,_p,hash,payload) values (%d,%d,'%s','%s'); update games set ts=current_timestamp where _id=%d;"; private static final String INSERT_STATE = "insert or replace into states(_g,hash,payload) values (%d,'%s','%s'); update games set ts=current_timestamp where _id=%d;"; + private static final String GET_STATE = "select payload from states where _g=%d;"; private static final String DB_CRT = TBL_CFG_CRT + TBL_PLAYERS_CRT + TBL_BATTLES_CRT + TBL_GAMES_CRT + TBL_TURNS_CRT + TBL_STATES_CRT; @@ -183,4 +184,17 @@ public class DB } return true; } + + public String loadState(int game) + { + String ret = null; + try { + DatabaseCursor cursor = db.rawQuery(String.format(GET_STATE, game)); + if (cursor.getCount() > 0) { + cursor.next(); + ret = cursor.getString(0); + } + } catch (SQLiteGdxException e) { RustAndDust.error("loadState"); } + return ret; + } } |