Page 1 of 1

stopping a long running query

Posted: Thu 28 Jul 2022 08:53
by mika
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.

Re: stopping a long running query

Posted: Tue 23 Aug 2022 09:17
by pavelpd
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.

Re: stopping a long running query

Posted: Thu 15 Sep 2022 12:22
by mika
Thanks for answer!
Command timeout helps a lot.

Re: stopping a long running query

Posted: Mon 26 Sep 2022 14:46
by pavelpd
Hi,

You're always welcome!

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