summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-02-23 18:39:27 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-02-23 18:39:27 +0100
commit8a82cc838397a9b1d57a541a9a34a30b3a8ba54a (patch)
treeca74bcc196064810f94e0ae5e320cebfd7adeba9 /core/src/ch/asynk/rustanddust
parent912ff43e9f59946fa304e0220070e04079bf2414 (diff)
downloadRustAndDust-8a82cc838397a9b1d57a541a9a34a30b3a8ba54a.zip
RustAndDust-8a82cc838397a9b1d57a541a9a34a30b3a8ba54a.tar.gz
DB: add gameExists(int, int)
Diffstat (limited to 'core/src/ch/asynk/rustanddust')
-rw-r--r--core/src/ch/asynk/rustanddust/util/DB.java16
1 files changed, 15 insertions, 1 deletions
diff --git a/core/src/ch/asynk/rustanddust/util/DB.java b/core/src/ch/asynk/rustanddust/util/DB.java
index cef1e52..c386efc 100644
--- a/core/src/ch/asynk/rustanddust/util/DB.java
+++ b/core/src/ch/asynk/rustanddust/util/DB.java
@@ -68,7 +68,8 @@ public class DB
private static final String GET_PLAYER_ID_FROM_GMAIL = "select _id from players where gmail='%s';";
private static final String UPDATE_BATTLE = "insert or replace into battles values (%d,'%s');";
private static final String INSERT_GAME = "insert or ignore into games(_p1,_p2,_b,m) values (%d,%d,%d,%d);";
- private static final String GET_GAME_ID = "select _id from games where _p1=%d and _p2=%d and _b=%d;";
+ 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'); 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 UPDATE_GAME = "update games set _p1=%d, _p2=%d, ts=current_timestamp where _id=%d;";
@@ -293,6 +294,19 @@ public class DB
} catch (SQLiteGdxException e) { r.dispose(); RustAndDust.error("loadGames"); }
}
+ public int gameExists(int battle, int mode)
+ {
+ int ret = NO_RECORD;
+ try {
+ DatabaseCursor cursor = query(String.format(GET_GAME_ID2, battle, mode));
+ if (cursor.getCount() > 0) {
+ cursor.next();
+ ret = cursor.getInt(0);
+ }
+ } catch (SQLiteGdxException e) { RustAndDust.error("loadConfig"); }
+ return ret;
+ }
+
private void exec(String sql) throws SQLiteGdxException
{
if (debug) RustAndDust.debug(" SQL " + sql);