From ce2945afa3c4a477eef7fd0db3d58b6395c18774 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Tue, 23 May 2017 11:10:09 +0200 Subject: server: WIP firebase: Prevent duplicate firebase tokens --- db.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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; } -- cgit v1.2.3-70-g09d2