From 4ed80c34b609224bca893a3655d921ab6ba01c8d Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 21 Jul 2015 22:21:26 +0300 Subject: [PATCH] Add table SqliteSequence SqliteSequence is an internal SQLite table; XSetBg uses to reset autoincrement counter. --- xsetbg_db.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/xsetbg_db.py b/xsetbg_db.py index f52c79d..fd9237d 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, 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 -- 2.39.2