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.

  • 60/120fps preview data on an Android device?
  • android what is the difference between Android Support Repository vs Android Support Library vs Google Repository vs Google Play Services
  • Click Listener behavior when two layouts get animated
  • Tabs Coming above Action bar when inflating custom layout
  • Pull to refresh in Android without popular library
  • Advantage of introducing Isolatedprocess tag within Services in JellyBean
  • 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.

    Related posts:

    View not attached to window manager crash
    Rotating Image on A canvas in android
    Get SSID when WIFI is connected
    How to avoid SQLiteException locking errors
    EditText cursor becomes invisible in JellyBean
    Volley Not Parsing 404 response
  • Android Layout: Is reusable component UI possible?
  • Panning google map in CoordinatorLayout causes recyclerview to scroll in android design support library 23.0.1
  • How to start two animations at same time in android?
  • How can I navigate between pages inside a PhoneGap application?
  • Difference between ContentObserver and DatasetObserver?
  • How to change color of Toolbar back button in Android?
  • 3 Solutions collect form web for “Where to get database error information in Android SQLite (e.g. failed insert due to violation of not null)”

    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.

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

    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.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.