Board index » off-topic » threads and BDE components - ?

threads and BDE components - ?


2003-11-25 05:40:31 PM
off-topic9
Hi,
In the article 'Performing database queries in a background thread'
bdn.borland.com/article/0,1410,16231,00.html it says that
each TQuery must have its own Tsession.
Is it also the case if:
- I have the same TQuery performing different SQL queries sequentially, one
after another?
- I have 2 TQueries open simultaneously (so I open 1st query, then open
second, then close first and second). Do these 2 TQuery ought to have each
own separate session? Or one will do for both?
 
 

Re:threads and BDE components - ?

Each thread needs its own session. If the queries are executed within the
same thread, they can both use the same session. The example in the article
creates 2 threads, therefore 2 sessions are required.
Personally, I create and destroy the session within the thread ...
In the constructor
ASession := TSession.Create(NIL);
ASession.SessionName := 'Id'+IntToStr(ThreadId);
ASession.Active := TRUE;
and destructor
ASession.Active := FALSE;
ASession.Free;
I use the ThreadId to ensure a unique SessionName. Prior to executing the
query, I assign
TQuery.SessionName := ASession.SessionName
within the thread.
Regards
Mike
 

Re:threads and BDE components - ?

Thanks a lot!
"Matthew Noordermeer" < XXXX@XXXXX.COM >schreef in bericht
Quote
Each thread needs its own session. If the queries are executed within the
same thread, they can both use the same session. The example in the
article
creates 2 threads, therefore 2 sessions are required.

Personally, I create and destroy the session within the thread ...

In the constructor

ASession := TSession.Create(NIL);
ASession.SessionName := 'Id'+IntToStr(ThreadId);
ASession.Active := TRUE;


and destructor

ASession.Active := FALSE;
ASession.Free;

I use the ThreadId to ensure a unique SessionName. Prior to executing the
query, I assign

TQuery.SessionName := ASession.SessionName

within the thread.


Regards

Mike


 

{smallsort}

Re:threads and BDE components - ?

Thanks!
"Bill Todd" < XXXX@XXXXX.COM >schreef in bericht
Quote
On Tue, 25 Nov 2003 10:40:31 +0100, "andru123" <andru123 at hotmail
dot com>wrote:

>Is it also the case if:
>- I have the same TQuery performing different SQL queries sequentially,
one
>after another?
>- I have 2 TQueries open simultaneously (so I open 1st query, then open
>second, then close first and second). Do these 2 TQuery ought to have
each
>own separate session? Or one will do for both?

No in both cases. You can open any number of queries in the main
thread (or any other thread) using one session.

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)