summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-02-29 13:24:35 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-02-29 13:24:35 +0100
commit4d8a62502c87c283c7dfd53a2ce6a9ddbea403e6 (patch)
tree699594fb7a34b44dc7a08a3aa969e34eec20fc7a /core/src/ch/asynk/rustanddust
parenta39a6c5802856c7b7246eb9631ef04f75a021675 (diff)
downloadRustAndDust-4d8a62502c87c283c7dfd53a2ce6a9ddbea403e6.zip
RustAndDust-4d8a62502c87c283c7dfd53a2ce6a9ddbea403e6.tar.gz
DB: add getTurns(int)
Diffstat (limited to 'core/src/ch/asynk/rustanddust')
-rw-r--r--core/src/ch/asynk/rustanddust/util/DB.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/core/src/ch/asynk/rustanddust/util/DB.java b/core/src/ch/asynk/rustanddust/util/DB.java
index 0855f3f..aedc9fd 100644
--- a/core/src/ch/asynk/rustanddust/util/DB.java
+++ b/core/src/ch/asynk/rustanddust/util/DB.java
@@ -72,6 +72,7 @@ public class DB
private static final String GET_GAME_ID = "select _id from games where _p1=%d and _p2=%d and _b=%d and m=%d;";
private static final String GET_GAME_ID2 = "select _id from games where _b=%d and m=%d;";
private static final String INSERT_TURN = "insert into turns(_g,_p,hash,payload) values (%d,%d,'%s','%s');";
+ private static final String GET_TURNS = "select payload from turns where _g=%d order by _id;";
private static final String INSERT_STATE = "insert or replace into states(_g,hash,payload) values (%d,'%s','%s');";
private static final String UPDATE_GAME = "update games set _p1=%d, _p2=%d, ts=current_timestamp where _id=%d;";
private static final String GET_STATE = "select payload from states where _g=%d;";
@@ -253,6 +254,27 @@ public class DB
return true;
}
+ public String getTurns(int game)
+ {
+ String ret = null;
+ try {
+ DatabaseCursor cursor = query(String.format(GET_TURNS, game));
+ int n = cursor.getCount();
+ if (n <= 0)
+ return null;
+
+ StringBuilder builder = new StringBuilder();
+ builder.append("[");
+ while(cursor.next()) {
+ builder.append(cursor.getString(0));
+ builder.append(",");
+ }
+ builder.setCharAt((builder.length() - 1), ']');
+ ret = builder.toString();
+ } catch (SQLiteGdxException e) { RustAndDust.error("getGameId"); }
+ return ret;
+ }
+
public boolean storeState(int game, int p1, int p2, String payload)
{
RustAndDust.debug("storeState");