aboutsummaryrefslogtreecommitdiff
path: root/db.c
diff options
context:
space:
mode:
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;
}