summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-02-03 11:07:44 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2016-02-03 11:07:44 -0500
commit150591f9e0a94902cb2a76b68ac7c9d8a1a3ec83 (patch)
tree88e0853370bc6d306f54047b5c85cf9bb4155e24
parentc9b03fa8afd52646aba8c59fc038330eeee6db60 (diff)
downloadsqlalchemy-150591f9e0a94902cb2a76b68ac7c9d8a1a3ec83.tar.gz
- add literal_binds for delete() statements in addition to insert()/update()
- move tests to CRUDTest - changelog, fixes #3643
-rw-r--r--doc/build/changelog/changelog_10.rst10
-rw-r--r--lib/sqlalchemy/sql/compiler.py2
-rw-r--r--test/sql/test_compiler.py41
3 files changed, 36 insertions, 17 deletions
diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst
index 15996be21..6130fdcef 100644
--- a/doc/build/changelog/changelog_10.rst
+++ b/doc/build/changelog/changelog_10.rst
@@ -20,6 +20,16 @@
:released:
.. change::
+ :tags: bug, sql
+ :tickets: 3643
+ :pullreq: github:232
+
+ Fixed issue where the "literal_binds" flag was not propagated
+ for :func:`.expression.insert`, :func:`.expression.update` or
+ :func:`.expression.delete` constructs when compiled to string
+ SQL. Pull request courtesy Tim Tate.
+
+ .. change::
:tags: bug, oracle, jython
:tickets: 3621
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 993956ef0..dbaa23a5d 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -2094,7 +2094,7 @@ class SQLCompiler(Compiled):
delete_stmt, delete_stmt._returning)
if delete_stmt._whereclause is not None:
- t = delete_stmt._whereclause._compiler_dispatch(self)
+ t = delete_stmt._whereclause._compiler_dispatch(self, **kw)
if t:
text += " WHERE " + t
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index 00195c6bf..f11a4e61a 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -255,22 +255,6 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL):
literal_binds=True
)
- def test_insert_literal_binds(self):
- stmt = table1.insert().values(myid=3, name='jack')
-
- self.assert_compile(
- stmt,
- "INSERT INTO mytable (myid, name) VALUES (3, 'jack')",
- literal_binds=True)
-
- def test_update_literal_binds(self):
- stmt = table1.update().values(name='jack').where(table1.c.name == 'jill')
-
- self.assert_compile(
- stmt,
- "UPDATE mytable SET name='jack' WHERE mytable.name = 'jill'",
- literal_binds=True)
-
def test_select_precol_compile_ordering(self):
s1 = select([column('x')]).select_from(text('a')).limit(5).as_scalar()
s2 = select([s1]).limit(10)
@@ -2730,6 +2714,31 @@ class KwargPropagationTest(fixtures.TestBase):
class CRUDTest(fixtures.TestBase, AssertsCompiledSQL):
__dialect__ = 'default'
+ def test_insert_literal_binds(self):
+ stmt = table1.insert().values(myid=3, name='jack')
+
+ self.assert_compile(
+ stmt,
+ "INSERT INTO mytable (myid, name) VALUES (3, 'jack')",
+ literal_binds=True)
+
+ def test_update_literal_binds(self):
+ stmt = table1.update().values(name='jack').\
+ where(table1.c.name == 'jill')
+
+ self.assert_compile(
+ stmt,
+ "UPDATE mytable SET name='jack' WHERE mytable.name = 'jill'",
+ literal_binds=True)
+
+ def test_delete_literal_binds(self):
+ stmt = table1.delete().where(table1.c.name == 'jill')
+
+ self.assert_compile(
+ stmt,
+ "DELETE FROM mytable WHERE mytable.name = 'jill'",
+ literal_binds=True)
+
def test_correlated_update(self):
# test against a straight text subquery
u = update(