问题
Executing multiple SQL statements without putting them into one transaction is a severe bottleneck (see e.g. http://www.sqlite.org/faq.html#q19). I haven't thoroughly checked how SQLite is configured on Android, but anecdotally I perceived dramatical performance increase within my on app when using transactions in more places.
Is it possible to detect instances where one forgets to use transactions using StrictMode? If not, could that be considered for a future release of StrictMode? It might be somewhat tricky to detect, but two different strategies could be, 1) non-select statements outside transaction, or 2) multiple non-select statements outside transaction executed within a short period of time.
回答1:
Yeah, that sounds like a good thing to catch. I could imagine an API like:
StrictMode.catchWritesOutsideTransactionsOn(SQLiteDatabase db);
We've been considering other SQLite hooks into StrictMode (mostly around selects missing indexes and such), but this is a good idea too!
来源:https://stackoverflow.com/questions/4433629/detecting-forgotten-sqlite-transaction-on-android-using-strictmode