X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=xsetbg_db.py;h=54d174b4076862fb865d3df0fa88ed3b17057f46;hb=990bd4dfbb33d7f14e2a44371a9ae76d8ccb125f;hp=77dc70242ae8e1f1d711a2e3ed714fb9cbd27ba7;hpb=bde51e3fd8d7b7948dacb6342e591228f1abcec9;p=xsetbg.git diff --git a/xsetbg_db.py b/xsetbg_db.py index 77dc702..54d174b 100755 --- a/xsetbg_db.py +++ b/xsetbg_db.py @@ -11,7 +11,8 @@ __all__ = ['xsetbg_db_path', 'xsetbg_db'] import os from sqlobject import SQLObject, connectionForURI, sqlhub, \ - StringCol, UnicodeCol, IntCol, BoolCol, dberrors + StringCol, UnicodeCol, IntCol, BoolCol, DatabaseIndex, dberrors, \ + SQLObjectNotFound from xsetbg_conf import xsetbg_conf @@ -27,6 +28,28 @@ class XSetBg(SQLObject): last_shown = IntCol(default=None) # timestamp flag = BoolCol(default=None) + last_shown_idx = DatabaseIndex('last_shown') + flag_idx = DatabaseIndex('flag') + + def clearTable(self): + super.clearTable(XSetBg, self) + try: + seq = SqliteSequence.byName(XSetBg.sqlmeta.table) + except SQLObjectNotFound: + SqliteSequence(name=XSetBg.sqlmeta.table, seq=0) + else: + seq.seq = 0 # Reset autoincrement counter + + +def recreate_db(): + global xsetbg_db + if xsetbg_db: + xsetbg_db.clearTable() + else: + xsetbg_db = XSetBg + xsetbg_db.createTable() + return xsetbg_db + db_dirs = [] try: