Reputation: 1574
I just realized that one of my database insert() commands failed due to violation of a not null constraint - I just filled no data into this field.
Problem is, it took me ages to find out why this insert returned -1, because I could not find an error or Exception anywhere.
I'd expect, and I guess for more complex databases and query, it's totally important, to have somewhere some information from the database what's really going on that makes the DB access fail, but I could not find any information on this anywhere.
Upvotes: 18
Views: 10317
Reputation: 1574
I found that one can use insertOrThrow() instead of insert, at least you get an exception when, something goes wrong, saying android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed - even though I actually would wish/expect it would be even clearer and tell me which column has an error or so, but maybe I'm too demanding about SQLIte's feaures here.
Upvotes: 28
Reputation: 12823
Have you looked in LogCat? It's usually pretty verbose about what's going on to include what's going wrong.
Upvotes: 5