Hi !

Only one process IS writing at once. The problem is that if
the writing is able to happen after _step and before _finalize
it locks the database,

What my code does:
sqlite3_exec(... "BEGIN TRANSACTION" ...)
sqlite3_prepare(... "SELECT * FROM A_TABLE" ...)
sqlite3_step(...)
<============================= Another process does an UPDATE
sqlite3_finalize(...)
sqlite3_exec(... "COMMIT TRANSACTION" ...)

Reading the documentation make me think this should not happen:

http://www.sqlite.org/lockingv3.html

SHARED The database may be read but not written. Any number of processes can hold SHARED locks at the same time, hence there can be many simultaneous readers. But no other thread or process is allowed to write to the database file while one or more SHARED locks are active.

The SQL command "BEGIN TRANSACTION" (the TRANSACTION keyword is optional) is used to take SQLite out of autocommit mode. Note that the BEGIN command does not acquire any locks on the database. After a BEGIN command, a SHARED lock will be acquired when the first SELECT statement is executed. A RESERVED lock will be acquired when the first INSERT, UPDATE, or DELETE statement is executed. No EXCLUSIVE lock is acquired until either the memory cache fills up and must be spilled to disk or until the transaction commits. In this way, the system delays blocking read access to the file file until the last possible moment.


>Only one user can write to an Sqlite database at any time.  The logic >of
>your application has to enforce that "serialization" or "single
>streaming" in some way.


>From: John Stanton <[EMAIL PROTECTED]>
>Subject: Re: Please help me locking/transaction? logic !
>Newsgroups: gmane.comp.db.sqlite.general
>Date: 2006-09-25 19:52:57 GMT (14 minutes ago)

>Martin Alfredsson wrote:
>> Is this correct ?
>>
>> My program calls:
>> sqlite3_prepare(...)
>> sqlite3_step(...)
>>
>> Here another process writes to the database sqlite3_exec(...)
>>
>> sqlite3_finalize(...)
>>
>> Now my program will fail with SQLITE_BUSY (5) when
>> accessing the database.
>>
>> If I dont terminate the other process restaring my program
>> will not help since it will get SQLITE_BUSY (5) all the time.
>>
>> Is there a way to avoid this,
>> Can I stop another process from being able to write to the
>> db while my program is between a _step/_finalize ?
>> (Avoiding "long" SELECTs is hard due to lots of data).
>>
>> /Martin
>> ma1999ATjmaDOTse
>


-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to