summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-02-01 09:54:10 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-02-01 09:54:10 +0100
commit2004d5349da5c9997942fa44717d0b8829673e48 (patch)
tree22128ef705bd9b0eebd3a841160a14ec9d8e3912 /core/src/ch/asynk/rustanddust
parent1a8e3783822f646bdf0411acc1ae27982d71e253 (diff)
downloadRustAndDust-2004d5349da5c9997942fa44717d0b8829673e48.zip
RustAndDust-2004d5349da5c9997942fa44717d0b8829673e48.tar.gz
DB: use instert or ingnore for players and games tables
Diffstat (limited to 'core/src/ch/asynk/rustanddust')
-rw-r--r--core/src/ch/asynk/rustanddust/DB.java13
1 files changed, 5 insertions, 8 deletions
diff --git a/core/src/ch/asynk/rustanddust/DB.java b/core/src/ch/asynk/rustanddust/DB.java
index a49612f..dc41870 100644
--- a/core/src/ch/asynk/rustanddust/DB.java
+++ b/core/src/ch/asynk/rustanddust/DB.java
@@ -36,7 +36,7 @@ public class DB
private static final String TBL_GAMES_CRT = "create table if not exists"
+ " games ( _id integer primary key autoincrement,"
+ " _p1 integer not null, _p2 integer not null, _b integer not null,"
- + " int mode not null, ts datetime default current_timestamp,"
+ + " m integer not null, ts datetime default current_timestamp,"
+ " foreign key (_p1) references players(_id),"
+ " foreign key (_p2) references players(_id),"
+ " foreign key (_b) references battles(_id),"
@@ -56,10 +56,10 @@ public class DB
+ " foreign key (_g) references games(_id)"
+ ");";
- private static final String INSERT_PLAYER = "insert into players(hash,gmail,firstname,lastname) values ('%s','%s','%s','%s');";
+ 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');";
- private static final String INSERT_GAME = "insert into games(_p1,_p2,_b,m) values (%d,%d,%d,%d);";
+ 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 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;";
@@ -97,9 +97,7 @@ public class DB
String hash = getDigest(gmail + firstname + lastname);
if (hash == null) return null;
try {
- if (getPlayerId(hash) == NO_RECORDS) {
- db.execSQL(String.format(INSERT_PLAYER, hash, gmail, firstname, lastname));
- }
+ db.execSQL(String.format(INSERT_PLAYER, hash, gmail, firstname, lastname));
} catch (SQLiteGdxException e) {
RustAndDust.error("storePlayer");
return null;
@@ -137,8 +135,7 @@ public class DB
public void storeGame(int you, int opponent, int battle, int mode)
{
try {
- if (getGameId(you, opponent, battle, mode) == NO_RECORDS)
- db.execSQL(String.format(INSERT_GAME, you, opponent, battle, mode));
+ db.execSQL(String.format(INSERT_GAME, you, opponent, battle, mode));
} catch (SQLiteGdxException e) { RustAndDust.error("storeGame"); }
}