]> git.phdru.name Git - xsetbg.git/commitdiff
Add table SqliteSequence
authorOleg Broytman <phd@phdru.name>
Tue, 21 Jul 2015 19:21:26 +0000 (22:21 +0300)
committerOleg Broytman <phd@phdru.name>
Tue, 21 Jul 2015 19:21:26 +0000 (22:21 +0300)
SqliteSequence is an internal SQLite table; XSetBg uses to reset
autoincrement counter.

xsetbg_db.py

index f52c79db1e7cf6d4a4678f5debf98d7d44eb4145..fd9237dbde6ccf0101a06e3190ff3c9949ed4630 100755 (executable)
@@ -10,13 +10,21 @@ __license__ = "GNU GPL"
 __all__ = ['xsetbg_db_path', 'xsetbg_db']
 
 import os
-from sqlobject import SQLObject, StringCol, IntCol, BoolCol, dberrors
+from sqlobject import SQLObject, connectionForURI, sqlhub, \
+    StringCol, IntCol, BoolCol, dberrors
 from xsetbg_conf import xsetbg_conf
 
 
-class XSetbg(SQLObject):
+class SqliteSequence(SQLObject):
+    class sqlmeta:
+        idName = 'rowid'
+    name = StringCol(unique=True)
+    seq = IntCol()
+
+
+class XSetBg(SQLObject):
     path = StringCol(alternateID=True)
-    last_shown = IntCol(default=None) # timestamp
+    last_shown = IntCol(default=None)  # timestamp
     flag = BoolCol(default=None)
 
 
@@ -40,13 +48,16 @@ if not xsetbg_db_path:
             break
 
 if xsetbg_db_path:
+    sqlhub.processConnection = \
+        connectionForURI('sqlite:///%s?debug=1&debugOutput=1' % xsetbg_db_path)
     try:
-        XSetbg.setConnection('sqlite:///' + xsetbg_db_path)
-        XSetbg.select()[0]
+        XSetBg.select()[0]
+    except IndexError:
+        xsetbg_db = XSetBg  # Table exists but is empty
     except dberrors.Error:
         xsetbg_db = None
     else:
-        xsetbg_db = XSetbg
+        xsetbg_db = XSetBg
 else:
     xsetbg_db = None