]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fixed expression translation of text() clauses; this repairs various
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 28 Oct 2007 18:25:37 +0000 (18:25 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 28 Oct 2007 18:25:37 +0000 (18:25 +0000)
  ORM scenarios where literal text is used for SQL expressions

CHANGES
lib/sqlalchemy/sql/expression.py
test/sql/generative.py

diff --git a/CHANGES b/CHANGES
index 66d6385b96ac4a370874fdcbb856204f5ec681f1..718e7528625918fe2a5b91a1df3e641873d1de98 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -15,6 +15,9 @@ CHANGES
 
 - Added contains operator (which generate a "LIKE %<other>%" clause).
 
+- fixed expression translation of text() clauses; this repairs various
+  ORM scenarios where literal text is used for SQL expressions
+  
 - sqlite will reflect "DECIMAL" as a numeric column.
 
 - Renamed the Dialect attribute 'preexecute_sequences' to
index fd96c52cd73ae692db03be30d51d3d3c6fee3b9e..3771734e3b7eddd7eb178d0aaa6cd2f7b9df30ff 100644 (file)
@@ -1870,7 +1870,7 @@ class _TextClause(ClauseElement):
     columns = property(lambda s:[])
 
     def _copy_internals(self):
-        self.bindparams = [b._clone() for b in self.bindparams]
+        self.bindparams = dict([(b.key, b._clone()) for b in self.bindparams.values()])
 
     def get_children(self, **kwargs):
         return self.bindparams.values()
index bcf5d6a5fa5d5e133bb225cfe8e2517c755f530c..437f0874ef875b05f6c4a5237ef224ac00b05bbf 100644 (file)
@@ -3,6 +3,7 @@ from sqlalchemy import *
 from sqlalchemy.sql import table, column, ClauseElement
 from testlib import *
 from sqlalchemy.sql.visitors import *
+from sqlalchemy import util
 
 class TraversalTest(AssertMixin):
     """test ClauseVisitor's traversal, particularly its ability to copy and modify
@@ -165,7 +166,21 @@ class ClauseTest(SQLCompileTest):
         clause2 = Vis().traverse(clause, clone=True)
         assert c1 == str(clause)
         assert str(clause2) == str(t1.join(t2, t1.c.col2==t2.c.col3))
-    
+        
+    def test_text(self):
+        clause = text("select * from table where foo=:bar", bindparams=[bindparam('bar')])
+        c1 = str(clause)
+        class Vis(ClauseVisitor):
+            def visit_textclause(self, text):
+                text.text = text.text + " SOME MODIFIER=:lala"
+                text.bindparams['lala'] = bindparam('lala')
+                
+        clause2 = Vis().traverse(clause, clone=True)
+        assert c1 == str(clause)
+        assert str(clause2) == c1 + " SOME MODIFIER=:lala"
+        assert clause.bindparams.keys() == ['bar']
+        assert util.Set(clause2.bindparams.keys()) == util.Set(['bar', 'lala'])
+                
     def test_select(self):
         s2 = select([t1])
         s2_assert = str(s2)