More fixes for modern versions of the sqlite module
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 19 Jun 2011 19:48:31 +0000 (21:48 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 19 Jun 2011 19:48:31 +0000 (21:48 +0200)
src/packages/kofoto/shelf.py
src/packages/kofoto/shelfschema.py

index 4b15db5..d2126f1 100644 (file)
@@ -194,6 +194,7 @@ class Shelf:
             raise ShelfNotFoundError(self.location)
         try:
             self.connection = sql.connect(self.location)
+            cursor = self.connection.execute("BEGIN EXCLUSIVE")
         except sql.OperationalError:
             raise ShelfLockedError(self.location)
         except sql.DatabaseError:
@@ -941,7 +942,7 @@ class Shelf:
     def _createShelf(self):
         """Helper method for Shelf.create."""
         cursor = self.connection.cursor()
-        cursor.execute(shelfschema.schema)
+        cursor.executescript(shelfschema.schema)
         cursor.execute(
             " insert into dbinfo (version)"
             " values (?)",
@@ -979,10 +980,11 @@ class Shelf:
             cursor.execute(
                 " select version"
                 " from   dbinfo")
-        except sql.OperationalError:
-            raise ShelfLockedError(self.location)
-        except sql.DatabaseError:
-            raise UnsupportedShelfError(self.location)
+        except sql.OperationalError, e:
+            if e.message == "database is locked":
+                raise ShelfLockedError(self.location)
+            else:
+                raise UnsupportedShelfError(self.location)
         version = cursor.fetchone()[0]
         if version != _SHELF_FORMAT_VERSION:
             raise UnsupportedShelfError(self.location)
@@ -1372,8 +1374,7 @@ class _Object:
             " values"
             "     (?, ?, ?, ?)",
             (self.getId(), name, value, value.lower()))
-        rows = cursor.fetchall()
-        if rows:
+        if cursor.rowcount == 1:
             self.attributes[name] = value
             self.shelf._setModified()
 
index 1ad38ca..f3f65ea 100644 (file)
@@ -39,6 +39,8 @@ schema = """
     -- where \|/ is supposed to look like the subclass relation symbol.
     --        |
 
+    BEGIN;
+
     -- Administrative information about the database.
     CREATE TABLE dbinfo (
         version     INTEGER NOT NULL
@@ -194,4 +196,6 @@ schema = """
     );
 
     CREATE INDEX object_category_category ON object_category (category);
+
+    COMMIT;
 """