From b6e7d309149cdb568e86df7d514174e1fb6a93e2 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Sun, 18 Aug 2019 22:19:31 +0200 Subject: [PATCH] Rename DB field identifiers.status to identifiers.active This better reflects what is the meaning of the value. If you need to manually create the table, use the following command, not the one from the previous commit. CREATE TABLE if not exists identifiers ( `userid` varchar ( 24 ) NOT NULL, `id` varchar ( 24 ) PRIMARY KEY NOT NULL, `name` varchar ( 24 ), `active` INTEGER NOT NULL DEFAULT 1, FOREIGN KEY(`userid`) REFERENCES `users`(`id`) ); --- coffee_db.py | 18 +++++++++--------- coffee_db.sql | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/coffee_db.py b/coffee_db.py index 5c41d51..072fe92 100644 --- a/coffee_db.py +++ b/coffee_db.py @@ -32,11 +32,11 @@ def add_user_identifier(uid, iid, name): # Try to remove old relation of identifier # As 'delete or ignore' does not exist, workaround is used - res = c.execute("select * from identifiers where id = ? and status = ?", (iid, 0, )) + res = c.execute("select * from identifiers where id = ? and active = ?", (iid, 0, )) # This is True when some rows were found before; delete old relation if res.fetchone(): - res = c.execute("delete from identifiers where id = ? and status = ?", (iid, 0, )) + res = c.execute("delete from identifiers where id = ? and active = ?", (iid, 0, )) # Add new relation res = c.execute("insert into identifiers (userid, id, name) values (?, ?, ?)", (uid, iid, name, )) @@ -45,7 +45,7 @@ def add_user_identifier(uid, iid, name): def disable_user_identifier(uid, iid): conn, c = open_db() - c.execute("update identifiers set status = ? where userid = ? and id = ?", (0, uid, iid, )) + c.execute("update identifiers set active = ? where userid = ? and id = ?", (0, uid, iid, )) close_db(conn) def get_name(uid): @@ -59,7 +59,7 @@ def get_name(uid): def get_uid(iid): conn, c = open_db() res = list(c.execute(""" - select userid from identifiers where id = ? and status + select userid from identifiers where id = ? and active """, (iid,))) close_db(conn) @@ -84,7 +84,7 @@ def list_users(): def list_user_identifiers(uid): conn, c = open_db() res = list(c.execute(""" - select * from identifiers where userid = ? and status + select * from identifiers where userid = ? and active """, (uid,))) close_db(conn) return res @@ -124,10 +124,10 @@ def coffee_flavors(uid=None, days=0, start=0): query += " where date(time) between date('now', 'localtime', '-"+ str(days+start-1) +" days') and date('now', 'localtime', '-"+ str(start) +" days')" if uid is not None: - query += " and ids.userid = ? and ids.status" + query += " and ids.userid = ? and ids.active" variables.append(uid) elif uid is not None: - query += " where ids.userid = ? and ids.status" + query += " where ids.userid = ? and ids.active" variables.append(uid) res = list(c.execute(""" @@ -158,7 +158,7 @@ def coffee_history(uid=None): select strftime('%s', ds.d),count(c.flavor),c.flavor from (select num,date('now', 'localtime', -num || ' days') as d from days) ds left join - (select date(time, 'localtime') as time,flavor from coffees co left join identifiers ids on co.id = ids.id where ids.userid = ? and ids.status) c + (select date(time, 'localtime') as time,flavor from coffees co left join identifiers ids on co.id = ids.id where ids.userid = ? and ids.active) c on d = date(c.time) group by d, c.flavor """ , (uid,))) @@ -173,7 +173,7 @@ def drink_count(uid=None, start=None, stop=None): clauses = [] if uid is not None: - clauses.append("ids.userid = ? and ids.status") + clauses.append("ids.userid = ? and ids.active") args.append(uid) if start is not None: diff --git a/coffee_db.sql b/coffee_db.sql index c7c88d1..5c65d11 100644 --- a/coffee_db.sql +++ b/coffee_db.sql @@ -40,6 +40,6 @@ CREATE TABLE if not exists identifiers ( `userid` varchar ( 24 ) NOT NULL, `id` varchar ( 24 ) PRIMARY KEY NOT NULL, `name` varchar ( 24 ), - `status` INTEGER NOT NULL DEFAULT 1, + `active` INTEGER NOT NULL DEFAULT 1, FOREIGN KEY(`userid`) REFERENCES `users`(`id`) ); -- 2.39.2