fixed SCHEMA error
authorMax Usachev <maxusachev@gmail.com>
Tue, 15 Jun 2010 10:21:43 +0000 (13:21 +0300)
committerMax Usachev <maxusachev@gmail.com>
Tue, 15 Jun 2010 10:21:43 +0000 (13:21 +0300)
database/SQLite.py

index b5e9514..28229cb 100644 (file)
@@ -15,31 +15,28 @@ SCHEMA = """
         field_id text,
         value text
     );
+    create index i_data on data (id);
 
     create table fields(
         id integer primary key,
         name text
     );
+    create index i_fields on fields (id);
 
     create table relation(
         data_id integer,
         struct_id integer
     );
+    create index i_relation_data on relation(data_id);
 
     create table struct(
         id integer primary key,
         name text,
         parent integer
     );
-
+    create index i_struct_id on struct(parent);
     commit;
 
-    create index i_fields on fields (id);
-    create index i_data on data (id);
-    create index i_struct_id on parent struct(id);
-    create index i_relation_data on relation(data_id);
-
-    commit;
 """
 
 
@@ -50,19 +47,22 @@ class SQLite:
         if not os.path.exists(self._path):
             self.new()
         else:
-            self.conn = sqlite3.connect(self._path)
+            self.connect()
+
+    def connect(self):
+        """Connects to database."""
+
+        self.conn = sqlite3.connect(self._path, isolation_level="EXCLUSIVE")
 
     def new(self):
         """Creates new databse."""
 
-        self.conn = sqlite3.connect(self._path)
+        self.connect()
         self.conn.executescript(SCHEMA)
-        self.conn.commit()
 
     def close(self):
         """Closes connection with database."""
 
-        self.conn.commit()
         self.conn.close()
 
     def save(self):