pinchbv / floor

The typesafe, reactive, and lightweight SQLite abstraction for your Flutter applications
https://pinchbv.github.io/floor/
Apache License 2.0
947 stars 190 forks source link

Invalid query (failing to parse) does not throw an error #820

Open tp opened 5 months ago

tp commented 5 months ago

In our app a wrong SQL statement in the form of DELETE * FROM foo (where there should be no * in the statement) snuck into a @Query annotation.

The underlying sqlparser throws a ParsingError in

https://github.com/simolus3/drift/blob/sqlparser-0.27.0/sqlparser/lib/src/reader/parser.dart#L141

which then gets converted into a InvalidStatement return value on a higher level (instead of throwing the error higher up):

https://github.com/simolus3/drift/blob/sqlparser-0.27.0/sqlparser/lib/src/reader/parser.dart#L185

But then in floor's query execution this type of "statement" is silently ignored and the error is never reported:

https://github.com/pinchbv/floor/blob/1.4.2/floor/lib/src/adapter/query_adapter.dart#L141-L152

I would suggest that the type-switch would be extended to handle InvalidStatement explicitly (forwarding the error) and then have a general fallback to throw on unknown statement types (as we can't exhaustively switch over them, as the base class is not sealed).

Does that sound a reasonable extension?