def raw_execute(self, statement, params): """ Like L{Connection.raw_execute}, but encode the statement to UTF-8 if it is unicode. """ if type(statement) is unicode: # psycopg breaks with unicode statements. statement = statement.encode("UTF-8") return Connection.raw_execute(self, statement, params)
def raw_execute(self, statement, params=None, _end=False): """Execute a raw statement with the given parameters. This method will automatically retry on locked database errors. This should be done by pysqlite, but it doesn't work with versions < 2.3.4, so we make sure the timeout is respected here. """ if _end: self._in_transaction = False elif not self._in_transaction: # See story at the end to understand why we do BEGIN manually. self._in_transaction = True self._raw_connection.execute("BEGIN") # Remember the time at which we started the operation. If pysqlite # handles the timeout correctly, we won't retry the operation, because # the timeout will have expired when the raw_execute() returns. started = now() while True: try: return Connection.raw_execute(self, statement, params) except sqlite.OperationalError, e: if str(e) != "database is locked": raise elif now() - started < self._database._timeout: # pysqlite didn't handle the timeout correctly, # so we sleep a little and then retry. sleep(0.1) else: # The operation failed due to being unable to get a # lock on the database. In this case, we are still # in a transaction. if _end: self._in_transaction = True raise
def raw_execute(self, statement, params=None, _end=False): """Execute a raw statement with the given parameters. This method will automatically retry on locked database errors. This should be done by pysqlite, but it doesn't work with versions < 2.3.4, so we make sure the timeout is respected here. """ if _end: self._in_transaction = False elif not self._in_transaction: # See story at the end to understand why we do BEGIN manually. self._in_transaction = True self._raw_connection.execute("BEGIN") # Remember the time at which we started the operation. If pysqlite # handles the timeout correctly, we won't retry the operation, because # the timeout will have expired when the raw_execute() returns. started = now() while True: try: return Connection.raw_execute(self, statement, params) except sqlite.OperationalError as e: if ustr(e) != "database is locked": raise elif now() - started < self._database._timeout: # pysqlite didn't handle the timeout correctly, # so we sleep a little and then retry. sleep(0.1) else: # The operation failed due to being unable to get a # lock on the database. In this case, we are still # in a transaction. if _end: self._in_transaction = True raise
def raw_execute(self, statement, params=None, _started=None): """Execute a raw statement with the given parameters. This method will automatically retry on locked database errors. This should be done by pysqlite, but it doesn't work with versions < 2.3.4, so we make sure the timeout is respected here. """ if not self._in_transaction: # See story at the end to understand why we do BEGIN manually. self._in_transaction = True self._raw_connection.execute("BEGIN") while True: try: return Connection.raw_execute(self, statement, params) except sqlite.OperationalError, e: if str(e) != "database is locked": raise if _started is None: _started = now() elif now() - _started < self._database._timeout: sleep(0.1) else: raise