'Execute some SQL, retrying if the db was locked.
:param sql: the SQL string passed to execute()
:param args: the variable values to `sql`. E.g. (1,2) or {uid:1,
flags:\'T\'}. See sqlite docs for possibilities.
:param executemany: bool indicating whether we want to
perform conn.executemany() or conn.execute().
:returns: None or raises an Exception.'

def __sql_write(self, sql, args=None, executemany=False):

    success = False
    while (not success):
        try:
            with self._databaseFileLock.getLock():
                if (args is None):
                    if executemany:
                        self.connection.executemany(sql)
                    else:
                        self.connection.execute(sql)
                elif executemany:
                    self.connection.executemany(sql, args)
                else:
                    self.connection.execute(sql, args)
                success = True
                if (not self._in_transactions):
                    self.connection.commit()
        except sqlite.OperationalError as e:
            if (e.args[0] == 'cannot    commit    -    no    transaction    is    active'):
                pass
            elif (e.args[0] == 'database    is    locked'):
                self.ui.debug('', 'Locked    sqlite    database,    retrying.')
                success = False
            else:
                raise
