[yunqa.de] Re: How to correctly avoid 'database is locked' in multi user environment

  • From: Delphi Inspiration <delphi@xxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Thu, 10 Jan 2013 14:49:14 +0100

On 10.01.2013 10:52, H M wrote:

> 1. Is it sufficient to do something like
> 
>     sqlite3_busy_timeout(FDb, 3000);
> 
> once only, each time the database is opened, or does it have to be done
> every time a piece of writing sql is executed?

Yes. Call sqlite3_busy_timeout() once per open database handle.

> 2. is it better to use sqlite3_busy_timeout with a very large value
> (around 10 seconds) or not to use it at all and to use code along the
> lines of the following to retry for as long as necessary  (maybe with
> some protection against an indefinite loop)
> 
>     writeOK := false;
>     repeat
> 
>          try
> 
>              <execute the writing sql>
>              writeOK := true;
> 
>         except
> 
>             on e: ESQLITE3 do
>             if e.ErrorCode= SQLITE_BUSY then
> 
>                 writeOK := false;
> 
>         end
> 
>     until writeOK = true;

Do not wait forever or your application might stall. Also, your
application users would probably like some feedback if nothing happens -
even if it is "The database is currently busy. Please try again later".

For this I'd go for a reasonable sqlite3_busy_timeout() value. You can
also set up your custom busy handler with sqlite3_busy_handler(). Again,
this is set up just once for each database handle.

> 3. Am I correct in thinking that multiple reads (select sql) can be
> going on simultaneously in a multi user environment?

Yes. I suggest reading the pages at

  DISQLite3.chm -> SQLite3 Documentation -> Atomic Commit

for a better understanding of concurrent reads and writes.

WAL mode usually improves concurrency over the rollback journal so I
suggest you try that, too.

And last but not least, keep both your read and write transactions as
short as possible.

> 4. There are several references in this mailing list to the DISQLite3
> HTML help file but I cannot seem to find it anywhere on my hard drive. I
> have lots of demo programs and source files but no .htm or .html file.
> Am I misunderstanding or it it located somewhere else?

The DISQLite3.chm file is located right at the root folder where you
extract your DISQLite3 archive:

  DISQLite3_Extract\DISQLite3.chm
  DISQLite3_Extract\Demos\...

Ralf
_______________________________________________
Delphi Inspiration mailing list
yunqa@xxxxxxxxxxxxx
//www.freelists.org/list/yunqa



Other related posts: