]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fix passing literal_binds flag through for update and insert
authorTim Tate <timttate@gmail.com>
Tue, 2 Feb 2016 23:20:02 +0000 (15:20 -0800)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 3 Feb 2016 16:10:38 +0000 (11:10 -0500)
(cherry picked from commit c9b03fa8afd52646aba8c59fc038330eeee6db60)

lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/sql/crud.py
test/sql/test_compiler.py

index fd6b6d9b046c248f83a690e54ee1e3ee27ed5f37..ec16511f1008a2d7c60836cf45cabb47a9369c4d 100644 (file)
@@ -2004,7 +2004,7 @@ class SQLCompiler(Compiled):
                 text += " " + extra_from_text
 
         if update_stmt._whereclause is not None:
-            t = self.process(update_stmt._whereclause)
+            t = self.process(update_stmt._whereclause, **kw)
             if t:
                 text += " WHERE " + t
 
index da63c502182bb0d7bd54bb9dc63581f6a8fd34fb..273cc7e964c0eb755457f01038ecdb75188efc56 100644 (file)
@@ -117,14 +117,14 @@ def _get_crud_params(compiler, stmt, **kw):
 
 def _create_bind_param(
         compiler, col, value, process=True,
-        required=False, name=None):
+        required=False, name=None, **kw):
     if name is None:
         name = col.key
     bindparam = elements.BindParameter(
         name, value, type_=col.type, required=required)
     bindparam._is_crud = True
     if process:
-        bindparam = bindparam._compiler_dispatch(compiler)
+        bindparam = bindparam._compiler_dispatch(compiler, **kw)
     return bindparam
 
 
@@ -275,7 +275,8 @@ def _append_param_parameter(
             compiler, c, value, required=value is REQUIRED,
             name=_col_bind_name(c)
             if not stmt._has_multi_parameters
-            else "%s_0" % _col_bind_name(c)
+            else "%s_0" % _col_bind_name(c),
+            **kw
         )
     else:
         if isinstance(value, elements.BindParameter) and \
index 4250c7b1233b23f20f52c38f12789012e9a71853..978547fd76bd4e6ecf4b1dd10991bfab20cd2b4f 100644 (file)
@@ -254,6 +254,22 @@ 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)