Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to get database error information in Android SQLite (e.g. failed insert due to violation of not null)

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.

like image 211
Henning Avatar asked Mar 22 '11 10:03

Henning


1 Answers

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.

like image 88
Henning Avatar answered Sep 21 '22 01:09

Henning