stephencelis / SQLite.swift

A type-safe, Swift-language layer over SQLite3.
MIT License
9.57k stars 1.54k forks source link

Fix incorrect behavior when preparing SELECT * preceded by a WITH #1179

Closed marmphco closed 1 year ago

marmphco commented 1 year ago

In #1139 I introduced support for the WITH clause. My implementation contains a bug: preparing a query containing a SELECT * preceded by a WITH causes an error to be thrown.

Consider the following statement:

WITH temp AS ( SELECT id, email from users) SELECT * from temp

An error is thrown when preparing this statement because the glob expansion procedure tries to determine the column names for the result by looking up the column names for the query SELECT * from temp. This does not work because temp is a temporary view defined in the WITH clause.

To fix this, I modified the glob expansion procedure to include the WITH clause in the query used to look up the result column names.