]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] repaired the with_hint() feature which
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 4 Dec 2011 01:04:55 +0000 (20:04 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 4 Dec 2011 01:04:55 +0000 (20:04 -0500)
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]

CHANGES
lib/sqlalchemy/dialects/mssql/base.py
test/dialect/test_mssql.py

diff --git a/CHANGES b/CHANGES
index 3dc5e315131e71ba172a064fe7c7ac26247c122f..89b07c4453f704720f990252c12cbb994533d663 100644 (file)
--- 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.
index c7e1a540a1ab3924c89441e59a9bf9da83ab0877..7d567602868d6d9c79a4109c033f32a5181f276a 100644 (file)
@@ -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):
index f336f5f3b3e0bd7d2e1f8820d3b436076aba7ab0..75e9510eb3817da62d5f6cf9aba28f58507ecc0e 100644 (file)
@@ -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(),