tpolecat / doobie

Functional JDBC layer for Scala.
MIT License
2.13k stars 349 forks source link

Analysis checker should catch updates declared as queries and vice versa #673

Open nigredo-tori opened 6 years ago

nigredo-tori commented 6 years ago

I made a silly mistake yesterday, defining something like this:

sql"DELETE FROM foo RETURNING lo_unlink(bar)".update

Basically, I used RETURNING clause to run an effect for each row being deleted, and declared this as an Update0, intending to ignore the results.

The problem is, Doobie analysis checker didn't catch this, resulting in a runtime exception when executing the Update0:

org.postgresql.util.PSQLException: A result was returned when none was expected.

I'd like for the checker to properly diagnose this problem in the future.

tpolecat commented 6 years ago

Good idea. The difference between update and query is basically whether you expect a resultset or not. We can certainly check this.