summaryrefslogtreecommitdiff
path: root/test/sql/selectable.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-07-10 06:51:58 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-07-10 06:51:58 +0000
commitbe29010e292739ca3545315eb2e6a9243aa53e1a (patch)
tree58b19350841644bef4a4550e313526dd3b23fef0 /test/sql/selectable.py
parent5cb66ee718ee15e91e6036d573aaec67d4c43fe6 (diff)
downloadsqlalchemy-be29010e292739ca3545315eb2e6a9243aa53e1a.tar.gz
more "column targeting" enhancements..columns have a "depth" from their ultimate source column so that corresponding_column() can find the column that is "closest" (i.e. fewest levels of proxying) to the requested column
Diffstat (limited to 'test/sql/selectable.py')
-rwxr-xr-xtest/sql/selectable.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/test/sql/selectable.py b/test/sql/selectable.py
index 57ad99886..340c55837 100755
--- a/test/sql/selectable.py
+++ b/test/sql/selectable.py
@@ -27,17 +27,42 @@ table2 = Table('table2', db,
)
class SelectableTest(testbase.AssertMixin):
+ def testdistance(self):
+ s = select([table.c.col1.label('c2'), table.c.col1, table.c.col1.label('c1')])
+
+ # didnt do this yet...col.label().make_proxy() has same "distance" as col.make_proxy() so far
+ #assert s.corresponding_column(table.c.col1) is s.c.col1
+ assert s.corresponding_column(s.c.col1) is s.c.col1
+ assert s.corresponding_column(s.c.c1) is s.c.c1
+
def testjoinagainstself(self):
jj = select([table.c.col1.label('bar_col1')])
jjj = join(table, jj, table.c.col1==jj.c.bar_col1)
+
+ # test column directly agaisnt itself
assert jjj.corresponding_column(jjj.c.table1_col1) is jjj.c.table1_col1
+ assert jjj.corresponding_column(jj.c.bar_col1) is jjj.c.bar_col1
+
+ # test alias of the join, targets the column with the least
+ # "distance" between the requested column and the returned column
+ # (i.e. there is less indirection between j2.c.table1_col1 and table.c.col1, than
+ # there is from j2.c.bar_col1 to table.c.col1)
+ j2 = jjj.alias('foo')
+ assert j2.corresponding_column(table.c.col1) is j2.c.table1_col1
+
+
def testjoinagainstjoin(self):
j = outerjoin(table, table2, table.c.col1==table2.c.col2)
jj = select([ table.c.col1.label('bar_col1')],from_obj=[j]).alias('foo')
jjj = join(table, jj, table.c.col1==jj.c.bar_col1)
assert jjj.corresponding_column(jjj.c.table1_col1) is jjj.c.table1_col1
+
+ j2 = jjj.alias('foo')
+ print j2.corresponding_column(jjj.c.table1_col1)
+ assert j2.corresponding_column(jjj.c.table1_col1) is j2.c.table1_col1
+ assert jjj.corresponding_column(jj.c.bar_col1) is jj.c.bar_col1
def testtablealias(self):
a = table.alias('a')
@@ -110,8 +135,8 @@ class SelectableTest(testbase.AssertMixin):
j = join(a, table2)
criterion = a.c.col1 == table2.c.col2
- print
- print str(j)
+ print criterion
+ print j.onclause
self.assert_(criterion.compare(j.onclause))
def testselectlabels(self):