From 5a95efa1da01fecb1516a94263cacc3744e7dab4 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Fri, 8 Jul 2011 01:42:29 +0000 Subject: Improve version detection code. --- dbgenerator/database.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/dbgenerator/database.py b/dbgenerator/database.py index 94ae0e2..6698d90 100644 --- a/dbgenerator/database.py +++ b/dbgenerator/database.py @@ -549,20 +549,23 @@ class SQLPackageDatabase(object): def schema_is_current(self): """Check if the database schema version matches the version expected by the sourcecode""" + result = False + detected_version = None try: sql = self.sql['SELECT_schema_is_current'] self.cursor.execute(sql) entries = self.cursor.fetchall() - if entries is None: - return False - current_schema = entries[0][0] - return current_schema == self.schema_version + if entries is not None: + current_schema = entries[0][0] + result = (current_schema == self.schema_version) + detected_version = current_schema) except IndexError: - return False + pass except self.db.OperationalError: - return False + pass except self.db.ProgrammingError: - return False + pass + return (result, detected_version) def _preparesql(self): """Prepare all SQL statements for the relevant DB backend""" @@ -614,7 +617,8 @@ class SQLitePackageDB(SQLPackageDatabase): self.cursor = self.db.cursor() self._preparesql() - if not self.schema_is_current(): + schema_check = self.schema_is_current() + if not schema_check[0]: print 'Schema is outdated, flushing!' self.initdb = True if self.initdb: -- cgit v1.2.3-65-gdbad