| View previous topic :: View next topic |
| Author |
Message |
Robert den Holder Guest
|
Posted: Mon Dec 19, 2005 10:17 am Post subject: Cancel TQuery |
|
|
Hello,
is there a way to cancel a TQuery?
I wan't to show a dialogbox when a query is executed. When the user clicks
the cancel-button, I want the query to stop.
Now I use the "active"-property to execute a query, but that one is
blocking.
Thanks in advance,
Robert.
|
|
| Back to top |
|
 |
Mike Shkolnik Guest
|
Posted: Mon Dec 19, 2005 11:40 am Post subject: Re: Cancel TQuery |
|
|
You may run the query in thread and terminate the thread by Cancel click
As alternative, you may use the BDE-callbacks but be sure that your
db-server/driver supports this feature.
--
With best regards, Mike Shkolnik
EMail: [email]mshkolnik (AT) scalabium (DOT) com[/email]
http://www.scalabium.com
"Robert den Holder" <robert.den.holder (AT) _NOSPAM_tpa (DOT) nl> wrote
| Quote: | Hello,
is there a way to cancel a TQuery?
I wan't to show a dialogbox when a query is executed. When the user clicks
the cancel-button, I want the query to stop.
Now I use the "active"-property to execute a query, but that one is
blocking.
Thanks in advance,
Robert.
|
|
|
| Back to top |
|
 |
Don Locke Guest
|
Posted: Mon Dec 19, 2005 1:48 pm Post subject: Re: Cancel TQuery |
|
|
If you just want it to stop, use Query->Close();
Don
|
|
| Back to top |
|
 |
Jayme Jeffman Filho Guest
|
Posted: Tue Dec 20, 2005 5:40 pm Post subject: Re: Cancel TQuery |
|
|
Hello Don,
Have you ever done it this way ? I thought that the Open method could not be
interrupted, because there is no any "middle" event while the server is
parsing or executing the query. Can you explain how it works ?
Jayme.
"Don Locke" <dgnospamlocke (AT) comcast (DOT) net> escreveu na mensagem
news:43a6b9ea$1 (AT) newsgroups (DOT) borland.com...
| Quote: | If you just want it to stop, use Query->Close();
Don
|
|
|
| Back to top |
|
 |
Don Locke Guest
|
Posted: Tue Dec 20, 2005 6:40 pm Post subject: Re: Cancel TQuery |
|
|
Here is some code that I use:
ProdQuery->Close();
ProdQuery->SQL->Clear();
ProdQuery->SQL->Add("SELECT * FROM Products");
ProdQuery->SQL->Add("WHERE Prod_code = :code");
ProdQuery->ParamByName("code")->AsString = sPcode;
if(!ProdQuery->Prepared)
ProdQuery->Prepare();
ProdQuery->Open();
--- do something with query ---
ProdQuery->Close();
I'm using the Advantage database set up as a local server. But I used
the same code when I was using the BDE & dBase tables. HTH.
Don
|
|
| Back to top |
|
 |
Jayme Jeffman Filho Guest
|
Posted: Tue Dec 20, 2005 7:13 pm Post subject: Re: Cancel TQuery |
|
|
Yes, your code is exactly as I usally do.
The problem is after calling the Open method, what happen if you call
immediately the Close one ? Will the Open operation be suspended ?
Or the Close method only will be performed when the Open finished ?
If so you are not able to interrupt an Open or Parse operation. While
the application is waiting for the database server you can not interrupt it.
Maybe using a thread .
HTH
Jayme.
"Don Locke" <dgnospamlocke (AT) comcast (DOT) net> escreveu na mensagem
news:43a84fca$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Here is some code that I use:
ProdQuery->Close();
ProdQuery->SQL->Clear();
ProdQuery->SQL->Add("SELECT * FROM Products");
ProdQuery->SQL->Add("WHERE Prod_code = :code");
ProdQuery->ParamByName("code")->AsString = sPcode;
if(!ProdQuery->Prepared)
ProdQuery->Prepare();
ProdQuery->Open();
--- do something with query ---
ProdQuery->Close();
I'm using the Advantage database set up as a local server. But I used the
same code when I was using the BDE & dBase tables. HTH.
Don
|
|
|
| Back to top |
|
 |
Robert den Holder Guest
|
Posted: Wed Dec 21, 2005 11:01 am Post subject: Re: Cancel TQuery |
|
|
As fas as I know, the Open() is a blocking function, so when you pass that
statement, the query is completed. I want to cancel the query during the
execution.
When I'm using ADO-queries, I can execute the query asynchronous. Then the
Open() isn't blocking anymore, but if I call Close() the query is still
executing in the background. If I wan't to change the SQL statement, I get
an error. Something like: "The query is still executing"
So, I don't have the solution yet, but I'm close :-)
Robert.
| Quote: | ProdQuery->Open();
--- do something with query ---
ProdQuery->Close();
I'm using the Advantage database set up as a local server. But I used the
same code when I was using the BDE & dBase tables. HTH.
Don
|
|
|
| Back to top |
|
 |
Don Locke Guest
|
Posted: Wed Dec 21, 2005 12:43 pm Post subject: Re: Cancel TQuery |
|
|
You should do a Query->Close() & then a Query->Clear() before attempting
to change the SQL statement. The query should stop executing when the
close statement is issued.
Don
|
|
| Back to top |
|
 |
Jayme Jeffman Filho Guest
|
Posted: Thu Dec 22, 2005 11:28 am Post subject: Re: Cancel TQuery |
|
|
I'm very sorry. I've never worked with ADO components.
Jayme.
|
|
| Back to top |
|
 |
|