with new instance
- fixes to postgres reflection to better handle when schema names are present;
thanks to jason (at) ncsmags.com [ticket:402]
+- fix to correlation of subqueries when the column list of the select statement
+is constructed with individual calls to append_column(); this fixes an ORM
+bug whereby nested select statements were not getting correlated with the
+main select generated by the Query object.
0.3.3
- string-based FROM clauses fixed, i.e. select(..., from_obj=["sometext"])
if columns is not None:
for c in columns:
self.append_column(c)
-
+
+ for f in from_obj:
+ self.append_from(f)
+
+ # whereclauses must be appended after the columns/FROM, since it affects
+ # the correlation of subqueries. see test/sql/select.py SelectTest.testwheresubquery
if whereclause is not None:
self.append_whereclause(whereclause)
if having is not None:
self.append_having(having)
- for f in from_obj:
- self.append_from(f)
class _CorrelatedVisitor(ClauseVisitor):
"""visits a clause, locates any Select clauses, and tells them that they should
select([users, s.c.street], from_obj=[s]),
"""SELECT users.user_id, users.user_name, users.password, s.street FROM users, (SELECT addresses.street AS street FROM addresses WHERE addresses.user_id = users.user_id) AS s""")
+ # test constructing the outer query via append_column(), which occurs in the ORM's Query object
+ s = select([], exists([1], table2.c.otherid==table1.c.myid), from_obj=[table1])
+ s.append_column(table1)
+ self.runtest(
+ s,
+ "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE EXISTS (SELECT 1 FROM myothertable WHERE myothertable.otherid = mytable.myid)"
+ )
+
def testcolumnsubquery(self):
s = select([table1.c.myid], scalar=True, correlate=False)
self.runtest(select([table1, s]), "SELECT mytable.myid, mytable.name, mytable.description, (SELECT mytable.myid AS myid FROM mytable) FROM mytable")