stopping a long running query

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
mika
Posts: 20
Joined: Thu 08 May 2014 06:15

stopping a long running query

Post by mika » Thu 28 Jul 2022 08:53

Hi,

We have search functionality in our app, customer use it usually very nicely but sometimes they enter searchterms which cause query to run very longtime and they wan't to cancel it.
Since queries are blocking, it can't be terminated.

This idea sounds ugly, but in separete test app it works:
Create a separete Uniconnection and Uniquery
Pass them to iTask, which runs actual query.
If users wan't to cancel task, call uniconnection.disconnect, catch exceptions. Free components.

I feel this sounds dangerous / can cause un expected behaviour, but is is dangerous?
I'm using Actian ZEN with ODBC.

pavelpd
Devart Team
Posts: 109
Joined: Thu 06 Jan 2022 14:16

Re: stopping a long running query

Post by pavelpd » Tue 23 Aug 2022 09:17

Hi Mika,
Thanks for contacting us!

Please be informed, that there is no danger in canceling the select request.

For example, if you want to limit the request by time, you can use the "CommandTimeout" option.
Example:

Code: Select all

...
try
...
	UniQuery.SQL.Text := 'SELECT ...'; //some big SQL query
	UniQuery.SpecificOptions.Values['CommandTimeout'] := '60'; time is in seconds
	UniQuery.Open;
...
except
	On E: EUniError do
	begin
		//some exception handling logic
	...
	end;
...
end;
...

You can find the description of the "CommandTimeout" option and other ODBC-specific options via the link: https://docs.devart.com/unidac/using-odbc-provider.htm

In case if you want to give the user the ability to cancel a long running request, you can alternatively try doing it on a separate thread.

mika
Posts: 20
Joined: Thu 08 May 2014 06:15

Re: stopping a long running query

Post by mika » Thu 15 Sep 2022 12:22

Thanks for answer!
Command timeout helps a lot.

pavelpd
Devart Team
Posts: 109
Joined: Thu 06 Jan 2022 14:16

Re: stopping a long running query

Post by pavelpd » Mon 26 Sep 2022 14:46

Hi,

You're always welcome!

Please feel free to contact us if you have any further questions about our products!

Post Reply