diff --git a/DataStore.py b/DataStore.py index 89a435e..2f55ea8 100644 --- a/DataStore.py +++ b/DataStore.py @@ -59,10 +59,36 @@ FROM projects SELECT id, name FROM tasks WHERE projectid = ? -''' % (projectid,)) +''', (projectid,)) tasks = {} for row in c: tasks[row[0]] = row[1] c.close() self.conn.commit() return tasks + + def createTask(self, projectid, taskname): + c = self.conn.cursor() + tasks = self.getTasks(projectid) + if taskname in tasks.values(): + return False + nextid = self.getNextId('tasks') + c.execute(''' +INSERT INTO tasks (id, projectid, name) +VALUES (?, ?) +''', (nextid, projectid, taskname)) + c.close() + self.conn.commit() + return True + + def getNextId(self, table): + c = self.conn.cursor() + nextid = 1 + c.execute(''' +SELECT MAX(id) +FROM %s +''' % table) + for row in c: + nextid = row[0] + 1 + c.close() + return nextid