]> git.mxchange.org Git - quix0rs-apt-p2p.git/commitdiff
Workaround old sqlite not having 'select count(distinct key)'.
authorCameron Dale <camrdale@gmail.com>
Thu, 20 Mar 2008 22:47:14 +0000 (15:47 -0700)
committerCameron Dale <camrdale@gmail.com>
Thu, 20 Mar 2008 22:47:14 +0000 (15:47 -0700)
apt_p2p_Khashmir/db.py

index 4ee9cb38068d69978828ca8c328b36d053fe15cc..bd777b60e78f65126859645a29152b49aeab80bd 100644 (file)
@@ -154,11 +154,16 @@ class DB:
         @return: the number of distinct keys and total values in the database
         """
         c = self.conn.cursor()
-        c.execute("SELECT COUNT(DISTINCT key) as num_keys, COUNT(value) as num_values FROM kv")
-        keys, values = 0, 0
+        c.execute("SELECT COUNT(value) as num_values FROM kv")
+        values = 0
         row = c.fetchone()
         if row:
-            keys, values = row[0], row[1]
+            values = row[0]
+        c.execute("SELECT COUNT(key) as num_keys FROM (SELECT DISTINCT key FROM kv)")
+        keys = 0
+        row = c.fetchone()
+        if row:
+            keys = row[0]
         return keys, values
 
 class TestDB(unittest.TestCase):