no shared connection
This commit is contained in:
parent
ecf782af64
commit
7443e33270
1 changed files with 17 additions and 15 deletions
|
@ -11,13 +11,15 @@ from settings import covers_db_path
|
|||
class Covers(dict):
|
||||
def __init__(self, db):
|
||||
self._db = db
|
||||
|
||||
def connect(self):
|
||||
self.conn = sqlite3.connect(self._db, timeout=10)
|
||||
self.create()
|
||||
|
||||
def connect(self):
|
||||
conn = sqlite3.connect(self._db, timeout=10)
|
||||
return conn
|
||||
|
||||
def create(self):
|
||||
c = self.conn.cursor()
|
||||
conn = self.connect()
|
||||
c = conn.cursor()
|
||||
c.execute(u'CREATE TABLE IF NOT EXISTS cover (id varchar(64) unique, data blob)')
|
||||
c.execute(u'CREATE TABLE IF NOT EXISTS setting (key varchar(256) unique, value text)')
|
||||
if int(self.get_setting(c, 'version', 0)) < 1:
|
||||
|
@ -42,34 +44,34 @@ class Covers(dict):
|
|||
|
||||
def __getitem__(self, id, default=None):
|
||||
sql = u'SELECT data FROM cover WHERE id=?'
|
||||
self.connect()
|
||||
c = self.conn.cursor()
|
||||
conn = self.connect()
|
||||
c = conn.cursor()
|
||||
c.execute(sql, (id, ))
|
||||
data = default
|
||||
for row in c:
|
||||
data = row[0]
|
||||
break
|
||||
c.close()
|
||||
self.conn.close()
|
||||
conn.close()
|
||||
return data
|
||||
|
||||
def __setitem__(self, id, data):
|
||||
sql = u'INSERT OR REPLACE INTO cover values (?, ?)'
|
||||
self.connect()
|
||||
c = self.conn.cursor()
|
||||
conn = self.connect()
|
||||
c = conn.cursor()
|
||||
data = sqlite3.Binary(data)
|
||||
c.execute(sql, (id, data))
|
||||
self.conn.commit()
|
||||
conn.commit()
|
||||
c.close()
|
||||
self.conn.close()
|
||||
conn.close()
|
||||
|
||||
def __delitem__(self, id):
|
||||
sql = u'DELETE FROM cover WHERE id = ?'
|
||||
self.connect()
|
||||
c = self.conn.cursor()
|
||||
conn = self.connect()
|
||||
c = conn.cursor()
|
||||
c.execute(sql, (id, ))
|
||||
self.conn.commit()
|
||||
conn.commit()
|
||||
c.close()
|
||||
self.conn.close()
|
||||
conn.close()
|
||||
|
||||
covers = Covers(covers_db_path)
|
||||
|
|
Loading…
Reference in a new issue