"""
self.dbcon = dbapi2.connect(os.getenv('HOME') + os.sep + '.tabnote.sqlite')
self.dbcur = self.dbcon.cursor()
+ self.initDB()
+
+ def initDB(self):
initnote = ('Welcome to TabNote!\n\n' +
'Click the "+"-Tab to open a new note.\n' +
'Double Click on the selected tab to relabel or delete it.\n' +
'Ctrl Return - bring up relabel/delete dialog\n' +
'Ctrl t - create new tab\n' +
'Ctrl q - save and quit')
+ initnote = self.escape(initnote)
+
try:
- self.dbcur.execute('CREATE TABLE settings (key TEXT, value TEXT, UNIQUE (key))')
- self.dbcur.execute('INSERT INTO settings (key, value) VALUES ("version", "1.0");')
+ self.dbcur.execute('CREATE TABLE settings (key TEXT, value TEXT, UNIQUE (key));')
+ self.dbcur.execute('INSERT INTO settings (key, value) VALUES ("version", "1.6");')
self.dbcur.execute('INSERT INTO settings (key, value) VALUES ("geometry", "420x300");')
- self.dbcur.execute('CREATE TABLE notes (id INTEGER PRIMARY KEY, label TEXT, content TEXT);')
- self.dbcur.execute('INSERT INTO notes (label, content) VALUES ("Introduction", "' +
- self.escape(initnote) + '");')
+ self.dbcur.execute('CREATE TABLE notes (uuid TEXT, seq INTEGER PRIMARY KEY, label TEXT, ' +
+ 'content TEXT, revision DATETIME, lastsync DATETIME, UNIQUE (uuid));')
+ self.dbcur.execute('INSERT INTO notes (uuid, label, content, revision, lastsync) VALUES ' +
+ '(lower(hex(randomblob(16))), "Intro", "' + initnote +
+ '", datetime(\'now\'), datetime(\'1970-01-01\'));')
except: pass
def getSetting(self, key):
Return list of all recorded notes
Each item is an array of the format [id, label, textcontent]
"""
- self.dbcur.execute('SELECT id, label, content FROM notes ORDER BY id;')
+ self.dbcur.execute('SELECT uuid, label, content FROM notes ORDER BY seq;')
return self.dbcur.fetchall()
- def setRecord(self, rid = None, label = None, content = None):
+ def setRecord(self, uuid = None, label = None, content = None):
"""
Create or alter a record
"""
- if not rid:
+ if not uuid:
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) + '");')
+ self.dbcur.execute('INSERT INTO notes (uuid, label, content, revision, lastsync) VALUES ' +
+ '(lower(hex(randomblob(16))), "' + label + '", "' + content +
+ '", datetime(\'now\'), datetime(\'1970-01-01\'));')
else:
if content:
self.dbcur.execute('UPDATE notes SET content = "' + self.escape(content) +
- '" WHERE id = ' + str(rid) + ';')
+ '", revision = datetime(\'now\') WHERE uuid = "' + str(uuid) +
+ '" AND NOT content = "' + self.escape(content) + '";')
if label:
self.dbcur.execute('UPDATE notes SET label = "' + self.escape(label) +
- '" WHERE id = ' + str(rid) + ';')
+ '", revision = datetime(\'now\') WHERE uuid = "' + str(uuid) + '";')
return self.dbcur.lastrowid
- def delRecord(self, rid):
+ def delRecord(self, uuid):
"""
Delete record by ID
"""
- self.dbcur.execute('DELETE FROM notes WHERE id = ' + str(rid) + ';')
+ self.dbcur.execute('DELETE FROM notes WHERE uuid = "' + str(uuid) + '";')
def close(self):
"""