summaryrefslogtreecommitdiff
path: root/test/dialect/test_mssql.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-03-13 14:00:05 -0700
committerMike Bayer <mike_mp@zzzcomputing.com>2012-03-13 14:00:05 -0700
commit4d2c1e2f17c702fd40af91532a36ec1b12db08fd (patch)
treeca20aca0c8af43d4bb2ba1d0825015378234fe8e /test/dialect/test_mssql.py
parent57868f587ee9f1e35661e8dfadc0b73740300da6 (diff)
downloadsqlalchemy-4d2c1e2f17c702fd40af91532a36ec1b12db08fd.tar.gz
- [feature] Added support for MSSQL INSERT,
UPDATE, and DELETE table hints, using new with_hint() method on UpdateBase. [ticket:2430]
Diffstat (limited to 'test/dialect/test_mssql.py')
-rw-r--r--test/dialect/test_mssql.py90
1 files changed, 90 insertions, 0 deletions
diff --git a/test/dialect/test_mssql.py b/test/dialect/test_mssql.py
index 94609d953..dddc6333d 100644
--- a/test/dialect/test_mssql.py
+++ b/test/dialect/test_mssql.py
@@ -63,6 +63,96 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
'n WHERE sometable.somecolumn = '
':somecolumn_1', dict(somecolumn=10))
+ def test_insert_hint(self):
+ t = table('sometable', column('somecolumn'))
+ for targ in (None, t):
+ for darg in ("*", "mssql"):
+ self.assert_compile(
+ t.insert().
+ values(somecolumn="x").
+ with_hint("WITH (PAGLOCK)",
+ selectable=targ,
+ dialect_name=darg),
+ "INSERT INTO sometable WITH (PAGLOCK) "
+ "(somecolumn) VALUES (:somecolumn)"
+ )
+
+ def test_update_hint(self):
+ t = table('sometable', column('somecolumn'))
+ for targ in (None, t):
+ for darg in ("*", "mssql"):
+ self.assert_compile(
+ t.update().where(t.c.somecolumn=="q").
+ values(somecolumn="x").
+ with_hint("WITH (PAGLOCK)",
+ selectable=targ,
+ dialect_name=darg),
+ "UPDATE sometable WITH (PAGLOCK) "
+ "SET somecolumn=:somecolumn "
+ "WHERE sometable.somecolumn = :somecolumn_1"
+ )
+
+ def test_update_exclude_hint(self):
+ t = table('sometable', column('somecolumn'))
+ self.assert_compile(
+ t.update().where(t.c.somecolumn=="q").
+ values(somecolumn="x").
+ with_hint("XYZ", "mysql"),
+ "UPDATE sometable SET somecolumn=:somecolumn "
+ "WHERE sometable.somecolumn = :somecolumn_1"
+ )
+
+ def test_delete_hint(self):
+ t = table('sometable', column('somecolumn'))
+ for targ in (None, t):
+ for darg in ("*", "mssql"):
+ self.assert_compile(
+ t.delete().where(t.c.somecolumn=="q").
+ with_hint("WITH (PAGLOCK)",
+ selectable=targ,
+ dialect_name=darg),
+ "DELETE FROM sometable WITH (PAGLOCK) "
+ "WHERE sometable.somecolumn = :somecolumn_1"
+ )
+
+ def test_delete_exclude_hint(self):
+ t = table('sometable', column('somecolumn'))
+ self.assert_compile(
+ t.delete().\
+ where(t.c.somecolumn=="q").\
+ with_hint("XYZ", dialect_name="mysql"),
+ "DELETE FROM sometable WHERE "
+ "sometable.somecolumn = :somecolumn_1"
+ )
+
+ def test_update_from_hint(self):
+ t = table('sometable', column('somecolumn'))
+ t2 = table('othertable', column('somecolumn'))
+ for darg in ("*", "mssql"):
+ self.assert_compile(
+ t.update().where(t.c.somecolumn==t2.c.somecolumn).
+ values(somecolumn="x").
+ with_hint("WITH (PAGLOCK)",
+ selectable=t2,
+ dialect_name=darg),
+ "UPDATE sometable SET somecolumn=:somecolumn "
+ "FROM othertable WITH (PAGLOCK) "
+ "WHERE sometable.somecolumn = othertable.somecolumn"
+ )
+
+ # TODO: not supported yet.
+ #def test_delete_from_hint(self):
+ # t = table('sometable', column('somecolumn'))
+ # t2 = table('othertable', column('somecolumn'))
+ # for darg in ("*", "mssql"):
+ # self.assert_compile(
+ # t.delete().where(t.c.somecolumn==t2.c.somecolumn).
+ # with_hint("WITH (PAGLOCK)",
+ # selectable=t2,
+ # dialect_name=darg),
+ # ""
+ # )
+
# TODO: should this be for *all* MS-SQL dialects ?
def test_mxodbc_binds(self):
"""mxodbc uses MS-SQL native binds, which aren't allowed in