projects
/
meabook
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
021e117
)
added update_filed function
author
Max Usachev
<maxusachev@gmail.com>
Tue, 8 Jun 2010 12:43:00 +0000
(15:43 +0300)
committer
Max Usachev
<maxusachev@gmail.com>
Tue, 8 Jun 2010 12:43:00 +0000
(15:43 +0300)
database/SQLite.py
patch
|
blob
|
history
diff --git
a/database/SQLite.py
b/database/SQLite.py
index
6d67aa4
..
656a331
100644
(file)
--- a/
database/SQLite.py
+++ b/
database/SQLite.py
@@
-19,7
+19,7
@@
class SQLite:
self.conn = sqlite3.connect(self._path)
self.conn.execute("""CREATE TABLE data (user_id int, field_id int, \
value str)""")
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 (field_id int, name 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, \
self.conn.execute("""CREATE TABLE relation (data_id int, \
struct_id int)""")
self.conn.execute("""CREATE TABLE struct (id int, name str, \
@@
-32,9
+32,18
@@
class SQLite:
self.conn.commit()
self.conn.close()
self.conn.commit()
self.conn.close()
+ def update_field(self, fname):
+ """Adds new field to database."""
+
+ fields = self.conn.execute("""SELECT name from field""").fetchall()
+ if not fname in fields:
+ self.conn.execute("""INSERT INTO field values((SELECT max(id)
+ FROM field)+1, ?)""", (fname,))
+
if __name__ == "__main__":
db = SQLite('/tmp/')
if __name__ == "__main__":
db = SQLite('/tmp/')
+ db.update_field('test')
db.close()
db.close()