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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
TThreaddescendant. Then resume the execution of the thread.Your actual code that does the work in the thread needs to be called from the
Execute()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.