Select from multiple tables throws "No such table"
Build Information
- Include the SQLite.swift version, commit or branch experiencing the issue. 0.11.4
- Mention Xcode and OS X versions affected. Xcode 9.2, iOS 11
- How do do you integrate SQLite.swift in your project?
- Carthage
Hi,
I noticed that when selecting all columns from multiple tables, SQLite.swift throws an No such table: exception even if the table does exists and the generated SQL itself works fine
More details are in the SO question
Basically
users.select(users[*], posts[*]).join(posts, on: user_id == users[id])
would throw "No such table: posts"
while this works
users.select(users[*], posts[post_text]).join(posts, on: user_id == users[id])
In both cases, the generated SQL is correct
cheers, Jan
Having the same problem.
actionAlias.select(modelTableAlias[*], actionAlias[*])
.join(JoinType.leftOuter, modelTableAlias, on: actionAlias[ActionDao.modelId] == cast(modelTableAlias[idColumn]) as Expression<String> )
.filter( actionAlias[ActionDao.modelTable] == tableName)
This worked just fine before.
I got the same problem, please fix asap.
Proposed Solution for this issue #777 I had the same problem, and debugged the SQLite.swift code. In file "Query.swift" in function "columnNamesForQuery(_ query: QueryType)" in the code block following "if column == "*" {" in the loop "for q in queries {" there is a "throw QueryError.noSuchTable(name: namespace)" immediately after the if statement WITHIN the loop. Therefore the loop tests one entry (first table of the join), then always throws. The fix is to delete this mis-placed throw statement, leaving the second throw (outside the loop) in place. (Sorry I can't seem to get indenting to work on the copied code below).
if column == "" {
var select = query
select.clauses.select = (false, [Expression
me too. please fix.
any updates on this @stephencelis? The proposed PR seems to fix it
The problem happens whenever we make tableName[*] to select all the fields of the table, but this table is not the source of the query, is a table in which the join was made.
An immediate solution, while not solving the problem, is to put all the columns of the table inside the select, as below.
rootTable.select (joinTable.firstColumn,
joinTable.secondColumn,
joinTable.thirdColumn)
.join (joinTable, on: joinTable.firstColumn == rootTable.mainColumn)
That will solve.