Author: fw Date: 2005-09-15 15:39:01 +0000 (Thu, 15 Sep 2005) New Revision: 2004 Modified: lib/python/security_db.py Log: lib/python/security_db.py (DB.calculateVulnerabilities): Use INSERT OR REPLACE to simplify the code considerably. Modified: lib/python/security_db.py ==================================================================--- lib/python/security_db.py 2005-09-15 15:15:46 UTC (rev 2003) +++ lib/python/security_db.py 2005-09-15 15:39:01 UTC (rev 2004) @@ -775,25 +775,6 @@ % (b.source_file, b.source_line, b_package)) if self.verbose: - print " create temporary tables" - cursor.execute( - """CREATE TEMPORARY TABLE tmp_bug_releases - (bug_name TEXT NOT NULL, - release TEXT NOT NULL, - PRIMARY KEY (bug_name, release))""") - for (bug_name, release) in list(cursor.execute( - """SELECT DISTINCT bug_name, release FROM package_notes - WHERE release <> ''''""")): - data = [(bug_name, release), - (bug_name, release + ''-security'')] - try: - data.append((bug_name, self.nicknames[release])) - except KeyError: - pass - cursor.executemany("INSERT INTO tmp_bug_releases VALUES (?, ?)", - data) - - if self.verbose: print " remove old status" cursor.execute("DELETE FROM source_package_status") cursor.execute("DELETE FROM binary_package_status") @@ -801,32 +782,25 @@ print " calculate package status" print " source packages (unqualified)" - # If there is a single package note qualified with a specific - # release, ignore all the unqualified annotations (even for - # other packages). This is implemented by looking at the - # tmp_bug_releases table. - cursor.execute( """INSERT INTO source_package_status SELECT n.id, p.rowid, n.fixed_version IS NULL OR p.version_id < n.fixed_version_id FROM package_notes AS n, source_packages AS p - WHERE n.release = '''' AND p.name = n.package - AND NOT EXISTS (SELECT * FROM tmp_bug_releases AS t - WHERE t.bug_name = n.bug_name - AND t.release = p.release)""") + WHERE n.release = '''' AND p.name = n.package""") + + # Release annotations always override previous results, + # therefore we use INSERT OR REPLACE. + if self.verbose: print " source packages (qualified)" cursor.execute( - """INSERT INTO source_package_status + """INSERT OR REPLACE INTO source_package_status SELECT n.id, p.rowid, n.fixed_version IS NULL OR p.version_id < n.fixed_version_id FROM package_notes AS n, source_packages AS p WHERE p.name = n.package - AND (p.release = n.release - OR p.release = (n.release || ''-security'') - OR p.release = (SELECT nickname FROM nicknames - WHERE realname = n.release))""") + AND p.release = n.release""") if self.verbose: print " binary packages (from source packages)" @@ -835,12 +809,10 @@ SELECT n.id, p.rowid, n.fixed_version IS NULL OR p.source_version_id < n.fixed_version_id FROM package_notes AS n, binary_packages AS p - WHERE n.release = '''' AND p.source = n.package - AND NOT EXISTS (SELECT * FROM tmp_bug_releases AS t - WHERE t.bug_name = n.bug_name - AND t.release = p.release)""") + WHERE n.release = '''' AND p.source = n.package""") + cursor.execute( - """INSERT INTO binary_package_status + """INSERT OR REPLACE INTO binary_package_status SELECT n.id, p.rowid, n.fixed_version IS NULL OR p.source_version_id < n.fixed_version_id FROM package_notes AS n, binary_packages AS p @@ -859,23 +831,16 @@ n.fixed_version IS NULL OR p.version_id < n.fixed_version_id FROM package_notes AS n, binary_packages AS p WHERE n.release = '''' AND p.name = n.package - AND (NOT EXISTS (SELECT * FROM tmp_bug_releases AS t - WHERE t.bug_name = n.bug_name - AND t.release = p.release)) AND n.package_kind = ''binary''""") if self.verbose: print " binary packages (qualified)" cursor.execute( - """INSERT INTO binary_package_status + """INSERT OR REPLACE INTO binary_package_status SELECT n.id, p.rowid, n.fixed_version IS NULL OR p.version_id < n.fixed_version_id FROM package_notes AS n, binary_packages AS p - WHERE p.name = n.package - AND (p.release = n.release - OR p.release = n.release || ''-security'' - OR p.release = (SELECT nickname FROM nicknames - WHERE realname = n.release)) + WHERE p.name = n.package AND p.release = n.release AND n.package_kind = ''binary''""") return result