diff --git a/DataStore.py b/DataStore.py index 0acb72e..cd6a0ac 100644 --- a/DataStore.py +++ b/DataStore.py @@ -95,4 +95,34 @@ WHERE id = ? for row in c: t = Task(row[0], row[1], row[2]) c.close() + self.conn.commit() return t + + def createTask(self, name, longname, parentid): + c = self.conn.cursor() + if parentid is not None and parentid != '': + c.execute(''' +SELECT * +FROM tasks +WHERE id = ? +''', (parentid,)) + found = False + for row in c: + found = True + if not found: + return 0 + c.execute(''' +SELECT MAX(id) +FROM tasks +''') + nextid = 1 + for row in c: + if row[0] is not None: + nextid = row[0] + 1 + c.execute(''' +INSERT INTO tasks +VALUES (?, ?, ?, ?) +''', (nextid, name, longname, parentid)) + c.close() + self.conn.commit() + return nextid