X-Git-Url: http://git.plutz.net/?p=tabnote;a=blobdiff_plain;f=tabnote;h=fa88355fa95faa9335778747cbb0e6aa09162a45;hp=21de6bb58fb34306e4fc6c7541845d74efe48adc;hb=cfa81c81667f8696c3003198099aa280d0327aa7;hpb=ec23a37bec609ac89ccb4356eab7433b859babbc 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: