aboutsummaryrefslogtreecommitdiff
path: root/db.c
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-05-23 11:10:09 +0200
committertomsmeding <tom.smeding@gmail.com>2017-05-23 11:10:09 +0200
commitce2945afa3c4a477eef7fd0db3d58b6395c18774 (patch)
tree5ba753fd234a32eabe4fc602d524531b71ea5c8d /db.c
parente5b02b16ba83b55ef12dff19c18cb03d9e1fad32 (diff)
server: WIP firebase: Prevent duplicate firebase tokens
Diffstat (limited to 'db.c')
-rw-r--r--db.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/db.c b/db.c
index 12230c3..f4517f1 100644
--- a/db.c
+++ b/db.c
@@ -261,11 +261,18 @@ struct db_strings_list db_user_tokens(i64 userid){
bool db_add_token(i64 userid,const char *token){
assert(userid!=-1);
+
sqlite3_stmt *stmt;
+ SQLITE(prepare_v2,database,"delete from Firebase where token = ?",-1,&stmt,NULL);
+ SQLITE(bind_text,stmt,1,token,-1,SQLITE_STATIC);
+ bool success=sqlite3_step(stmt)==SQLITE_DONE;
+ SQLITE(finalize,stmt);
+ if(!success)return false;
+
SQLITE(prepare_v2,database,"insert into Firebase (user, token) values (?, ?)",-1,&stmt,NULL);
SQLITE(bind_int64,stmt,1,userid);
SQLITE(bind_text,stmt,2,token,-1,SQLITE_STATIC);
- bool success=sqlite3_step(stmt)==SQLITE_DONE;
+ success=sqlite3_step(stmt)==SQLITE_DONE;
SQLITE(finalize,stmt);
return success;
}