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

前端 未结 2 980
-上瘾入骨i
-上瘾入骨i 2021-02-18 22:55

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 m

2条回答
  •  北海茫月
    2021-02-18 23:45

    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.

提交回复
热议问题