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):
"""
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 = ""):
"""
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: