sqldelight icon indicating copy to clipboard operation
sqldelight copied to clipboard

Add more checks for statements with parameters

Open syt0r opened this issue 6 months ago • 4 comments

Description

I was under impression that queries like these will work:

deletePractice:
DELETE FROM practice WHERE id=:id;
DELETE FROM practice_entry WHERE practice_id=:id;

deletePractices:
DELETE FROM practice WHERE id IN :practiceIds;
DELETE FROM practice_entry WHERE practice_id IN :practiceIds;

Android driver instantly gave me an runtime error and upon investigating I noticed that second statements were executed during database creation and have no parameters detected

I think there should be more checks for detecting parameters where they're not working. Maybe even forbid to have multiple statements after you start defining methods so all database creation statements would be located at the top

syt0r avatar Jan 27 '24 11:01 syt0r

I think you just need to use this syntax https://cashapp.github.io/sqldelight/2.0.1/android_sqlite/grouping_statements/ My guess is that the second line is interpreted independently from the function name and gets run during creation otherwise

brinsche avatar Jan 28 '24 17:01 brinsche

Yes, this is what I used to fix this, but I think it should be an error when there're invalid parameters in the database creation queries that will make app crash in runtime

syt0r avatar Jan 28 '24 17:01 syt0r

Ah sorry I misread the issue, seems like a good idea

brinsche avatar Jan 28 '24 23:01 brinsche

Personally, I think, we should split sql declarations (including delete statements!) and actual user queries in separate files (and languages). This also allows us to get rid of the grouping transaction syntax.

hfhbd avatar Feb 01 '24 10:02 hfhbd