Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Call do_update if this is an update type.
# Otherwise we insert.
if static:
txn.execute("DELETE FROM '%s';" % tablename)
rowcount = self.do_insert_table(txn, table)
else:
if update:
rowcount = self.do_update_table(txn, table, identity)
else:
rowcount = self.do_insert_table(txn, table)
txn.execute("COMMIT;")
except apsw.BusyError as e:
# This should only happen if we exceed the busy timeout.
logging.info("SqlConnections: Warning: Lock contention for adding table '%s': %s for %s", tablename, str(e), identity)
try:
txn.execute("ROLLBACK;")
except:
pass
# Should we try again?
if table.test_retry():
logging.info("SqlConnections: ERROR: Retries failed for table '%s'", tablename)
return 0
# Place this request back on the event queue for a retry.
self.async_add_table_data(table, identity)
def backup_database(self, path):
dest_db = apsw.Connection(path)
with dest_db.backup('main', self.conn, 'main') as b:
while not b.done:
try:
b.step(100)
except apsw.BusyError:
pass
dest_db.cursor().execute('DELETE FROM metadata_dirtied; VACUUM;')
dest_db.close()
step = 1
#log.debug(statement)
while True:
curtime = time.time()
try:
if bindings is not None:
return cur.execute(statement, newbindings)
else:
return cur.execute(statement)
except apsw.LockedError:
if waited > self.retrytime:
raise # We don't wait any longer
time.sleep(step / 1000)
waited += step
step = randrange(step+1, 2*(step+1), 1)
except apsw.BusyError:
if time.time() - curtime < self.retrytime/1000:
log.warn('SQLite detected deadlock condition!')
raise
def backup_database(self, path):
dest_db = apsw.Connection(path)
with dest_db.backup('main', self.conn, 'main') as b:
while not b.done:
try:
b.step(100)
except apsw.BusyError:
pass
dest_db.cursor().execute('DELETE FROM metadata_dirtied; VACUUM;')
dest_db.close()