diff options
author | Helmut Grohne <helmut@subdivi.de> | 2013-03-07 08:43:15 +0100 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2013-03-07 08:43:15 +0100 |
commit | ac4c52c7a4501e90ed53f3ca5780bec4551a8c9f (patch) | |
tree | b6d065fd8386b26ea1b642dfc79b086386a543b3 | |
parent | d6638c18872db382a8d1045b6de1f9438c8a25fa (diff) | |
download | debian-dedup-ac4c52c7a4501e90ed53f3ca5780bec4551a8c9f.tar.gz |
enable enforcing foreign keys
-rwxr-xr-x | autoimport.py | 6 | ||||
-rwxr-xr-x | importpkg.py | 5 | ||||
-rwxr-xr-x | update_sharing.py | 1 |
3 files changed, 8 insertions, 4 deletions
diff --git a/autoimport.py b/autoimport.py index a7ea5ff..bc2c6aa 100755 --- a/autoimport.py +++ b/autoimport.py @@ -14,6 +14,7 @@ def main(): urlbase = sys.argv[1] db = sqlite3.connect("test.sqlite3") cur = db.cursor() + cur.execute("PRAGMA foreign_keys = ON;") cur.execute("SELECT package, version FROM package;") knownpkgs = dict((row[0], row[1]) for row in cur.fetchall()) @@ -37,7 +38,10 @@ def main(): delpkgs = set(knownpkgs) - distpkgs print("clearing packages %s" % " ".join(delpkgs)) - cur.execute("PRAGMA foreign_keys=1;") + cur.executemany("DELETE FROM sharing WHERE package1 = ?", + ((pkg,) for pkg in delpkgs)) + cur.executemany("DELETE FROM sharing WHERE package2 = ?", + ((pkg,) for pkg in delpkgs)) cur.executemany("DELETE FROM content WHERE package = ?;", ((pkg,) for pkg in delpkgs)) cur.executemany("DELETE FROM dependency WHERE package = ?;", diff --git a/importpkg.py b/importpkg.py index ef368c2..aae9a7f 100755 --- a/importpkg.py +++ b/importpkg.py @@ -109,6 +109,7 @@ def get_hashes(tar): def process_package(db, filelike): cur = db.cursor() + cur.execute("PRAGMA foreign_keys = ON;") af = ArReader(filelike) af.read_magic() state = "start" @@ -144,11 +145,9 @@ def process_package(db, filelike): if row and version_compare(row[0], version) > 0: return # already seen a newer package - cur.execute("DELETE FROM package WHERE package = ?;", - (package,)) cur.execute("DELETE FROM content WHERE package = ?;", (package,)) - cur.execute("INSERT INTO package (package, version, architecture, source) VALUES (?, ?, ?, ?);", + cur.execute("INSERT OR REPLACE INTO package (package, version, architecture, source) VALUES (?, ?, ?, ?);", (package, version, architecture, source)) depends = control.relations.get("depends", []) depends = set(dep[0]["name"].encode("ascii") diff --git a/update_sharing.py b/update_sharing.py index dd12e5b..2ed532b 100755 --- a/update_sharing.py +++ b/update_sharing.py @@ -40,6 +40,7 @@ def process_pkgdict(cursor, pkgdict): def main(): db = sqlite3.connect("test.sqlite3") cur = db.cursor() + cur.execute("PRAGMA foreign_keys = ON;") cur.execute("DELETE FROM sharing;") readcur = db.cursor() readcur.execute("SELECT hash FROM content GROUP BY hash HAVING count(*) > 1;") |