X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=xsetbg_db.py;h=77dc70242ae8e1f1d711a2e3ed714fb9cbd27ba7;hb=72abad5af9e89331952a64578b8f24c146a6e767;hp=f52c79db1e7cf6d4a4678f5debf98d7d44eb4145;hpb=aa64b9d6bb2f1653cc65e57d7f1aed279542b54d;p=xsetbg.git diff --git a/xsetbg_db.py b/xsetbg_db.py index f52c79d..77dc702 100755 --- a/xsetbg_db.py +++ b/xsetbg_db.py @@ -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, UnicodeCol, IntCol, BoolCol, 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) @@ -40,13 +48,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