moved sqlite code to DataStore.py

This commit is contained in:
Josh Holtrop committed 2010-12-26 22:09:23 -05:00
1 parent 7765a7cb0b
commit 1d9f305cf9
2 files changed
+41 -31

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
import sqlite3
import os
class DataStore:
def __init__(self, timedbfile):
if not os.path.exists(timedbfile):
self.createdb(timedbfile)
self.conn = sqlite3.connect(dbfile)
def __del__(self):
self.conn.close()
def createdb(self, dbfile):
conn = sqlite3.connect(dbfile)
c = conn.cursor()
c.execute('''
CREATE TABLE tasks (
id INTEGER PRIMARY KEY,
name TEXT,
longname TEXT,
parent TEXT
)''')
c.execute('''
CREATE TABLE entries (
date INTEGER PRIMARY KEY,
taskid INTEGER,
hours REAL,
FOREIGN KEY (taskid) REFERENCES tasks(id)
)''')
c.execute('''
CREATE TABLE history (
id INTEGER PRIMARY KEY,
taskid INTEGER,
FOREIGN KEY (taskid) REFERENCES tasks(id)
)''')
conn.commit()
c.close()
conn.close()
+1 -31
View File
@@ -2,8 +2,6 @@
from CmdWindow import CmdWindow from CmdWindow import CmdWindow
from Command import Command from Command import Command
import sqlite3
import os
import sys import sys
import getopt import getopt
from datetime import datetime from datetime import datetime
@@ -39,35 +37,7 @@ def main(argv):
sys.exit(2) sys.exit(2)
timedbfile = args[0] timedbfile = args[0]
if not os.path.exists(timedbfile): ds = DataStore(timedbfile)
createdb(timedbfile)
def createdb(dbfile):
conn = sqlite3.connect(dbfile)
c = conn.cursor()
c.execute('''
CREATE TABLE tasks (
id INTEGER PRIMARY KEY,
name TEXT,
longname TEXT,
parent TEXT
)''')
c.execute('''
CREATE TABLE entries (
date INTEGER PRIMARY KEY,
taskid INTEGER,
hours REAL,
FOREIGN KEY (taskid) REFERENCES tasks(id)
)''')
c.execute('''
CREATE TABLE history (
id INTEGER PRIMARY KEY,
taskid INTEGER,
FOREIGN KEY (taskid) REFERENCES tasks(id)
)''')
conn.commit()
c.close()
conn.close()
def doCmdWindow(): def doCmdWindow():
c = CmdWindow() c = CmdWindow()