X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=xsetbg_db.py;h=eedb25ffa1c4ac533dad4f2100222cffc23a4c9f;hb=688d1400d0e05a4ff2f10db88e89f149f39fee4e;hp=f52c79db1e7cf6d4a4678f5debf98d7d44eb4145;hpb=aa64b9d6bb2f1653cc65e57d7f1aed279542b54d;p=xsetbg.git diff --git a/xsetbg_db.py b/xsetbg_db.py index f52c79d..eedb25f 100755 --- a/xsetbg_db.py +++ b/xsetbg_db.py @@ -10,15 +10,26 @@ __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, UnicodeCol, IntCol, BoolCol, DatabaseIndex, dberrors from xsetbg_conf import xsetbg_conf -class XSetbg(SQLObject): - path = StringCol(alternateID=True) - last_shown = IntCol(default=None) # timestamp +class SqliteSequence(SQLObject): + class sqlmeta: + idName = 'rowid' + name = StringCol(unique=True) + seq = IntCol() + + +class XSetBg(SQLObject): + full_name = UnicodeCol(alternateID=True) + last_shown = IntCol(default=None) # timestamp flag = BoolCol(default=None) + last_shown_idx = DatabaseIndex('last_shown') + flag_idx = DatabaseIndex('flag') + db_dirs = [] try: @@ -40,13 +51,16 @@ if not xsetbg_db_path: break if xsetbg_db_path: + sqlhub.processConnection = \ + connectionForURI('sqlite:///%s' % 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