从SQLite数据库读取未提交的更改 [英] Reading uncommitted changes from SQLite database
问题描述
我写了一个应用程序(使用C ++中的Qt),它将数据插入到SQLite数据库中。另一个应用程序从同一个数据库读取数据,但我注意到,无法读取未提交的数据。
I wrote an application (using Qt in C++) which inserts data into a SQLite database. Another application reads data from the same database, but I noticed that it is not possible to read uncommitted data. I would like instead to be able to read data even if it is not committed yet.
阅读SQLite文档我发现pragma read_uncommitted,根据我的理解,应该是我需要的。问题是,即使我设置为true,我不能得到未提交的数据。
Reading the SQLite documentation I found the pragma read_uncommitted which, from what I understand, should be what I need. Problem is that, even if I set that to true, I cannot get uncommitted data.
我试图运行我的应用程序执行插入过程,时间,启动sqlite3客户端。我将pragma设置为true,我尝试计算表中的记录。我得到的总是0(数据库在我的插入过程开始之前为空),直到整个过程完成,我立即得到整个数据。
I tried to run my application which performs the insertion process, and, at the same time, start the sqlite3 client. I set the pragma to true and I try to count the records inside the table. What I get is always 0 (database was empty before my insertion process started), until the entire process finishes where I immediately get the entire data.
我做错了?这个pragma是不是应该使sqlite3客户端的行为不同?
Am I doing something wrong? Isn't this pragma supposed to make the sqlite3 client behave differently?
推荐答案
我回答自己:不,不可能。 read_uncommitted隔离模式需要启用共享缓存,目前仅可用于同一进程中的不同线程。这似乎是最好的地方学习这个: http://www.sqlite.org/sharedcache.html。
I answer to myself: no, it seems it is not possible. The read_uncommitted isolation mode requires to enable the shared cache, which is possible currently only for different threads living in the same process. This seems the best place to study this: http://www.sqlite.org/sharedcache.html.
这篇关于从SQLite数据库读取未提交的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!