square / sqlbrite

A lightweight wrapper around SQLiteOpenHelper which introduces reactive stream semantics to SQL operations.
https://square.github.io/sqlbrite/3.x/sqlbrite/
Apache License 2.0
4.57k stars 416 forks source link

Table name lint check #237

Closed ShaishavGandhi closed 6 years ago

ShaishavGandhi commented 6 years ago

58

I've added a lint check to make sure that table name being passed in createQuery actually exists in the SQL query.

This doesn't yet cover checking for list of tables or SupportSQLiteQuery. I had a hard time finding documentation to evaluate values of lists.

JakeWharton commented 6 years ago

I think for the first argument we'll probably want to traverse the AST to try and find any string literal. This will allow parsing Collections.singleton("foo"), Collections.singletonList("foo"), Arrays.asList("foo", "bar"), ImmutableList.of("foo", "bar"), etc. We can just assume any literal inside the AST node for the first argument is a table name. Now this breaks if you do something crazy like "foo|bar".split("|") but anyone doing such nonsense can suppress.

@jrodbx can you take a look? Ignore the formatting stuff I can fix that manually.

ShaishavGandhi commented 6 years ago

@JakeWharton Thanks. I can work on that and submit a separate PR if that's fine. Apologies for the 4 spaces instead of 2. I can update it if you want!

JakeWharton commented 6 years ago

It's up to you. I don't mind reformatting it.

On Mon, Jan 29, 2018 at 6:49 PM Shaishav Gandhi notifications@github.com wrote:

@JakeWharton https://github.com/jakewharton Thanks. I can work on that and submit a separate PR if that's fine. Apologies for the 4 spaces instead of 2. I can update it if you want!

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/square/sqlbrite/pull/237#issuecomment-361327702, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEeQxXvQYlZLlcst65qW6IWKDUrL6ks5tPgSigaJpZM4Rd8UA .

ShaishavGandhi commented 6 years ago

Any update on this?

ShaishavGandhi commented 6 years ago

Closing this since most functionality is going to be transferred to SqlDelight.