Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there insertOrThrow but no updateOrThrow or deleteOrThrow?

Tags:

android

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...

like image 929
Ognyan Avatar asked Jan 30 '11 19:01

Ognyan


1 Answers

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.

like image 101
Matthew Willis Avatar answered Oct 04 '22 01:10

Matthew Willis