X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=apt_p2p_Khashmir%2Fdb.py;h=a7962566cc5a07eb99c0744b65eb81389f8b45bc;hb=d563aab35fc0fd1fab59e0f6d594fbb05735cf21;hp=4ee9cb38068d69978828ca8c328b36d053fe15cc;hpb=0ebb5e0abe0740bbd24675e4ac83c48f48c00b0c;p=quix0rs-apt-p2p.git diff --git a/apt_p2p_Khashmir/db.py b/apt_p2p_Khashmir/db.py index 4ee9cb3..a796256 100644 --- a/apt_p2p_Khashmir/db.py +++ b/apt_p2p_Khashmir/db.py @@ -150,15 +150,20 @@ class DB: def keyStats(self): """Count the total number of keys and values in the database. - @rtype: (C{int), C{int}) + @rtype: (C{int}, C{int}) @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): @@ -177,6 +182,7 @@ class TestDB(unittest.TestCase): def test_Value(self): self.store.storeValue(self.key, self.key) + self.failUnlessEqual(self.store.countValues(self.key), 1) val = self.store.retrieveValues(self.key) self.failUnlessEqual(len(val), 1) self.failUnlessEqual(val[0], self.key)