dwtt/DataStore.py
2010-12-27 15:02:35 -05:00

42 lines
904 B
Python

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,
parentid INTEGER,
FOREIGN KEY (parentid) REFERENCES tasks(id)
)''')
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()