阅读Android中未提交的事务 [英] Reading uncommitted transactions in Android
问题描述
我有数据库重操作发生的事情,这将增加大约10,000条记录到我的数据库。由于这可能需要花费很长的时间,这将是更好地使用交易。
I have database heavy operations happening, which adds around 10,000 records to my Database. Since this could take a very long time, it would be better to use transactions.
db.startTransaction();
....
do write operations.
....
db.setTransactionSuccessful();
db.endTransaction();
现在,我有交易里面的一些读操作,并且由于刀片不被提交到endTransaction,那些记录并不牵强。我听说过一些所谓的事务隔离级别,这使我们能够读脏(未提交)记录为好。任何想法如何做到这一点?
Now, I have some read operations inside the transactions, and since the inserts are not committed until endTransaction, those records are not fetched. I have heard about something called Transaction Isolation Levels, which enables us to read dirty (uncommitted) records as well. Any idea how to do this?
推荐答案
我发现,在默认情况下,你将能够读取其尚未被提交记录。虽然这如果您正在使用失败 SQliteOpenHelper
。这是因为 SQliteOpenHelper
2给出了处理分开(读&安培;写),并提交的写操作不会从其他的读可用。
所以,如果你想读未提交的记录,可使用 SQLiteDatabase
类。
I found that by default you will be able to read records which are yet to be committed. Though this fails if you are using SQliteOpenHelper
. This is because SQliteOpenHelper
gives 2 separate handled (read& write) and uncommitted writes won't be available for read from the other handle.
So, if you want to read uncommited records, use SQLiteDatabase
class.
这篇关于阅读Android中未提交的事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!