From: Mike Bayer Date: Tue, 6 Dec 2011 22:41:19 +0000 (-0500) Subject: - enable SAVEPOINT support fully, remove warning, [ticket:822]. X-Git-Tag: rel_0_7_4~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58e692d76bbea84667609a4ceb828dcf43571f6e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - enable SAVEPOINT support fully, remove warning, [ticket:822]. It's not known what the potential "data loss" issues are, tests seem to pass. --- diff --git a/CHANGES b/CHANGES index 1f67610667..2c77bb4612 100644 --- a/CHANGES +++ b/CHANGES @@ -242,6 +242,11 @@ CHANGES scripts. - mssql + - [feature] lifted the restriction on SAVEPOINT + for SQL Server. All tests pass using it, + it's not known if there are deeper issues + however. [ticket:822] + - [bug] repaired the with_hint() feature which wasn't implemented correctly on MSSQL - usually used for the "WITH (NOLOCK)" hint diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index bc50da5ad6..5443a66cbf 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -854,6 +854,9 @@ class MSSQLCompiler(compiler.SQLCompiler): return 'DATEPART("%s", %s)' % \ (field, self.process(extract.expr, **kw)) + def visit_savepoint(self, savepoint_stmt): + return "SAVE TRANSACTION %s" % self.preparer.format_savepoint(savepoint_stmt) + def visit_rollback_to_savepoint(self, savepoint_stmt): return ("ROLLBACK TRANSACTION %s" % self.preparer.format_savepoint(savepoint_stmt)) @@ -1115,12 +1118,12 @@ class MSDialect(default.DefaultDialect): super(MSDialect, self).__init__(**opts) def do_savepoint(self, connection, name): - util.warn("Savepoint support in mssql is experimental and " - "may lead to data loss.") + # give the DBAPI a push connection.execute("IF @@TRANCOUNT = 0 BEGIN TRANSACTION") - connection.execute("SAVE TRANSACTION %s" % name) + super(MSDialect, self).do_savepoint(connection, name) def do_release_savepoint(self, connection, name): + # SQL Server does not support RELEASE SAVEPOINT pass def initialize(self, connection): diff --git a/test/lib/requires.py b/test/lib/requires.py index 9a117b6b13..65ad0aa8f5 100644 --- a/test/lib/requires.py +++ b/test/lib/requires.py @@ -96,6 +96,14 @@ def independent_connections(fn): 'SQL Server 2005+ is required for independent connections'), ) +def updateable_autoincrement_pks(fn): + """Target must support UPDATE on autoincrement/integer primary key.""" + return _chain_decorators_on( + fn, + no_support('mssql', "IDENTITY cols can't be updated"), + no_support('sybase', "IDENTITY cols can't be updated"), + ) + def isolation_level(fn): return _chain_decorators_on( fn, @@ -136,7 +144,6 @@ def savepoints(fn): """Target database must support savepoints.""" return _chain_decorators_on( fn, - emits_warning_on('mssql', 'Savepoint support in mssql is experimental and may lead to data loss.'), no_support('access', 'savepoints not supported'), no_support('sqlite', 'savepoints not supported'), no_support('sybase', 'savepoints not supported'), diff --git a/test/orm/test_transaction.py b/test/orm/test_transaction.py index 2a609c4278..c0d6d7c15f 100644 --- a/test/orm/test_transaction.py +++ b/test/orm/test_transaction.py @@ -592,6 +592,7 @@ class AutoCommitTest(TransactionTest): [] ) + @testing.requires.updateable_autoincrement_pks def test_accounting_no_select_needed(self): """test that flush accounting works on non-expired instances when autocommit=True/expire_on_commit=True."""