X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=db_access.py;h=afbddeeba1cd32cc35b933719b571f95c13f0869;hb=bce58243846a5683b77f586c7210723b47227a60;hp=741e54b80b0c4aa2575428d36661d4b74cf49f26;hpb=d52ebffcc7af210985d90ffc58e7ecc4141dd8a8;p=dak.git diff --git a/db_access.py b/db_access.py index 741e54b8..afbddeeb 100644 --- a/db_access.py +++ b/db_access.py @@ -1,6 +1,6 @@ # DB access fucntions # Copyright (C) 2000, 2001 James Troup -# $Id: db_access.py,v 1.6 2001-03-02 02:24:33 troup Exp $ +# $Id: db_access.py,v 1.10 2001-11-24 18:42:05 troup Exp $ # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,12 +33,13 @@ location_id_cache = {}; maintainer_id_cache = {}; source_id_cache = {}; files_id_cache = {}; +maintainer_cache = {} ############################################################################################ def init (config, sql): global Cnf, projectB - + Cnf = config; projectB = sql; @@ -52,9 +53,9 @@ def get_suite_id (suite): q = projectB.query("SELECT id FROM suite WHERE suite_name = '%s'" % (suite)) ql = q.getresult(); - if ql == []: - return -1; - + if not ql: + return -1; + suite_id = ql[0][0]; suite_id_cache[suite] = suite_id @@ -68,9 +69,9 @@ def get_section_id (section): q = projectB.query("SELECT id FROM section WHERE section = '%s'" % (section)) ql = q.getresult(); - if ql == []: - return -1; - + if not ql: + return -1; + section_id = ql[0][0]; section_id_cache[section] = section_id @@ -84,9 +85,9 @@ def get_priority_id (priority): q = projectB.query("SELECT id FROM priority WHERE priority = '%s'" % (priority)) ql = q.getresult(); - if ql == []: - return -1; - + if not ql: + return -1; + priority_id = ql[0][0]; priority_id_cache[priority] = priority_id @@ -100,9 +101,9 @@ def get_override_type_id (type): q = projectB.query("SELECT id FROM override_type WHERE type = '%s'" % (type)); ql = q.getresult(); - if ql == []: - return -1; - + if not ql: + return -1; + override_type_id = ql[0][0]; override_type_id_cache[type] = override_type_id; @@ -116,9 +117,9 @@ def get_architecture_id (architecture): q = projectB.query("SELECT id FROM architecture WHERE arch_string = '%s'" % (architecture)) ql = q.getresult(); - if ql == []: + if not ql: return -1; - + architecture_id = ql[0][0]; architecture_id_cache[architecture] = architecture_id; @@ -127,11 +128,17 @@ def get_architecture_id (architecture): def get_archive_id (archive): global archive_id_cache + archive = string.lower(archive); + if archive_id_cache.has_key(archive): return archive_id_cache[archive] - q = projectB.query("SELECT id FROM archive WHERE name = '%s'" % (archive)) - archive_id = q.getresult()[0][0] + q = projectB.query("SELECT id FROM archive WHERE lower(name) = '%s'" % (archive)); + ql = q.getresult(); + if not ql: + return -1; + + archive_id = ql[0][0] archive_id_cache[archive] = archive_id return archive_id @@ -139,12 +146,14 @@ def get_archive_id (archive): def get_component_id (component): global component_id_cache + component = string.lower(component); + if component_id_cache.has_key(component): return component_id_cache[component] - q = projectB.query("SELECT id FROM component WHERE lower(name) = '%s'" % (string.lower(component))) + q = projectB.query("SELECT id FROM component WHERE lower(name) = '%s'" % (component)) ql = q.getresult(); - if ql == []: + if not ql: return -1; component_id = ql[0][0]; @@ -166,7 +175,11 @@ def get_location_id (location, component, archive): q = projectB.query("SELECT id FROM location WHERE path = '%s' AND component = %d AND archive = %d" % (location, component_id, archive_id)) else: q = projectB.query("SELECT id FROM location WHERE path = '%s' AND archive = %d" % (location, archive_id)) - location_id = q.getresult()[0][0] + ql = q.getresult(); + if not ql: + return -1; + + location_id = ql[0][0] location_id_cache[cache_key] = location_id return location_id @@ -221,7 +234,7 @@ def get_files_id (filename, size, md5sum, location_id): if ql: if len(ql) != 1: return -1; - ql = ql[0]; + ql = ql[0]; orig_size = int(ql[1]); orig_md5sum = ql[2]; if orig_size != size or orig_md5sum != md5sum: @@ -240,7 +253,7 @@ def set_files_id (filename, size, md5sum, location_id): cache_key = "%s~%d" % (filename, location_id); #print "INSERT INTO files (filename, size, md5sum, location) VALUES ('%s', %d, '%s', %d)" % (filename, long(size), md5sum, location_id); - projectB.query("INSERT INTO files (filename, size, md5sum, location) VALUES ('%s', %d, '%s', %d)" % (filename, long(size), md5sum, location_id)); + projectB.query("INSERT INTO files (filename, size, md5sum, location) VALUES ('%s', %d, '%s', %d)" % (filename, long(size), md5sum, location_id)); q = projectB.query("SELECT id FROM files WHERE id = currval('files_id_seq')"); ql = q.getresult()[0]; files_id_cache[cache_key] = ql[0] @@ -249,3 +262,13 @@ def set_files_id (filename, size, md5sum, location_id): ########################################################################################## +def get_maintainer (maintainer_id): + global maintainer_cache; + + if not maintainer_cache.has_key(maintainer_id): + q = projectB.query("SELECT name FROM maintainer WHERE id = %s" % (maintainer_id)); + maintainer_cache[maintainer_id] = q.getresult()[0][0]; + + return maintainer_cache[maintainer_id]; + +##########################################################################################