Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to implement a progress bar while running a remote v
Message
From
06/05/2021 00:30:13
Walter Meester
HoogkarspelNetherlands
 
 
To
05/05/2021 19:28:00
John Ryan
Captain-Cooker Appreciation Society
Taumata Whakatangi ..., New Zealand
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01680151
Message ID:
01680189
Views:
55
Likes (3)
>>>With asynchronous connections, you can do exactly that. I've got a search dialog that searches patients through an asynchronous query and displaying a animated GIF and at the same time being able to cancel out the search is perfectly possible and not even that difficult.
>
>Care to share the gist of it, after your earlier fabulous automagic connection preserver?! ;-)

My code involves a lot more than just the mechanism so I'll try to illustrate the neccesities. I've build it into a class with a timer part of it. So the following is from the top of my head and is not tested in any way.

First of all, you need a asynchronous connection
		THIS.Handle = SQLSTRINGCONNECT(THIS.ConnString)
		SQLSETPROP(THIS.handle, "Asynchronous", .T.)
		THIS.TIMER = CREATEOBJECT("Timer")
		THIS.TIMER.ENABLED = .F.
		THIS.TIMER.INTERVAL = 100
		BINDEVENT(THIS.TIMER, "Timer", THIS, "CheckResults")
Create a seperate method to execute the query
FUNCTION Start(cSql, cAlias)

		THIS.Alias = cAlias
		nRet=SQLEXEC(THIS.handle, cSQL, THIS.Alias)
		THIS.TIMER.ENABLED = .T.
		RETURN nRet
ENDFUNC
And do the checking in the CheckResults event (binded the timer.timer event)
FUNCTION CheckResults

	IF SQLGETPROP(THIS.h,"ConnectBusy") = .F.
		** e.g. An error occurred in successfully executing the query.
		RAISEEVENT(THIS, "QueryEnd")
		THIS.TIMER.ENABLED = .F.
	ELSE
		lRet= SQLEXEC(THIS.handle) > 0 AND  USED(THIS.Alias)
		IF lRet
			THIS.TImer.Enabled = .F.
			RAISEEVENT(THIS, "QueryEnd")  && Allows to use eventbinding in the calling functionality
		ENDIF
	ENDIF
ENDFUNC
Now its important to mention this works not work so well in the following conditions
1. Queries that return a lot of data over slow connections. The reason for this is that the SQLEXEC in the checkresults event will not be return control to VFP until all the data has been downloaded to VFP.

2. Some queries will return the first few results very quickly, but it might take some time to get the full resultset. This usually is caused by large table or index scans that need a lot of filtering. There is a simple workarround for this by ordering the result (using ORDER BY) in some way (not matching the clustered index) which forces SQL server to first get all the results before sending back to the results to VFP.

You can use SQLCANCEL to cancel the query at any time. At a minimum do this at the destroy of the class.
Previous
Reply
Map
View

Click here to load this message in the networking platform