]> rtime.felk.cvut.cz Git - coffee/coffee-flask.git/commitdiff
Include constant SQL values directly in queries
authorMichal Sojka <michal.sojka@cvut.cz>
Mon, 19 Aug 2019 06:16:31 +0000 (08:16 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Mon, 19 Aug 2019 06:16:31 +0000 (08:16 +0200)
It makes the query slightly more readable.

coffee_db.py

index 072fe92f19e937bd30158c1b22db5013d8d7b0fc..f0ad4078bfe3c34223721ce539266bc06b624318 100644 (file)
@@ -32,11 +32,12 @@ 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 active = ?", (iid, 0, ))
+        res = c.execute("select * from identifiers where id = ? and active = 0", (iid, ))
 
         # This is True when some rows were found before; delete old relation
         if res.fetchone():
-            res = c.execute("delete from identifiers where id = ? and active = ?", (iid, 0, ))
+            print("Deleting uid:%s id:%s" % (uid, iid))
+            res = c.execute("delete from identifiers where id = ? and active = 0", (iid, ))
 
         # Add new relation
         res = c.execute("insert into identifiers (userid, id, name) values (?, ?, ?)", (uid, iid, name, ))
@@ -45,7 +46,7 @@ def add_user_identifier(uid, iid, name):
 
 def disable_user_identifier(uid, iid):
     conn, c = open_db()
-    c.execute("update identifiers set active = ? where userid = ? and id = ?", (0, uid, iid, ))
+    c.execute("update identifiers set active = 0 where userid = ? and id = ?", (uid, iid, ))
     close_db(conn)
 
 def get_name(uid):