From e525e8eb8cc4536857146a1579f79d2d7793522d Mon Sep 17 00:00:00 2001 From: Cameron Dale Date: Thu, 20 Mar 2008 15:47:14 -0700 Subject: [PATCH] Workaround old sqlite not having 'select count(distinct key)'. --- apt_p2p_Khashmir/db.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apt_p2p_Khashmir/db.py b/apt_p2p_Khashmir/db.py index 4ee9cb3..bd777b6 100644 --- a/apt_p2p_Khashmir/db.py +++ b/apt_p2p_Khashmir/db.py @@ -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): -- 2.30.2