From: Mike Bayer Date: Sun, 4 Dec 2011 01:04:55 +0000 (-0500) Subject: - [bug] repaired the with_hint() feature which X-Git-Tag: rel_0_7_4~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2fca3c8ee89ba5a2924a66acdacd01f711b45679;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - [bug] repaired the with_hint() feature which wasn't implemented correctly on MSSQL - usually used for the "WITH (NOLOCK)" hint (which you shouldn't be using anyway ! use snapshot isolation instead :) ) [ticket:2336] --- diff --git a/CHANGES b/CHANGES index 3dc5e31513..89b07c4453 100644 --- a/CHANGES +++ b/CHANGES @@ -175,6 +175,14 @@ CHANGES will do this. Helps with Alembic "offline" scripts. +- mssql + - [bug] repaired the with_hint() feature which + wasn't implemented correctly on MSSQL - + usually used for the "WITH (NOLOCK)" hint + (which you shouldn't be using anyway ! + use snapshot isolation instead :) ) + [ticket:2336] + - mysql - [bug] Unicode adjustments allow latest pymysql (post 0.4) to pass 100% on Python 2. diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index c7e1a540a1..7d56760286 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -239,7 +239,6 @@ RESERVED_WORDS = set( 'writetext', ]) - class REAL(sqltypes.REAL): __visit_name__ = 'REAL' @@ -789,7 +788,7 @@ class MSSQLCompiler(compiler.SQLCompiler): return s return compiler.SQLCompiler.get_select_precolumns(self, select) - def get_from_hint_text(self, text): + def get_from_hint_text(self, table, text): return text def limit_clause(self, select): diff --git a/test/dialect/test_mssql.py b/test/dialect/test_mssql.py index f336f5f3b3..75e9510eb3 100644 --- a/test/dialect/test_mssql.py +++ b/test/dialect/test_mssql.py @@ -20,6 +20,35 @@ from sqlalchemy.engine.reflection import Inspector class CompileTest(fixtures.TestBase, AssertsCompiledSQL): __dialect__ = mssql.dialect() + def test_select(self): + t = table('sometable', column('somecolumn')) + self.assert_compile(t.select(), + 'SELECT sometable.somecolumn FROM sometable') + + def test_select_with_nolock(self): + t = table('sometable', column('somecolumn')) + self.assert_compile(t.select().with_hint(t, 'WITH (NOLOCK)'), + 'SELECT sometable.somecolumn FROM sometable WITH (NOLOCK)') + + def test_join_with_hint (self): + t1 = table('t1', + column('a', Integer), + column('b', String), + column('c', String), + ) + t2 = table('t2', + column("a", Integer), + column("b", Integer), + column("c", Integer), + ) + join = t1.join(t2, t1.c.a==t2.c.a).\ + select().with_hint(t1, 'WITH (NOLOCK)') + self.assert_compile( + join, + 'SELECT t1.a, t1.b, t1.c, t2.a, t2.b, t2.c ' + 'FROM t1 WITH (NOLOCK) JOIN t2 ON t1.a = t2.a' + ) + def test_insert(self): t = table('sometable', column('somecolumn')) self.assert_compile(t.insert(),