Query in Thread
Query in Thread
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
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
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 .
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
Thanks a lot for the fast answer
Re: Query in Thread
Hello,
If you have any other questions, feel free to contact us.
If you have any other questions, feel free to contact us.
Re: Query in Thread
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
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
Hello,
You can set the ReadUncommitted option to True and increase the BusyTimeout property value.
You can set the ReadUncommitted option to True and increase the BusyTimeout property value.
-
- Posts: 1
- Joined: Mon 29 Dec 2014 12:21
Re: Query in Thread
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.
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
Please describe in more details the behavior you want to implement in threads - and we will try to help you resolve the issue.