summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/util.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-04-07 01:12:44 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-04-07 01:12:44 +0000
commite3b2305d6721a1f1ed20f9c520765f7c33876f32 (patch)
tree8fa4a5565f42dc836a22c44219762dee4b933fd7 /lib/sqlalchemy/sql/util.py
parent5b3cddc48e5b436a0c46f0df3b016a837d823c92 (diff)
downloadsqlalchemy-e3b2305d6721a1f1ed20f9c520765f7c33876f32.tar.gz
- merged -r4458:4466 of query_columns branch
- this branch changes query.values() to immediately return an iterator, adds a new "aliased" construct which will be the primary method to get at aliased columns when using values() - tentative ORM versions of _join and _outerjoin are not yet public, would like to integrate with Query better (work continues in the branch) - lots of fixes to expressions regarding cloning and correlation. Some apparent ORM bug-workarounds removed. - to fix a recursion issue with anonymous identifiers, bind parameters generated against columns now just use the name of the column instead of the tablename_columnname label (plus the unique integer counter). this way expensive recursive schemes aren't needed for the anon identifier logic. This, as usual, impacted a ton of compiler unit tests which needed a search-n-replace for the new bind names.
Diffstat (limited to 'lib/sqlalchemy/sql/util.py')
-rw-r--r--lib/sqlalchemy/sql/util.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py
index 5b9ffd4fa..dd29cb42b 100644
--- a/lib/sqlalchemy/sql/util.py
+++ b/lib/sqlalchemy/sql/util.py
@@ -130,7 +130,43 @@ def criterion_as_pairs(expression, consider_as_foreign_keys=None, consider_as_re
pairs = []
visitors.traverse(expression, visit_binary=visit_binary)
return pairs
+
+def folded_equivalents(join, equivs=None):
+ """Returns the column list of the given Join with all equivalently-named,
+ equated columns folded into one column, where 'equated' means they are
+ equated to each other in the ON clause of this join.
+
+ This function is used by Join.select(fold_equivalents=True).
+ TODO: deprecate ?
+ """
+
+ if equivs is None:
+ equivs = util.Set()
+ def visit_binary(binary):
+ if binary.operator == operators.eq and binary.left.name == binary.right.name:
+ equivs.add(binary.right)
+ equivs.add(binary.left)
+ visitors.traverse(join.onclause, visit_binary=visit_binary)
+ collist = []
+ if isinstance(join.left, expression.Join):
+ left = folded_equivalents(join.left, equivs)
+ else:
+ left = list(join.left.columns)
+ if isinstance(join.right, expression.Join):
+ right = folded_equivalents(join.right, equivs)
+ else:
+ right = list(join.right.columns)
+ used = util.Set()
+ for c in left + right:
+ if c in equivs:
+ if c.name not in used:
+ collist.append(c)
+ used.add(c.name)
+ else:
+ collist.append(c)
+ return collist
+
class AliasedRow(object):
def __init__(self, row, map):