]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- implement "literal binds" for the text() clause, [ticket:2882]
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 12 Dec 2013 01:00:39 +0000 (20:00 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 12 Dec 2013 01:00:39 +0000 (20:00 -0500)
doc/build/changelog/changelog_09.rst
lib/sqlalchemy/sql/compiler.py
test/sql/test_text.py

index b1da813cb534d93692491dda2cb38bd315b9f72d..c40c4c6c8df4ba130860f5085dba747806ceeb8f 100644 (file)
 
     .. change::
         :tags: feature, sql
-        :tickets: 2877
+        :tickets: 2877, 2882
 
         New improvements to the :func:`.text` construct, including
         more flexible ways to set up bound parameters and return types;
         in particular, a :func:`.text` can now be turned into a full
         FROM-object, embeddable in other statements as an alias or CTE
-        using the new method :meth:`.TextClause.columns`.
+        using the new method :meth:`.TextClause.columns`.   The :func:`.text`
+        construct can also render "inline" bound parameters when the construct
+        is compiled in a "literal bound" context.
 
         .. seealso::
 
index 0c252089c291607ad22bd78f32192f4797e80fda..3c8d71331dbd8c8c7c6c05c2c2f091415fcfd4f0 100644 (file)
@@ -585,13 +585,13 @@ class SQLCompiler(Compiled):
     def post_process_text(self, text):
         return text
 
-    def visit_textclause(self, textclause, **kwargs):
+    def visit_textclause(self, textclause, **kw):
         def do_bindparam(m):
             name = m.group(1)
             if name in textclause._bindparams:
-                return self.process(textclause._bindparams[name])
+                return self.process(textclause._bindparams[name], **kw)
             else:
-                return self.bindparam_string(name, **kwargs)
+                return self.bindparam_string(name, **kw)
 
         # un-escape any \:params
         return BIND_PARAMS_ESC.sub(lambda m: m.group(1),
index 827f4dfb982ba4cf10bb1c6f050fb6bd983be9ae..37346437ec3ecb3709e7cd331f25c26015d0e038 100644 (file)
@@ -165,6 +165,17 @@ class BindParamTest(fixtures.TestBase, AssertsCompiledSQL):
             checkparams={'bar': 4, 'whee': 7},
         )
 
+    def test_literal_binds(self):
+        t = text("select * from foo where lala=:bar and hoho=:whee")
+        t = t.bindparams(bindparam('bar', 4), whee='whee')
+
+        self.assert_compile(
+            t,
+            "select * from foo where lala=4 and hoho='whee'",
+            checkparams={},
+            literal_binds=True
+        )
+
     def _assert_type_map(self, t, compare):
         map_ = dict(
             (b.key, b.type) for b in t._bindparams.values()