diff --git a/DataStore.py b/DataStore.py index 2f55ea8..233be74 100644 --- a/DataStore.py +++ b/DataStore.py @@ -67,6 +67,20 @@ WHERE projectid = ? self.conn.commit() return tasks + def createProject(self, projectname): + c = self.conn.cursor() + projects = self.getProjects() + if projectname in projects.values(): + return False + nextid = self.getNextId('projects') + c.execute(''' +INSERT INTO projects (id, name) +VALUES (?, ?) +''', (nextid, projectname)) + c.close() + self.conn.commit() + return True + def createTask(self, projectid, taskname): c = self.conn.cursor() tasks = self.getTasks(projectid) @@ -75,7 +89,7 @@ WHERE projectid = ? nextid = self.getNextId('tasks') c.execute(''' INSERT INTO tasks (id, projectid, name) -VALUES (?, ?) +VALUES (?, ?, ?) ''', (nextid, projectid, taskname)) c.close() self.conn.commit() @@ -89,6 +103,7 @@ SELECT MAX(id) FROM %s ''' % table) for row in c: - nextid = row[0] + 1 + if row[0]: + nextid = row[0] + 1 c.close() return nextid