From 44ee524ecef4a75f116656184c77bf9c9826b038 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Tue, 9 Aug 2016 00:19:29 +0200 Subject: [PATCH] Forgot that NULL values are actually always seen as distinct values in SQL. Why does SQLite even allow NULL in PRIMARY KEY? --- dbtools/__init__.py | 4 ++-- filler.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dbtools/__init__.py b/dbtools/__init__.py index 46d440a..e616238 100644 --- a/dbtools/__init__.py +++ b/dbtools/__init__.py @@ -75,12 +75,12 @@ class dbObject: return setuptools.getDate(str(self.getNext()["%s(SUBSTR(timestamp,0,11))" % mode])) def getFollowers(db): - db.executeQuery("SELECT id FROM followers WHERE `until` IS NULL;") + db.executeQuery("SELECT id FROM followers WHERE `until` = 0;") for i in db.getAll(): yield i[0] def getFollowing(db): - db.executeQuery("SELECT id FROM following WHERE `until` IS NULL;") + db.executeQuery("SELECT id FROM following WHERE `until` = 0;") for i in db.getAll(): yield i[0] diff --git a/filler.py b/filler.py index 499c352..ccfe413 100755 --- a/filler.py +++ b/filler.py @@ -62,13 +62,13 @@ def getFollowers(db=dbtools.dbHelper(), two=twitools.twObject(), firstrun=False) for follower in new: if follower not in current: - db.executeQuery("INSERT INTO followers VALUES('%s', %i, NULL)" % (follower, int(time.time()))) + db.executeQuery("INSERT INTO followers VALUES('%s', %i, 0)" % (follower, int(time.time()))) print("New follower: %s" % follower) gained += 1 for follower in current: if follower not in new: - db.executeQuery("UPDATE followers SET `until` = %i WHERE `id` = '%s' AND `until` IS NULL" % (int(time.time()), follower)) + db.executeQuery("UPDATE followers SET `until` = %i WHERE `id` = '%s' AND `until` = 0" % (int(time.time()), follower)) print("Lost follower: %s" % follower) lost += 1 @@ -88,13 +88,13 @@ def getFollowing(db=dbtools.dbHelper(), two=twitools.twObject(), firstrun=False) for following in new: if following not in current: - db.executeQuery("INSERT INTO following VALUES('%s', %i, NULL)" % (following, int(time.time()))) + db.executeQuery("INSERT INTO following VALUES('%s', %i, 0)" % (following, int(time.time()))) print("You started following: %s" % following) gained += 1 for following in current: if following not in new: - db.executeQuery("UPDATE following SET `until` = %i WHERE `id` = '%s' AND `until` IS NULL" % (int(time.time()), following)) + db.executeQuery("UPDATE following SET `until` = %i WHERE `id` = '%s' AND `until` = 0" % (int(time.time()), following)) print("You no longer follow: %s" % following) lost += 1