Page 1 of 1
Query in Thread
Posted: Thu 29 Aug 2013 07:10
by Schlueter
Hi,
I want to execute a TLiteQuery in a TThread (Delphi XE3) for updating tabledata. At same time there will be probably a query in the main thread (for same or different table). Can I use the same TLiteConnection for both threads? Is it Thread-Safe?
Should I use separate TLiteConnections, one for the main thread and one for the background thread, if I want to protect the background query to be blocked by the main queries?
Best regards
Rolf Schlueter
Re: Query in Thread
Posted: Thu 29 Aug 2013 09:15
by AlexP
Hello,
Yes, LiteDAC allows work in threads via one connection: for parallel access to a DB from different threads, extended options were added to delimit simultaneous access to a DB: BusyTimeout, EnableSharedCache, ReadUncommitted. You can find more detailed information on these options in the LiteDAC help.
P.S. Moreover, SQLite thread-safety depends on the value of the SQLITE_THREADSAFE option, that was set when building the SQLite library. In the Direct mode, we use the value "1" supposing full thread-safety.You can refer to the SQLite developers site for more detailed information:
http://www.sqlite.org/compile.html#threadsafe ,
http://www.sqlite.org/threadsafe.html .
Re: Query in Thread
Posted: Thu 29 Aug 2013 11:45
by Schlueter
Thanks a lot for the fast answer
Re: Query in Thread
Posted: Thu 29 Aug 2013 11:50
by AlexP
Hello,
If you have any other questions, feel free to contact us.
Re: Query in Thread
Posted: Tue 17 Sep 2013 16:43
by Schlueter
Hi,
if I perform an UPDATE on a table in the one thread, and at same time a SELECT on a (different) table in another thread, sometimes I get the exception 'database is locked' and a rollback is performed automatically.
How can I prevent my application from this exception, perhaps with a TCriticalSection?
What settings do you recommend for BusyTimeout, EnableSharedCache and ReadUncommited?
Best regards
Rolf Schlueter
Re: Query in Thread
Posted: Thu 19 Sep 2013 09:33
by AlexP
Hello,
You can set the ReadUncommitted option to True and increase the BusyTimeout property value.
Re: Query in Thread
Posted: Mon 29 Dec 2014 12:31
by Bestgtester
Hello,
could you provide source code to see TLitequery executed in a thread.
As far I know, TLitequery is a TComponent (VCL), so it should not be declared in a thread
and not even used in a thread. This is the same problem with TLiteSql (=TComponent) but in the demo you provide, it seems that you can execute it in a thread and I don't understand how it is possible. Do you use "synchronize" method ?
Thanks for your help.
Re: Query in Thread
Posted: Tue 30 Dec 2014 11:22
by AlexP
Please describe in more details the behavior you want to implement in threads - and we will try to help you resolve the issue.