Board index » delphi » Killing a query before it is finished

Killing a query before it is finished

In one of our applications users will occasionally run a long query, and
want to kill it before it is done. The queries usually just call stored
procedures that must do a fair amount of processing before they return
results. What's the best way to give the user  a "cancel" button?

The only way I can figure out how to do it is to spin the query off
using a separate thread, then kill the thread. This leaves the query
still running on the server, so we have to issue the SQL command "Kill
<spid>". Unfortunately, killing a spid means losing the whole
connection, so we would have to use a separate database component and
open up a new connection into the database just for this query. Surely
there is a better way.

We're using Delphi 3, SQL Links, the BDE, and Sybase Adaptive Server
11.5.

Chris

--
Chris Cleveland
Genesee Development Group, Inc.
2000 North Racine Avenue, Suite 4100
Chicago, Illinois  60614
773.528.1700 voice, 773.528.8862 fax
http://genesee.net
cclevel...@genesee.net

 

Re:Killing a query before it is finished


Quote
>In one of our applications users will occasionally run a long query, and
>want to kill it before it is done. The queries usually just call stored
>procedures that must do a fair amount of processing before they return
>results. What's the best way to give the user  a "cancel" button?

Ctrl-C I believe works in Delphi. (At least for Oracle)

Roger

Re:Killing a query before it is finished


Sybase (and only Sysbase) supports the OnServerYield property of TQuery.  To
cancel the query you set the AbortQuery parameter to TRUE.

Quote
Chris Cleveland wrote in message <357F0E3B.AA116...@genesee.net>...
>In one of our applications users will occasionally run a long query, and
>want to kill it before it is done. The queries usually just call stored
>procedures that must do a fair amount of processing before they return
>results. What's the best way to give the user  a "cancel" button?

>The only way I can figure out how to do it is to spin the query off
>using a separate thread, then kill the thread. This leaves the query
>still running on the server, so we have to issue the SQL command "Kill
><spid>". Unfortunately, killing a spid means losing the whole
>connection, so we would have to use a separate database component and
>open up a new connection into the database just for this query. Surely
>there is a better way.

>We're using Delphi 3, SQL Links, the BDE, and Sybase Adaptive Server
>11.5.

>Chris

>--
>Chris Cleveland
>Genesee Development Group, Inc.
>2000 North Racine Avenue, Suite 4100
>Chicago, Illinois  60614
>773.528.1700 voice, 773.528.8862 fax
>http://genesee.net
>cclevel...@genesee.net

Re:Killing a query before it is finished


Hi Chris,

I think you have to run your query within a seperate thread.
That give you to chance to press a button, alter some values ...

HTH

Karsten

On Tue, 16 Jun 1998 21:13:44 -0500, Chris Cleveland

Quote
<cclevel...@genesee.net> wrote:
>Thanks for the response.

>While the query is processing there is no way, to the best of my knowledge, to
>let a user click a Cancel button because the query doesn't let the app process
>messages while it is running. I actually tried the OnServerYield event, but for
>some reason it never gets called. Am I missing something?

>--
>Chris Cleveland
>Genesee Development Group, Inc.
>2000 North Racine Avenue, Suite 4100
>Chicago, Illinois  60614
>773.528.1700 voice, 773.528.8862 fax
>http://genesee.net
>cclevel...@genesee.net

>Chris Wennersten wrote:

>> Sybase (and only Sysbase) supports the OnServerYield property of TQuery.  To
>> cancel the query you set the AbortQuery parameter to TRUE.

>> Chris Cleveland wrote in message <357F0E3B.AA116...@genesee.net>...
>> >In one of our applications users will occasionally run a long query, and
>> >want to kill it before it is done. The queries usually just call stored
>> >procedures that must do a fair amount of processing before they return
>> >results. What's the best way to give the user  a "cancel" button?

>> >The only way I can figure out how to do it is to spin the query off
>> >using a separate thread, then kill the thread. This leaves the query
>> >still running on the server, so we have to issue the SQL command "Kill
>> ><spid>". Unfortunately, killing a spid means losing the whole
>> >connection, so we would have to use a separate database component and
>> >open up a new connection into the database just for this query. Surely
>> >there is a better way.

>> >We're using Delphi 3, SQL Links, the BDE, and Sybase Adaptive Server
>> >11.5.

>> >Chris

>> >--
>> >Chris Cleveland
>> >Genesee Development Group, Inc.
>> >2000 North Racine Avenue, Suite 4100
>> >Chicago, Illinois  60614
>> >773.528.1700 voice, 773.528.8862 fax
>> >http://genesee.net
>> >cclevel...@genesee.net

Other Threads