Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View causes SELECT query to be generated with nonexistent type, causing build to fail #1874

Closed
andrewfarm opened this issue Aug 14, 2020 · 1 comment · Fixed by #3059
Closed
Labels
Milestone

Comments

@andrewfarm
Copy link

andrewfarm commented Aug 14, 2020

Build Environment
SQLDelight version: 1.4.0
OS: macOS 10.15.5
Gradle version: 6.6
Kotlin version: 1.3.72
AGP Version: 4.0.1

Example:

song.sq

CREATE TABLE song(
    title TEXT,
    track_number INTEGER,
    album_id INTEGER
);

selectSongsByAlbumId:
SELECT * FROM song WHERE album_id = ?;

This compiles to the following:

SongQueries.kt

interface SongQueries : Transacter {
  fun <T : Any> selectSongsByAlbumId(album_id: Long?, mapper: (
    title: String?,
    track_number: Long?,
    album_id: Long?
  ) -> T): Query<T>

  fun selectSongsByAlbumId(album_id: Long?): Query<Song>
}

Everything works correctly so far. Adding another .sq file with a view that selects all columns from the table changes things:

first_song_in_album.sq

CREATE VIEW first_song_in_album AS
SELECT * FROM song WHERE track_number = 1;

This causes the selectSongsByAlbumId query to be compiled with the wrong return type:

SongQueries.kt

interface SongQueries : Transacter {
  fun <T : Any> selectSongsByAlbumId(album_id: Long?, mapper: (
    title: String?,
    track_number: Long?,
    album_id: Long?
  ) -> T): Query<T>

  fun selectSongsByAlbumId(album_id: Long?): Query<First_song_in_album> // Instead of Query<Song>
}

The First_song_in_album type does not exist and the build fails because of this:

SongQueries.kt: (16, 52): Unresolved reference: First_song_in_album

Additional information

  • The IDE plugin generates the return type correctly as Query<Song>. Only when building with the Gradle plugin does this problem occur.
  • The problem only occurs when both the selectSongsByAlbumId query and the first_song_in_album view select all columns (*) from the table.
  • The problem only occurs when the query and the view are in separate files.
@andrewfarm andrewfarm added the bug label Aug 14, 2020
@AlecKazakova
Copy link
Collaborator

thanks for the repro, added that here: https://github.com/cashapp/sqldelight/pull/new/astrong/2020-08-20/1874-repro but don't have an idea for a fix yet. If someone runs in to this and needs a work around you just have to declare the view in the same file after the query (or just have the view return a unique projection)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants