How to prevent Android SQLite from dumping stack trace to logcat?
On Android 2.3.3 I'm doing a bulk import into one of my SQLite tables, using the API method:
SQLiteDatabase.insert(String table, String nullColumnHack, ContentValues values)
It works fine, but if there is a database error with any row (e.g. constraint error) a full stack trace is written to Android Logcat which quickly fills up.
How can I turn off this stack trace?
I already handle any Exception being thrown but the Logcat is being polluted from within the SQLite library code.
I am worried about performance on mobile devices.
- transactions for import are enabled already
- preloaded DB is impossible because data might change
Constraints should be enforced and I will handle violation, but 20 line stack traces in Logcat for each violation multiplied by hundreds of violations is what I want to turn off.
Unfortunately I also cannot use advanced conflict handling introduced with Android Froyo because app must also run on older devices.
OK, I just found the solution as follows:
I have to use a different API method (not SQLiteDatabase.insert()):
SQLiteDatabase.insertOrThrow(String table, String nullColumnHack, ContentValues values)
Now, the exception is thrown from the SQLite library, as expected and no stack trace is dumped.