From eaba84e444c77495a5654b600c599646b8aa1aed Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 23 Jul 2013 23:23:41 +0200 Subject: schema: identify hash values by an integer This one is a bit more complex, than the other transformations, because the new hashvalue table has to be cleaned with a trigger. During a test import the -wal file exploded. The resulting db is similar in size to the original. --- readyaml.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'readyaml.py') diff --git a/readyaml.py b/readyaml.py index bb8ac54..007ed96 100755 --- a/readyaml.py +++ b/readyaml.py @@ -45,9 +45,16 @@ def readyaml(db, stream): cur.execute("INSERT INTO content (pid, filename, size) VALUES (?, ?, ?);", (pid, entry["name"], entry["size"])) cid = cur.lastrowid - cur.executemany("INSERT INTO hash (cid, function, hash) VALUES (?, ?, ?);", - ((cid, func, hexhash) - for func, hexhash in entry["hashes"].items())) + for func, hexhash in entry["hashes"].items(): + cur.execute("SELECT id FROM hashvalue WHERE hash = ?;", (hexhash,)) + row = cur.fetchone() + if row: + hid = row[0] + else: + cur.execute("INSERT INTO hashvalue (hash) VALUES (?);", (hexhash,)) + hid = cur.lastrowid + cur.execute("INSERT INTO hash (cid, function, hid) VALUES (?, ?, ?);", + (cid, func, hid)) raise ValueError("missing commit block") def main(): -- cgit v1.2.3