Hi Richard,

Yes, only one thread is working on the database first time. So even if I am
opening more handles, I work only with one of the handles to run some
PRAGMA statements and to check the structural integrity of database. If
tables, or columns are missing I will run some DROP TABLE IF EXISTS
statements, and CREATE TABLE within a transaction. The pseudo-code would be:

1. open 1 handle
2. on handle 1 - perform one SQL SELECT statement
3. on handle 1 - start a transaction and create some tables
4.a. On handle 1 - PRAGMA temp_store=MEMORY
4.b. On handle 1 - PRAGMA locking_mode=EXCLUSIVE
4.c. On handle 1 - PRAGMA main.journal_mode=WAL
5. open another 4 db connections

If step 4 would be executed before step 2, I have immediately after BEGIN
TRANSACTION a database lock. But, after I enable the WAL mode the
consequent transactions (in any other threads) will go in database lock. I
can include the SQLite traces.

The code used to open the the database is:

int res = sqlite3_open_v2( m_FilePath.getBuffer(), &dbHandle,
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_WAL|SQLITE_OPEN_FULLMUTEX|SQLITE_OPEN_PRIVATECACHE,
NULL );

and for the next four handles:

res = sqlite3_open_v2( m_FilePath.getBuffer(), &secondaryDbHandle,
SQLITE_OPEN_READWRITE|SQLITE_OPEN_FULLMUTEX|SQLITE_OPEN_PRIVATECACHE, NULL
);


Regards,
Sandu Buraga

>> On Mon, Nov 11, 2013 at 12:33 PM, Sandu Buraga <sandu.bur...@gmail.com>wrote:
>>
>>> Hi,
>>>
>>> I took your advice and now I am setting only once the journal_mode=WAL,
>>> also locking_mode=EXCLUSIVE and temp_store=MEMORY. But still it doesn't
>>> work, and I get DB locks immediately. I enabled SQLite traces, and I also
>>> added some supplementary traces when the WAL is set. Even if the
>>> journal_mode=WAL pragma seems to be successful, I don't think that the WAL
>>> works because I see no wal file on the disk, also I should have some WAL
>>> related traces, which are not present.
>>>
>>
>> There can only be a single connection open on the database file when you
>> change it to WAL mode.  Did you try to change to WAL mode while holding
>> multiple connections open?
>>
>>
>The above is not quite correct.

>There can be multiple connections open, but none of the other connections
>can have any kind of lock.  Are you sure that you don't have another thread
>trying to read the database file when you enter WAL mode?  The easiest way
>to ensure this is to put the database in WAL mode when the first thread
>connects, and before any other threads have even opened.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to