summaryrefslogtreecommitdiff
path: root/test/sql/test_compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-03-21 22:58:55 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-03-21 22:58:55 -0400
commit7142a17291deba2eb9d4a2b30e1635129c2284ea (patch)
treeaa0364a5a29d315c8ec7ea6f3ac402a6425ffa6b /test/sql/test_compiler.py
parent565b5dc537e8c155fb85878d477180a4c954b81f (diff)
downloadsqlalchemy-7142a17291deba2eb9d4a2b30e1635129c2284ea.tar.gz
- [feature] Added new for_update/with_lockmode()
options for Postgresql: for_update="read"/ with_lockmode("read"), for_update="read_nowait"/ with_lockmode("read_nowait"). These emit "FOR SHARE" and "FOR SHARE NOWAIT", respectively. Courtesy Diana Clarke [ticket:2445]
Diffstat (limited to 'test/sql/test_compiler.py')
-rw-r--r--test/sql/test_compiler.py86
1 files changed, 64 insertions, 22 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index 970030d55..c3cf001fa 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -1139,38 +1139,80 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL):
def test_for_update(self):
self.assert_compile(
- table1.select(table1.c.myid==7, for_update=True),
- "SELECT mytable.myid, mytable.name, mytable.description "
- "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE")
+ table1.select(table1.c.myid==7, for_update=True),
+ "SELECT mytable.myid, mytable.name, mytable.description "
+ "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE")
self.assert_compile(
- table1.select(table1.c.myid==7, for_update="nowait"),
- "SELECT mytable.myid, mytable.name, mytable.description "
- "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE")
+ table1.select(table1.c.myid==7, for_update=False),
+ "SELECT mytable.myid, mytable.name, mytable.description "
+ "FROM mytable WHERE mytable.myid = :myid_1")
+ # not supported by dialect, should just use update
self.assert_compile(
- table1.select(table1.c.myid==7, for_update="nowait"),
- "SELECT mytable.myid, mytable.name, mytable.description "
- "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE NOWAIT",
- dialect=oracle.dialect())
+ table1.select(table1.c.myid==7, for_update='nowait'),
+ "SELECT mytable.myid, mytable.name, mytable.description "
+ "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE")
+ # unknown lock mode
self.assert_compile(
- table1.select(table1.c.myid==7, for_update="read"),
- "SELECT mytable.myid, mytable.name, mytable.description "
- "FROM mytable WHERE mytable.myid = %s LOCK IN SHARE MODE",
- dialect=mysql.dialect())
+ table1.select(table1.c.myid==7, for_update='unknown_mode'),
+ "SELECT mytable.myid, mytable.name, mytable.description "
+ "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE")
+
+ # ----- mysql
+
+ self.assert_compile(
+ table1.select(table1.c.myid==7, for_update=True),
+ "SELECT mytable.myid, mytable.name, mytable.description "
+ "FROM mytable WHERE mytable.myid = %s FOR UPDATE",
+ dialect=mysql.dialect())
+
+ self.assert_compile(
+ table1.select(table1.c.myid==7, for_update="read"),
+ "SELECT mytable.myid, mytable.name, mytable.description "
+ "FROM mytable WHERE mytable.myid = %s LOCK IN SHARE MODE",
+ dialect=mysql.dialect())
+
+ # ----- oracle
+
+ self.assert_compile(
+ table1.select(table1.c.myid==7, for_update=True),
+ "SELECT mytable.myid, mytable.name, mytable.description "
+ "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE",
+ dialect=oracle.dialect())
+
+ self.assert_compile(
+ table1.select(table1.c.myid==7, for_update="nowait"),
+ "SELECT mytable.myid, mytable.name, mytable.description "
+ "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE NOWAIT",
+ dialect=oracle.dialect())
+
+ # ----- postgresql
self.assert_compile(
- table1.select(table1.c.myid==7, for_update=True),
- "SELECT mytable.myid, mytable.name, mytable.description "
- "FROM mytable WHERE mytable.myid = %s FOR UPDATE",
- dialect=mysql.dialect())
+ table1.select(table1.c.myid==7, for_update=True),
+ "SELECT mytable.myid, mytable.name, mytable.description "
+ "FROM mytable WHERE mytable.myid = %(myid_1)s FOR UPDATE",
+ dialect=postgresql.dialect())
self.assert_compile(
- table1.select(table1.c.myid==7, for_update=True),
- "SELECT mytable.myid, mytable.name, mytable.description "
- "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE",
- dialect=oracle.dialect())
+ table1.select(table1.c.myid==7, for_update="nowait"),
+ "SELECT mytable.myid, mytable.name, mytable.description "
+ "FROM mytable WHERE mytable.myid = %(myid_1)s FOR UPDATE NOWAIT",
+ dialect=postgresql.dialect())
+
+ self.assert_compile(
+ table1.select(table1.c.myid==7, for_update="read"),
+ "SELECT mytable.myid, mytable.name, mytable.description "
+ "FROM mytable WHERE mytable.myid = %(myid_1)s FOR SHARE",
+ dialect=postgresql.dialect())
+
+ self.assert_compile(
+ table1.select(table1.c.myid==7, for_update="read_nowait"),
+ "SELECT mytable.myid, mytable.name, mytable.description "
+ "FROM mytable WHERE mytable.myid = %(myid_1)s FOR SHARE NOWAIT",
+ dialect=postgresql.dialect())
def test_alias(self):
# test the alias for a table1. column names stay the same, table name "changes" to "foo".