i want to put the execution of a query with parameters into a thread-safe class in delphi-2009.
I navigate in google but i don't found just what I wanted.
Thanks
i want to put the execution of a query with parameters into a thread-safe class in delphi-2009.
I navigate in google but i don't found just what I wanted.
Thanks
I have found that most database API's are only thread safe at the connection level. Firebird may be different, but using InterBase several (8+) years ago, it was not thread safe. Update: I have verified Firebird is only thread safe at the connection level.
This means that typically you need to avoid using a single connection from more than one thread at the same time. The execution of a query against a given connection applies. Avoid having two queries in different threads running against the same connection.
However, having said that if you have two connections you can have two queries running at the same time.
The nature of your question seems to be how to pass data in a safe manner to a thread, and although you specific need is database, this applies in a generic manner regardless of what is contained in a thread.
The easiest way to pass data is on creation, you can create the thread suspended, set various properties on your
TThread
descendant. Then resume the execution of the thread. Your actual code that does the work in the thread needs to be called from theExecute()
method.If you need to share data between threads you must wrap in one of the various structures that allow to synchronization, such as a Critical Section, Mutex, or Semaphore.
Delphi has library wrappers for each of these in the SyncObjs.pas unit.