aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-03-15 08:53:25 +0100
committertomsmeding <tom.smeding@gmail.com>2017-03-15 08:53:25 +0100
commitf1634688d62f2a6115739b65a311ab2b1cf79764 (patch)
treee185cbc4f53a27f0588d5660b9bec567d6f6fa66
parenta7a5b95990e0d6c1617c796dba2c45dab816161d (diff)
Remove useless UserNames table
-rw-r--r--db.c21
-rw-r--r--schema.sql9
2 files changed, 10 insertions, 20 deletions
diff --git a/db.c b/db.c
index 9efbd4a..068817c 100644
--- a/db.c
+++ b/db.c
@@ -131,21 +131,16 @@ struct db_room_list db_list_rooms(i64 userid){
i64 db_create_user(const char *name,const char *pass){
sqlite3_stmt *stmt;
- SQLITE(prepare_v2,database,"insert into Users (username, pass) values (?, ?)",-1,&stmt,NULL);
+ SQLITE(prepare_v2,database,"insert into Users (name, pass) values (?, ?)",-1,&stmt,NULL);
SQLITE(bind_text,stmt,1,name,-1,SQLITE_STATIC);
SQLITE(bind_text,stmt,2,pass,-1,SQLITE_STATIC);
- if(sqlite3_step(stmt)!=SQLITE_DONE)die_sqlite("sqlite3_step");
- SQLITE(finalize,stmt);
-
- i64 userid=sqlite3_last_insert_rowid(database);
-
- SQLITE(prepare_v2,database,"insert into UserNames (name, user) values (?, ?)",-1,&stmt,NULL);
- SQLITE(bind_text,stmt,1,name,-1,SQLITE_STATIC);
- SQLITE(bind_int64,stmt,2,userid);
- if(sqlite3_step(stmt)!=SQLITE_DONE)die_sqlite("sqlite3_step");
+ bool success=sqlite3_step(stmt)==SQLITE_DONE;
SQLITE(finalize,stmt);
-
- return userid;
+ if(success){
+ return sqlite3_last_insert_rowid(database);
+ } else {
+ return -1;
+ }
}
char* db_get_pass(i64 userid){
@@ -164,7 +159,7 @@ char* db_get_pass(i64 userid){
i64 db_find_user(const char *name){
sqlite3_stmt *stmt;
- SQLITE(prepare_v2,database,"select user from UserNames where name = ?",-1,&stmt,NULL);
+ SQLITE(prepare_v2,database,"select id from Users where name = ?",-1,&stmt,NULL);
SQLITE(bind_text,stmt,1,name,-1,SQLITE_STATIC);
i64 userid=-1;
if(sqlite3_step(stmt)==SQLITE_ROW){
diff --git a/schema.sql b/schema.sql
index 9f6da9e..321cb38 100644
--- a/schema.sql
+++ b/schema.sql
@@ -16,15 +16,10 @@ create table Members (
create table Users (
id integer primary key,
- username text,
+ name text,
pass text
);
-
-create table UserNames (
- name text primary key,
- user integer,
- foreign key(user) references Users(id) on delete cascade
-);
+create unique index users_name_index on Users(name);
create table Messages (
id integer primary key,