replaced db initialization by script
authorMax Usachev <maxusachev@gmail.com>
Wed, 9 Jun 2010 05:13:45 +0000 (08:13 +0300)
committerMax Usachev <maxusachev@gmail.com>
Wed, 9 Jun 2010 05:13:45 +0000 (08:13 +0300)
database/SQLite.py

index 83ebff0..1ec907c 100644 (file)
@@ -3,6 +3,34 @@ import sqlite3
 
 DATABASE_NAME = 'contacts.db'
 
+SCHEMA = """
+    begin;
+
+    create table data(
+        id integer primary key,
+        field_id integer,
+        value text
+    );
+
+    create table fields(
+        id integer primary key,
+        name text
+    );
+
+    create table relation (
+        data_id integer,
+        struct_id integer
+    );
+
+    create table struct(
+        id integer primary key,
+        name text,
+        parent integer
+    );
+
+    commit;
+"""
+
 
 class SQLite:
     def __init__(self, basedir):
@@ -17,13 +45,7 @@ class SQLite:
         """Creates new databse."""
 
         self.conn = sqlite3.connect(self._path)
-        self.conn.execute("""CREATE TABLE data (user_id int, field_id int, \
-            value str)""")
-        self.conn.execute("""CREATE TABLE field (id int primary key, name str)""")
-        self.conn.execute("""CREATE TABLE relation (data_id int, \
-            struct_id int)""")
-        self.conn.execute("""CREATE TABLE struct (id int, name str, \
-            parent_id int)""")
+        self.conn.executescript(SCHEMA)
         self.conn.commit()
 
     def close(self):
@@ -71,11 +93,11 @@ class SQLite:
 
 
 if __name__ == "__main__":
-    db = SQLite('/home/plastun/meabook')
+    db = SQLite('/tmp/')
     #db.update_field('test')
     #print db.get_field_id_by_name('fax')
     #print db.get_entry_by_id(1)
-    print db.get_all_entries()
+    #print db.get_all_entries()
     db.close()