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

前端 未结 2 981
-上瘾入骨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:24

    Have you looked in LogCat? It's usually pretty verbose about what's going on to include what's going wrong.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题