From: Mike Bayer Date: Wed, 3 Feb 2016 16:07:44 +0000 (-0500) Subject: - add literal_binds for delete() statements in addition to insert()/update() X-Git-Tag: rel_1_1_0b1~98^2~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=150591f9e0a94902cb2a76b68ac7c9d8a1a3ec83;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - add literal_binds for delete() statements in addition to insert()/update() - move tests to CRUDTest - changelog, fixes #3643 --- diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst index 15996be21e..6130fdcefc 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -19,6 +19,16 @@ :version: 1.0.12 :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 993956ef0c..dbaa23a5d0 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 00195c6bf6..f11a4e61af 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(