7

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 (dirty read). I would like instead to be able to read data even if it is not committed yet.

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.

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.

Am I doing something wrong? Isn't this pragma supposed to make the sqlite3 client behave differently?

2
  • 1
    Why would you want to read uncommitted data? If you don't care about transactions, you can insert everything with autocommit on, and every row will be visible immediately. Commented Sep 10, 2011 at 10:26
  • 2
    Yes, sure, I know. But the entire process must not be committed in case a failure of some king happens before it finishes completely. Anyway, I want the user to be able to see the changes even before the entire transaction ends. Sure the user is warned those are not complete results. Moreover it seems that using transactions like this increase performance of the insertion... Commented Sep 10, 2011 at 10:35

2 Answers 2

9

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.

Sign up to request clarification or add additional context in comments.

Comments

0

According to my experiments, all anomalies below don't occur with READ UNCOMMITTED and SERIALIZABLE(default) in SQLite. *SQLite doesn't have READ COMMITTED and REPEATABLE READ :

Anomaly READ UNCOMMITTED READ COMMITTED REPEATABLE READ SERIALIZABLE
Dirty Read No - - No
Non-repeatable Read No - - No
Phantom Read No - - No
Lost Update No - - No
Write Skew No - - No

*I ran the commands below for my experiments:

PRAGMA read_uncommitted=true; -- READ UNCOMMITTED
PRAGMA read_uncommitted=false; -- SERIALIZABLE 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.