File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -130,21 +130,29 @@ class QueryTests: XCTestCase {
130130 }
131131
132132 func test_join_withSubquery_joinsSubquery( ) {
133+ InsertUser ( db, " alice " , age: 20 )
134+
133135 let maxId = max ( id) . alias ( " max_id " )
134136 let subquery = users. select ( maxId) . group ( age)
135137 let query = users. join ( subquery, on: maxId == id)
136138
139+ XCTAssertEqual ( Int64 ( 1 ) , query. first![ maxId] !)
140+
137141 let SQL = " SELECT * FROM \" users \" " +
138142 " INNER JOIN (SELECT (max( \" id \" )) AS \" max_id \" FROM \" users \" GROUP BY \" age \" ) " +
139143 " ON ( \" max_id \" = \" id \" ) "
140144 ExpectExecutions ( db, [ SQL: 1 ] ) { _ in for row in query { println ( row) } }
141145 }
142146
143147 func test_join_withAliasedSubquery_joinsSubquery( ) {
148+ InsertUser ( db, " alice " , age: 20 )
149+
144150 let maxId = max ( id) . alias ( " max_id " )
145151 let subquery = users. select ( maxId) . group ( age) . alias ( " u " )
146152 let query = users. join ( subquery, on: subquery [ maxId] == id)
147153
154+ XCTAssertEqual ( Int64 ( 1 ) , query. first![ subquery [ maxId] ] !)
155+
148156 let SQL = " SELECT * FROM \" users \" " +
149157 " INNER JOIN (SELECT (max( \" id \" )) AS \" max_id \" FROM ( \" users \" ) AS \" u \" GROUP BY \" age \" ) AS \" u \" " +
150158 " ON ( \" u \" . \" max_id \" = \" id \" ) "
Original file line number Diff line number Diff line change @@ -787,7 +787,7 @@ public struct Row {
787787 if similar. count > 1 {
788788 fatalError ( " ambiguous column \( quote ( literal: column. SQL) ) (please disambiguate: \( similar) ) " )
789789 }
790- fatalError ( " no such column \( quote ( literal: column. SQL) ) in columns: \( Array ( columnNames. keys) ) " )
790+ fatalError ( " no such column \( quote ( literal: column. SQL) ) in columns: \( sorted ( columnNames. keys) ) " )
791791 }
792792
793793 // FIXME: rdar://18673897 // ... subscript<T>(expression: Expression<V>) -> Expression<V>
@@ -833,14 +833,16 @@ public struct QueryGenerator: GeneratorType {
833833
834834 func expandGlob( namespace: Bool ) -> Query -> ( ) {
835835 return { table in
836- var names = Query ( self . query. database, self . query. tableName. unaliased) . selectStatement. columnNames. map { quote ( identifier: $0) }
836+ var query = Query ( table. database, table. tableName. unaliased)
837+ if let columns = table. columns { query. columns = columns }
838+ var names = query. selectStatement. columnNames. map { quote ( identifier: $0) }
837839 if namespace { names = names. map { " \( table. tableName. SQL) . \( $0) " } }
838840 for name in names { columnNames [ name] = idx++ }
839841 }
840842 }
841843
842844 if column == " * " {
843- let tables = [ self . query] + self . query. joins. map { $0. table }
845+ let tables = [ self . query. select ( all : * ) ] + self . query. joins. map { $0. table }
844846 if let tableName = tableName {
845847 for table in tables {
846848 if table. tableName. SQL == tableName {
You can’t perform that action at this time.
0 commit comments