diff options
author | Robin H. Johnson <robbat2@gentoo.org> | 2007-10-11 10:52:38 +0000 |
---|---|---|
committer | Robin H. Johnson <robbat2@gentoo.org> | 2007-10-11 10:52:38 +0000 |
commit | 9d9edb3fbfd60ebe2d294716996e4b17f90bc8fe (patch) | |
tree | 3e334ee0994022011a5404cad95ef1ae34cefe2a /dbgenerator/database.py | |
parent | Fix tuple usage. (diff) | |
download | packages-3-9d9edb3fbfd60ebe2d294716996e4b17f90bc8fe.tar.gz packages-3-9d9edb3fbfd60ebe2d294716996e4b17f90bc8fe.tar.bz2 packages-3-9d9edb3fbfd60ebe2d294716996e4b17f90bc8fe.zip |
Improve naming of columns.
Diffstat (limited to 'dbgenerator/database.py')
-rw-r--r-- | dbgenerator/database.py | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/dbgenerator/database.py b/dbgenerator/database.py index d328690..0b6d31f 100644 --- a/dbgenerator/database.py +++ b/dbgenerator/database.py @@ -15,7 +15,7 @@ class SQLPackageDatabase(object): # This should match /usr/portage/profiles/arch.list arches = frozenset(['alpha', 'amd64', 'arm', 'hppa', 'ia64', 'm68k', 'mips', 'ppc', 'ppc64', 'ppc-macos', 's390', 'sh', 'sparc', 'sparc-fbsd', 'x86', 'x86-fbsd']) # If you change the database structure below, you should increment this number - schema_version = 54 + schema_version = 57 # These are used to cache the various relations # and avoid more SELECT queries just to find the relations @@ -63,13 +63,13 @@ class SQLPackageDatabase(object): self.cursor.execute("""CREATE TABLE keywords ( cpv INTEGER, - arch INTEGER, + a INTEGER, mode CHAR(2), - PRIMARY KEY (cpv, arch) + PRIMARY KEY (cpv, a) )""") self.cursor.execute("""CREATE TABLE arches ( - archid INTEGER PRIMARY KEY AUTOINCREMENT, + a INTEGER PRIMARY KEY AUTOINCREMENT, arch VARCHAR(16), UNIQUE(arch) )""") @@ -95,10 +95,10 @@ class SQLPackageDatabase(object): cpv = self.find_cpv(category, pn, pv) #print "c=%s pn=%s pv=%s cpv=%s kw=%s" % (category, pn, pv, repr(cpv), keyword_dict) self.cursor.execute('DELETE FROM keywords WHERE cpv = ?'.replace('?',self.placeholder), (cpv,)) - sql = 'INSERT INTO keywords (cpv, arch, mode) VALUES (?, ?, ?)'.replace('?',self.placeholder) + sql = 'INSERT INTO keywords (cpv, a, mode) VALUES (?, ?, ?)'.replace('?',self.placeholder) for arch in keyword_dict.keys(): - archid = self.find_or_create_arch(arch) - self.cursor.execute(sql, (cpv, archid, keyword_dict[arch])) + a = self.find_or_create_arch(arch) + self.cursor.execute(sql, (cpv, a, keyword_dict[arch])) self.commit() def add_metadata(self, category, pn, description, homepage, license, changelog): @@ -145,32 +145,32 @@ class SQLPackageDatabase(object): self.cursor.execute('SELECT c FROM categories WHERE category = ?'.replace('?',self.placeholder), (category,)) entries = self.cursor.fetchall() try: - categoryid = entries[0][0] - self.cache_category[cachekey] = categoryid - return categoryid + c = entries[0][0] + self.cache_category[cachekey] = c + return c except IndexError: self.cursor.execute('INSERT INTO categories (category) VALUES (?)'.replace('?',self.placeholder), (category,)) self.commit() - categoryid = self.cursor.lastrowid - self.cache_category[cachekey] = categoryid - return categoryid + c = self.cursor.lastrowid + self.cache_category[cachekey] = c + return c def find_or_create_arch(self, arch): cachekey = arch if cachekey in self.cache_arch: return self.cache_arch[cachekey] - self.cursor.execute('SELECT archid FROM arches WHERE arch = ?'.replace('?',self.placeholder), (arch,)) + self.cursor.execute('SELECT a FROM arches WHERE arch = ?'.replace('?',self.placeholder), (arch,)) entries = self.cursor.fetchall() try: - archid = entries[0][0] - self.cache_arch[cachekey] = archid - return archid + a = entries[0][0] + self.cache_arch[cachekey] = a + return a except IndexError: self.cursor.execute('INSERT INTO arches (arch) VALUES (?)'.replace('?',self.placeholder), (arch,)) self.commit() - archid = self.cursor.lastrowid - self.cache_arch[cachekey] = archid - return archid + a = self.cursor.lastrowid + self.cache_arch[cachekey] = a + return a def find_or_create_cp(self, category, pn): cachekey = category+pn @@ -221,6 +221,7 @@ class SQLitePackageDB(SQLPackageDatabase): self.db.isolation_level = 'DEFERRED' self.cursor = self.db.cursor() if not self.schema_is_current(): + print 'Schema is outdated, flushing!' initdb = True if initdb: self.drop_structure() @@ -242,6 +243,7 @@ class MySQLPackageDB(SQLPackageDatabase): self.db = MySQLdb.connect(host=host, user=username, passwd=password, db=database, charset='utf8') self.cursor = self.db.cursor() if not self.schema_is_current(): + print 'Schema is outdated, flushing!' initdb = True if initdb: self.drop_structure() |