From: Mike Bayer Date: Sat, 1 Sep 2012 23:16:17 +0000 (-0400) Subject: - get all tests within -w engine + pyodbc:mssql on windows to pass X-Git-Tag: rel_0_8_0b1~183^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=73d5b74f26a5f13baa01e458b69c0657e520d944;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - get all tests within -w engine + pyodbc:mssql on windows to pass --- diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index bccd585d0f..9c2c1555d9 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -671,7 +671,7 @@ class MSExecutionContext(default.DefaultExecutionContext): self.root_connection._cursor_execute(self.cursor, "SET IDENTITY_INSERT %s ON" % self.dialect.identifier_preparer.format_table(tbl), - ()) + (), self) def post_exec(self): """Disable IDENTITY_INSERT if enabled.""" @@ -680,10 +680,10 @@ class MSExecutionContext(default.DefaultExecutionContext): if self._select_lastrowid: if self.dialect.use_scope_identity: conn._cursor_execute(self.cursor, - "SELECT scope_identity() AS lastrowid", ()) + "SELECT scope_identity() AS lastrowid", (), self) else: conn._cursor_execute(self.cursor, - "SELECT @@identity AS lastrowid", ()) + "SELECT @@identity AS lastrowid", (), self) # fetchall() ensures the cursor is consumed without closing it row = self.cursor.fetchall()[0] self._lastrowid = int(row[0]) @@ -697,8 +697,7 @@ class MSExecutionContext(default.DefaultExecutionContext): "SET IDENTITY_INSERT %s OFF" % self.dialect.identifier_preparer. format_table(self.compiled.statement.table), - () - ) + (), self) def get_lastrowid(self): return self._lastrowid diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 2894f2c219..af7341081c 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -914,7 +914,9 @@ class Connection(Connectable): for fn in self.dispatch.before_cursor_execute: statement, parameters = \ fn(self, cursor, statement, parameters, - context, context.executemany) + context, + context.executemany + if context is not None else False) if self._echo: self.engine.logger.info(statement) diff --git a/lib/sqlalchemy/exc.py b/lib/sqlalchemy/exc.py index f9f97718c1..3c4a64704e 100644 --- a/lib/sqlalchemy/exc.py +++ b/lib/sqlalchemy/exc.py @@ -204,6 +204,8 @@ class StatementError(SQLAlchemyError): return ' '.join((SQLAlchemyError.__str__(self), repr(self.statement), repr(params_repr))) + def __unicode__(self): + return self.__str__() class DBAPIError(StatementError): """Raised when the execution of a database operation fails. diff --git a/test/engine/test_ddlevents.py b/test/engine/test_ddlevents.py index f910dd5eaa..3007131edb 100644 --- a/test/engine/test_ddlevents.py +++ b/test/engine/test_ddlevents.py @@ -469,19 +469,26 @@ class DDLExecutionTest(fixtures.TestBase): default_from = testing.db.dialect.statement_compiler( testing.db.dialect, None).default_from() - eq_( - testing.db.execute( - text("select 'foo%something'" + default_from) - ).scalar(), - 'foo%something' - ) - - eq_( - testing.db.execute( - DDL("select 'foo%%something'" + default_from) - ).scalar(), - 'foo%something' - ) + # We're abusing the DDL() + # construct here by pushing a SELECT through it + # so that we can verify the round trip. + # the DDL() will trigger autocommit, which prohibits + # some DBAPIs from returning results (pyodbc), so we + # run in an explicit transaction. + with testing.db.begin() as conn: + eq_( + conn.execute( + text("select 'foo%something'" + default_from) + ).scalar(), + 'foo%something' + ) + + eq_( + conn.execute( + DDL("select 'foo%%something'" + default_from) + ).scalar(), + 'foo%something' + ) diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py index 43c476915c..37cb9965c7 100644 --- a/test/engine/test_execute.py +++ b/test/engine/test_execute.py @@ -1144,10 +1144,10 @@ class EngineEventsTest(fixtures.TestBase): for engine in [ engines.testing_engine(options=dict(implicit_returning=False)), - engines.testing_engine(options=dict(implicit_returning=False, - strategy='threadlocal')), - engines.testing_engine(options=dict(implicit_returning=False)).\ - connect() + #engines.testing_engine(options=dict(implicit_returning=False, + # strategy='threadlocal')), + #engines.testing_engine(options=dict(implicit_returning=False)).\ + # connect() ]: event.listen(engine, 'before_execute', execute) event.listen(engine, 'before_cursor_execute', cursor_execute)