]> 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)
committerTim Tate <timttate@gmail.com>
Tue, 2 Feb 2016 23:40:07 +0000 (15:40 -0800)
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/sql/crud.py
test/sql/test_compiler.py

index 2431e53cc06e316fdd809fd2f7607fe56efdcc92..993956ef0cf2df50695e54aedf42f28406e02674 100644 (file)
@@ -2045,7 +2045,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 b66778578ba03977e5c504fc587e3129899580e2..a01b72e61b4edb097bbcdccb9cc793bf4658e894 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
 
 
@@ -280,7 +280,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 85a9f77bc0a035f16a0350bbc892eecf7b49e8cf..00195c6bf6f765e415714d52a813868e5fa513bf 100644 (file)
@@ -255,6 +255,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)