Raise errors other than database is locked

Remove old code
This commit is contained in:
angelblue05 2016-11-04 05:03:44 -05:00
parent 7ec6574ade
commit 4f7c63d5df
2 changed files with 2 additions and 95 deletions

View file

@ -87,51 +87,11 @@ class DatabaseConn(object):
# Errors were raised in the with statement
log.error("rollback: Type: %s Value: %s", exc_type, exc_val)
self.conn.rollback()
raise
if not "database is locked" in exc_val:
raise
elif self.commit_mode is not None:
log.warn("commit: %s", self.path)
self.conn.commit()
self.conn.close()
'''def query(execute_query, connection=None, conn_type=None, *args):
"""
connection is sqlite.connect
conn_type is only required if a connection is not provided
*args are tuple values that contain the corresponding data for the query
i.e args_executemany = (('value1', 'value2'),('value1', 'value2'))
args_execute = ('value1', 'value2')
tip: to build args_executemany, build a list of sets [(v1,v2),(v1,v2)], then pass it as *args
"""
if connection is None:
if conn_type is None:
return False
else:
connection = DatabaseConn(conn_type)
attempts = 3
while True:
try:
with connection as conn:
# raise sqlite3.OperationalError("database is locked")
if not args:
return conn.execute(query)
elif isinstance(args[0], tuple):
# Multiple entries for the same query
return conn.executemany(query, args)
else:
return conn.execute(query, args)
except sqlite3.OperationalError as e:
if "database is locked" in e:
# Database is locked, retry
attempts -= 1
xbmc.sleep(500)
else:
raise
if not attempts:
return False'''

View file

@ -169,59 +169,6 @@ def getKodiMusicDBPath():
% dbVersion.get(xbmc.getInfoLabel('System.BuildVersion')[:2], "")).decode('utf-8')
return dbPath
def querySQL(query, args=None, cursor=None, conntype=None):
result = None
manualconn = False
failed = False
if cursor is None:
if conntype is None:
log.info("New connection type is missing.")
return result
else:
manualconn = True
connection = kodiSQL(conntype)
cursor = connection.cursor()
attempts = 0
while attempts < 3:
try:
log.debug("Query: %s Args: %s" % (query, args))
if args is None:
result = cursor.execute(query)
else:
result = cursor.execute(query, args)
break # Query successful, break out of while loop
except sqlite3.OperationalError as e:
if "database is locked" in e:
log.warn("%s...Attempt: %s" % (e, attempts))
attempts += 1
xbmc.sleep(1000)
else:
log.error(e)
if manualconn:
cursor.close()
raise
except sqlite3.Error as e:
log.error(e)
if manualconn:
cursor.close()
raise
else:
failed = True
log.info("FAILED // Query: %s Args: %s" % (query, args))
if manualconn:
if failed:
cursor.close()
else:
connection.commit()
cursor.close()
log.debug(result)
return result
#################################################################################################
# Utility methods