diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-05-23 11:10:09 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-05-23 11:10:09 +0200 |
commit | ce2945afa3c4a477eef7fd0db3d58b6395c18774 (patch) | |
tree | 5ba753fd234a32eabe4fc602d524531b71ea5c8d /db.c | |
parent | e5b02b16ba83b55ef12dff19c18cb03d9e1fad32 (diff) |
server: WIP firebase: Prevent duplicate firebase tokens
Diffstat (limited to 'db.c')
-rw-r--r-- | db.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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; } |