From: Mike Bayer Date: Sun, 28 Oct 2007 18:25:37 +0000 (+0000) Subject: - fixed expression translation of text() clauses; this repairs various X-Git-Tag: rel_0_4_1~101 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=19fcf37483b381d795239fa328d08ce97b87ed90;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - fixed expression translation of text() clauses; this repairs various ORM scenarios where literal text is used for SQL expressions --- diff --git a/CHANGES b/CHANGES index 66d6385b96..718e752862 100644 --- a/CHANGES +++ b/CHANGES @@ -15,6 +15,9 @@ CHANGES - Added contains operator (which generate a "LIKE %%" 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 diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index fd96c52cd7..3771734e3b 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -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() diff --git a/test/sql/generative.py b/test/sql/generative.py index bcf5d6a5fa..437f0874ef 100644 --- a/test/sql/generative.py +++ b/test/sql/generative.py @@ -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)