I am creating android app that uses SQLite database. Looking at the SQLiteDatabase class I found that there is a method called insertOrThrow()
which is similar to insert()
but with one important difference - if insert fails it will throw exception and app will die (if not catched). I am using insertOrThrow()
in the initial stage of the development because it draws my attention to SQL errors in a very noticeable way, i.e. app dies.
I am just curious: Why is there no updateOrThrow()
, deleteOrThrow()
, etc... I've tried to google for info but did not found anything...
I think it might be because insert
and replace
are intended to affect a single row. It might make more sense to throw if something bad (like your row wasn't actually inserted due to a constraint) happens here.
For delete
and update
multiple rows are affected, and it isn't abnormal for zero rows to be affected by these queries.
In either case, exceptions will be thrown for a variety of reasons like a malformed query or a non-existent table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With