def test_wrap_multi_arg(self): # this is not supported by the API but oslo_db is doing it orig = sa_exceptions.DBAPIError(False, False, False) orig.args = [2006, 'Test raise operational error'] eq_( str(orig), "(2006, 'Test raise operational error') " "(Background on this error at: http://sqlalche.me/e/dbapi)")
def test_wrap_unicode_arg(self): # this is not supported by the API but oslo_db is doing it orig = sa_exceptions.DBAPIError(False, False, False) orig.args = [u('méil')] eq_( compat.text_type(orig), compat.u("méil (Background on this error at: " "http://sqlalche.me/e/dbapi)")) eq_(orig.args, (u('méil'), ))
def test_wrap_unicode_arg(self): # this is not supported by the API but oslo_db is doing it orig = sa_exceptions.DBAPIError(False, False, False) orig.args = ["méil"] eq_( str(orig), "méil\n(Background on this error at: " "https://sqlalche.me/e/%s/dbapi)" % sa_exceptions._version_token, ) eq_(orig.args, ("méil", ))
def test_pyodbc_version_fallback(self): dialect = pyodbc.MSDialect_pyodbc() dialect.dbapi = Mock() for vers, expected in [("11.0.9216.62", (11, 0, 9216, 62)), ("notsqlserver.11.foo.0.9216.BAR.62", (11, 0, 9216, 62)), ("Not SQL Server Version 10.5", (5, ))]: conn = Mock(scalar=Mock( side_effect=exc.DBAPIError("stmt", "params", None)), connection=Mock(getinfo=Mock(return_value=vers))) eq_(dialect._get_server_version_info(conn), expected)
def execute(self, logic_row: LogicRow): # logic_row.log(f'Constraint BEGIN {str(self)} on {str(logic_row)}') if self._function is not None: value = self._function(row=logic_row.row, old_row=logic_row.old_row, logic_row=logic_row) else: value = self._as_condition(row=logic_row.row) if value: pass elif not value: row = logic_row.row msg = eval(f'f"""{self._error_msg}"""') from sqlalchemy import exc exception = exc.DBAPIError( msg, None, None) # 'statement', 'params', and 'orig' raise exception else: raise Exception(f'Constraint did not return boolean: {str(self)}') logic_row.log_engine(f'Constraint END {str(self)} on {str(logic_row)}')
def c122(): raise exc.DBAPIError("statement", None, "no such table", None, None)
def get_isolation_level(connection): raise exc.DBAPIError( "get isolation level", {}, engine.dialect.dbapi.Error("isolation level failed"), )