Discussion:
Do any dbExpress methods run in separate threads?
(too old to reply)
Enquiring Mind
2008-06-04 10:17:42 UTC
Permalink
Hi,

I have a method TTimeRecords.ReadFromDatabase(SQLConnection: TSQLConnection,
{..}) that reads data from an Interbase database into a TTimeRecords custom
object using a TSQLDataset component only. The SQLConnection parameter is a
SQLConnection that must be already open when the method is called. In the
calling procedure, I connect to the database, set the screen cursor to
crHourglass, call the ReadFromDatabase method, and finally reset the cursor
to crDefault and close the database connection. This is intended to display
an hourglass cursor while the potentially lengthy ReadFromDatabase procedure
is executing.

Now this approach sometimes doesn't work as intended, with the cursor
apparently changing back to the default value before the ReadFromDatabase
method execution has completed. In another NG someone suggested that this
may be due to some of the code between the cursor assignment statements
running in a different thread to the calling thread. If that's the case I
may need to call an OnTerminate event handler at an appropriate point in the
code to notify the calling thread that the asynchronous operation has
terminated. The problem is where? Can anyone advise whether the
TSQLConnection or TSQLDataset methods anywhere create new threads, and if
so, how I can assign an event handler to notify the main thread that the
operation has terminated? Alternatively, is there a way to force the
dbExpress methods to execute in the main program thread?

Thanks,

EM
PhilDGS
2008-06-04 12:01:23 UTC
Permalink
Hi;

I do not understand exactly what you are doing, but YES, you can do
multi-threading with DBExpress.
In my case, I use to create new connection and new dataset as component
owned by each new thread.
Also, you can synchronize methods from your theads to execute in main
thread, if you need.

Regards,

Phil
Hi,
TSQLConnection, {..}) that reads data from an Interbase database into a
TTimeRecords custom object using a TSQLDataset component only. The
SQLConnection parameter is a SQLConnection that must be already open when
the method is called. In the calling procedure, I connect to the database,
set the screen cursor to crHourglass, call the ReadFromDatabase method,
and finally reset the cursor to crDefault and close the database
connection. This is intended to display an hourglass cursor while the
potentially lengthy ReadFromDatabase procedure is executing.
Now this approach sometimes doesn't work as intended, with the cursor
apparently changing back to the default value before the ReadFromDatabase
method execution has completed. In another NG someone suggested that this
may be due to some of the code between the cursor assignment statements
running in a different thread to the calling thread. If that's the case I
may need to call an OnTerminate event handler at an appropriate point in
the code to notify the calling thread that the asynchronous operation has
terminated. The problem is where? Can anyone advise whether the
TSQLConnection or TSQLDataset methods anywhere create new threads, and if
so, how I can assign an event handler to notify the main thread that the
operation has terminated? Alternatively, is there a way to force the
dbExpress methods to execute in the main program thread?
Thanks,
EM
Enquiring Mind
2008-06-04 13:21:59 UTC
Permalink
Post by PhilDGS
Hi;
I do not understand exactly what you are doing, but YES, you can do
multi-threading with DBExpress.
In my case, I use to create new connection and new dataset as component
owned by each new thread.
Also, you can synchronize methods from your theads to execute in main
thread, if you need.
You seem to be saying that one can include TSQLConnection and TSQLDataset
components as owned members of a TThread object, in order to make the
database operations take place within the secondary thread. Is that correct?

My question, though, is different. I am asking whether, given TSQLConnection
and TSQLDataset components declared within a data module at the main program
level, there is any chance that any of their methods might carry out
database operations within a secondary thread created internally within the
method, that could cause the method to be exited before the work in the
secondary thread has been completed.

Regards,

EM
Bill Todd [TeamB]
2008-06-04 14:46:10 UTC
Permalink
Post by Enquiring Mind
My question, though, is different. I am asking whether, given
TSQLConnection and TSQLDataset components declared within a data
module at the main program level, there is any chance that any of
their methods might carry out database operations within a secondary
thread
AFAIK the answer is no.
--
Bill Todd (TeamB)
Enquiring Mind
2008-06-05 11:38:09 UTC
Permalink
Post by Bill Todd [TeamB]
Post by Enquiring Mind
My question, though, is different. I am asking whether, given
TSQLConnection and TSQLDataset components declared within a data
module at the main program level, there is any chance that any of
their methods might carry out database operations within a secondary
thread
AFAIK the answer is no.
Many thanks - that's a great help.
PhilDGS
2008-06-06 17:57:43 UTC
Permalink
Hi;

Because that, I suggested you to create instances of that components as
members of new threads.

Regards,

Phil.

Loading...