[pkg-fso-commits] [SCM] FSO frameworkd Debian packaging branch, debian, updated. upstream/0.9.5.5-717-g0f98819

Daniele Ricci daniele.athome at gmail.com
Sat Aug 6 08:20:10 UTC 2011


The following commit has been merged in the debian branch:
commit c103cd44b8aab96ff7be48d218b01e5b67d641fb
Author: Daniele Ricci <daniele.athome at gmail.com>
Date:   Wed Oct 27 10:54:55 2010 +0200

    opimd: insert database metadata if creating new database in order to prevent automatic database upgrade
    
    Signed-off-by: Daniele Ricci <daniele.athome at gmail.com>

diff --git a/framework/subsystems/opimd/db_handler.py b/framework/subsystems/opimd/db_handler.py
index 7a26d47..e14fc17 100644
--- a/framework/subsystems/opimd/db_handler.py
+++ b/framework/subsystems/opimd/db_handler.py
@@ -102,31 +102,58 @@ class DbHandler(object):
         # group the rest by sql type
         
         self.table_types.extend(['entryid', 'generic'])
+        self.init_db()
     def __repr__(self):
         return self.name
 
     def __del__(self):
         self.con.commit()
         self.con.close()
-    def create_db(self):
+
+    def init_db(self):
         try:
+            new_db = not os.path.isfile(_SQLITE_FILE_NAME)
             self.con = sqlite3.connect(_SQLITE_FILE_NAME, isolation_level=None)
             self.con.text_factory = sqlite3.OptimizedUnicode
             self.con.create_collation("compare_numbers", numbers_compare)
             self.con.create_function("regex_matches", 2, regex_matches)
+
+            cur = self.con.cursor()
+            cur.execute("""
+                    CREATE TABLE IF NOT EXISTS info (
+                        field_name TEXT PRIMARY KEY,
+                        value TEXT NOT NULL
+                    )
+            """)
+
+            if new_db:
+                cur.execute("INSERT INTO info VALUES('version', ?)", (db_upgrade.DB_VERSIONS[-1], ))
+
+            self.con.commit()
+            cur.close()
+        except Exception, exp:
+            logger.error("""The following errors occured when trying to init db: %s\n%s""", _SQLITE_FILE_NAME, str(exp))
+            raise
+    def create_db(self):
+        try:
+            cur = self.con.cursor()
+
+            check, version = db_upgrade.check_version(cur)
+
+            if check == db_upgrade.DB_UNSUPPORTED:
+                raise Exception("Unsupported database version %s" % (version))
+            elif check == db_upgrade.DB_NEEDS_UPGRADE:
+                db_upgrade.upgrade(version, cur, self.con)
+
+            self.con.commit()
+
             #Creates basic db structue (tables and basic indexes) more complex
             #indexes should be done per backend
-            cur = self.con.cursor()
             cur.executescript("""
                     CREATE TABLE IF NOT EXISTS """ + self.db_prefix + """ (
                         """ + self.db_prefix + """_id INTEGER PRIMARY KEY,
                         name TEXT
                     );
-
-                    CREATE TABLE IF NOT EXISTS info (
-                        field_name TEXT PRIMARY KEY,
-                        value TEXT NOT NULL
-                    );
                     
                     CREATE TABLE IF NOT EXISTS """ + self.db_prefix + """_fields (
                         field_name TEXT PRIMARY KEY,
@@ -155,19 +182,12 @@ class DbHandler(object):
                     self.tables.append(self.db_prefix + "_" + type)
 
                     cur.execute(self.get_create_type_index(type))
-            self.con.commit()
-
-            check, version = db_upgrade.check_version(cur)
-
-            if check == db_upgrade.DB_UNSUPPORTED:
-                raise Exception("Unsupported database version %s" % (version))
-            elif check == db_upgrade.DB_NEEDS_UPGRADE:
-                db_upgrade.upgrade(version, cur, self.con)
 
+            self.con.commit()
             cur.close()
 
         except Exception, exp:
-            logger.error("""The following errors occured when trying to init db: %s\n%s""", _SQLITE_FILE_NAME, str(exp))
+            logger.error("""The following errors occured when trying to create db: %s\n%s""", _SQLITE_FILE_NAME, str(exp))
             raise 
     def get_create_type_index(self, type):
         if type == "phonenumber":

-- 
FSO frameworkd Debian packaging



More information about the pkg-fso-commits mailing list