From: paul Date: Tue, 11 Jan 2011 23:40:40 +0000 (+0000) Subject: included functionality of addRecord in setRecord X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=cfa81c81667f8696c3003198099aa280d0327aa7;p=tabnote included functionality of addRecord in setRecord svn path=/trunk/; revision=3 --- diff --git a/tabnote b/tabnote index 21de6bb..fa88355 100755 --- a/tabnote +++ b/tabnote @@ -84,23 +84,24 @@ class Persistence(): self.dbcur.execute('SELECT id, label, content FROM notes ORDER BY id;') return self.dbcur.fetchall() - def setRecord(self, rid, content = None, label = None): - """ - Alter an existing record - """ - if content: - self.dbcur.execute('UPDATE notes SET content = "' + self.escape(content) + - '" WHERE id = ' + str(rid) + ';') - if label: - self.dbcur.execute('UPDATE notes SET label = "' + self.escape(label) + - '" WHERE id = ' + str(rid) + ';') - - def addRecord(self, label = '', content = ''): - """ - Create a new record, return the new record id - """ - self.dbcur.execute('INSERT INTO notes (label, content) VALUES ("' + self.escape(label) + - '", "' + self.escape(content) + '");') + def setRecord(self, rid = None, label = None, content = None): + """ + Create or alter a record + """ + if not rid: + if label: label = self.escape(label) + else: label = '' + if content: content = self.escape(content) + else: content = '' + self.dbcur.execute('INSERT INTO notes (label, content) VALUES ("' + self.escape(label) + + '", "' + self.escape(content) + '");') + else: + if content: + self.dbcur.execute('UPDATE notes SET content = "' + self.escape(content) + + '" WHERE id = ' + str(rid) + ';') + if label: + self.dbcur.execute('UPDATE notes SET label = "' + self.escape(label) + + '" WHERE id = ' + str(rid) + ';') return self.dbcur.lastrowid def delRecord(self, rid): @@ -255,7 +256,7 @@ class Main(Tk): """ for tab in self.contents: if tab[1] == self.tablist.page(name): - self.storage.setRecord(tab[0], content=tab[2].getvalue()[:-1]) + self.storage.setRecord(tab[0], content = tab[2].getvalue()[:-1]) def addTab(self, rid, label = 'New', content = ""): """ @@ -275,7 +276,7 @@ class Main(Tk): If the + tab is selected, this function creates a new record and tab """ if name == '+': - self.addTab(self.storage.addRecord('New', ''), 'New', ''); + self.addTab(self.storage.setRecord(None, 'New', ''), 'New', ''); self.tablist.previouspage(); else: for tab in self.contents: