From 5fd371fa9cd8d57aa04d21a704db6fad0a2f2350 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 28 Feb 2010 21:29:20 +0000 Subject: [PATCH] some ms/odbc fixes --- lib/sqlalchemy/dialects/mssql/base.py | 4 ++-- lib/sqlalchemy/test/requires.py | 9 +++++++++ test/dialect/test_mssql.py | 17 +++++++++++------ test/engine/test_pool.py | 1 + test/engine/test_transaction.py | 3 ++- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 988088faed..d1ccf44e2c 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -803,9 +803,9 @@ class MSExecutionContext(default.DefaultExecutionContext): if self._select_lastrowid: if self.dialect.use_scope_identity: - self.cursor.execute("SELECT scope_identity() AS lastrowid") + self.cursor.execute("SELECT scope_identity() AS lastrowid", ()) else: - self.cursor.execute("SELECT @@identity AS lastrowid") + self.cursor.execute("SELECT @@identity AS lastrowid", ()) # fetchall() ensures the cursor is consumed without closing it row = self.cursor.fetchall()[0] self._lastrowid = int(row[0]) diff --git a/lib/sqlalchemy/test/requires.py b/lib/sqlalchemy/test/requires.py index 0bf4689dfe..6cfab18ce8 100644 --- a/lib/sqlalchemy/test/requires.py +++ b/lib/sqlalchemy/test/requires.py @@ -66,6 +66,15 @@ def identity(fn): no_support('sybase', 'not supported by database'), ) +def independent_cursors(fn): + """Target must support simultaneous, independent database cursors on a single connection.""" + + return _chain_decorators_on( + fn, + no_support('mssql+pyodbc', 'no driver support'), + no_support('mssql+mxodbc', 'no driver support'), + ) + def independent_connections(fn): """Target must support simultaneous, independent database connections.""" diff --git a/test/dialect/test_mssql.py b/test/dialect/test_mssql.py index caf71ab103..f7728c8845 100644 --- a/test/dialect/test_mssql.py +++ b/test/dialect/test_mssql.py @@ -692,6 +692,7 @@ class TypesTest(TestBase, AssertsExecutionResults, ComparesTables): def teardown(self): metadata.drop_all() + @testing.fails_on_everything_except('mssql+pyodbc', 'this is some pyodbc-specific feature') def test_decimal_notation(self): import decimal numeric_table = Table('numeric_table', metadata, @@ -1074,7 +1075,6 @@ class TypesTest(TestBase, AssertsExecutionResults, ComparesTables): self.assert_(repr(t.c.t)) t.create(checkfirst=True) - @testing.crashes("+mxodbc", "mxODBC doesn't do scope_identity() with DEFAULT VALUES") def test_autoincrement(self): Table('ai_1', metadata, Column('int_y', Integer, primary_key=True), @@ -1129,11 +1129,16 @@ class TypesTest(TestBase, AssertsExecutionResults, ComparesTables): assert not c.autoincrement, name assert tbl._autoincrement_column is not c, name - for counter, engine in enumerate([ - engines.testing_engine(options={'implicit_returning':False}), - engines.testing_engine(options={'implicit_returning':True}), - ] - ): + # mxodbc can't handle scope_identity() with DEFAULT VALUES + if testing.db.driver == 'mxodbc': + eng = [engines.testing_engine(options={'implicit_returning':True})] + else: + eng = [ + engines.testing_engine(options={'implicit_returning':False}), + engines.testing_engine(options={'implicit_returning':True}), + ] + + for counter, engine in enumerate(eng): engine.execute(tbl.insert()) if 'int_y' in tbl.c: assert engine.scalar(select([tbl.c.int_y])) == counter + 1 diff --git a/test/engine/test_pool.py b/test/engine/test_pool.py index 2b6ee5e58d..44b9a94cf4 100644 --- a/test/engine/test_pool.py +++ b/test/engine/test_pool.py @@ -73,6 +73,7 @@ class PoolTest(PoolTestBase): self.assert_(connection.cursor() is not None) self.assert_(connection is not connection2) + @testing.fails_on('+pyodbc', "pyodbc cursor doesn't implement tuple __eq__") def test_cursor_iterable(self): conn = testing.db.raw_connection() cursor = conn.cursor() diff --git a/test/engine/test_transaction.py b/test/engine/test_transaction.py index 84ffaf455d..e8da894381 100644 --- a/test/engine/test_transaction.py +++ b/test/engine/test_transaction.py @@ -850,7 +850,8 @@ class TLTransactionTest(TestBase): c2.close() assert not c1.closed assert not tlengine.closed - + + @testing.requires.independent_cursors def test_result_closing(self): """tests that contextual_connect is threadlocal""" -- 2.47.3