Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What to do when user SQL Selects too much?
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01105674
Message ID:
01105807
Views:
22
This message has been marked as a message which has helped to the initial question of the thread.
>I have a situation when user may create a query/filter criteria that will make SQL Select to select up to 200,000 records (or even more). The problem with this is that 1) it takes too much time and I don't know how to "allow" user to cancel the selection. 2) I really would prefer to "stop" or not allow user to select that many records. I wish there were a way to set some criteria in SQL Select that would stop selecting once the number of selected records has reached a certain number.
>
>Any suggestion to deal with this situation?

What is your back end? You can do select count(*) first, then the actual select. This is the approach we're using here. If you use VFP native database, you can implement something like:
**************************************************
*-- Class:        cussqlthermo
*-- ParentClass:  custom
*-- BaseClass:    custom
*---Created by:   Mike Yearwood
*-- Time Stamp:   10/18/05 09:07:11 PM
*
define class cussqlthermo as custom

*-- Holds SET TALK setting at initialization.
	protected icOldSetTalk
	icOldSetTalk = ""
*-- Holds SET NOTIFY setting at initialization.
	icOldSetNotify = ""
*-- Holds the output window at initialization.
	protected icOldOutputWindow
	icOldOutputWindow = ""
*-- Holds the name of the temporary output window.
	protected icNewOutputWindow
	icNewOutputWindow = ""
*----Holds Escape settings
	protected cOnEscape
	cOnEscape= ""
	protected cSetEscape
	cSetEscape = ""
	name = "cussqlthermo"

	procedure destroy
	set talk off
	local ;
		lcNewOutputWindow, ;
		lcOldOutputWindow, ;
		lcOldSetNotify, ;
		lcOldSetTalk, lcOnEscape, lcSetEscape

	with this
		lcNewOutputWindow = .icNewOutputWindow
		lcOldOutputWindow = .icOldOutputWindow
		lcOldSetNotify = .icOldSetNotify
		lcOldSetTalk = .icOldSetTalk
		lcOnEscape = .cOnEscape
		lcSetEscape = .cSetEscape
	endwith

	if version(5)>=700
		set notify &lcOldSetNotify
	endif

	set talk &lcOldOutputWindow

	release windows &lcNewOutputWindow

	set talk &lcOldSetTalk
* Now restore our settings
	on escape &lcOnEscape

	if m.lcSetEscape = "OFF"
		set escape off
	else
		set escape on
	endif

	endproc

	procedure init
*Class that activates SQL thermometer bar during init
*and restores altered settings during destroy.

	with this

		.icOldSetTalk = set("TALK")
		set talk off

		.icOldOutputWindow = set("TALK",1)

		.icNewOutputWindow = "SQLThermo" + sys(2015)
		.cOnEscape = on('ESCAPE')
		.cSetEscape = set('ESCAPE')

		set escape on
		on escape plStop = YesNo("Are you sure you want to stop?")

		local m.lcNewOutputWindow
		lcNewOutputWindow = .icNewOutputWindow
		define window &lcNewOutputWindow. from -1000,-1000 to -500,-500
		activate window &lcNewOutputWindow. in screen

		set talk window &lcNewOutputWindow
		if version(5)>=700
			.icOldSetNotify = set("NOTIFY")
			set notify on
		endif
	endwith

	set talk on

	return .t.
	endproc

enddefine
*
*-- EndDefine: cussqlthermo
**************************************************
You would need to instantiate your class before doing select statement. In form's error method you can do:
lparameters tnError, tcMethod, tnLine, tcSys16, toErrObj, tcMessage
if m.tnError = 1839 && SQL-Select was cancelled

	if vartype(m.plStop) = "L" and m.plStop
* Have we stopped already?
		this.lRepeatRequery = .f.
	else
* RETRY  - doesn't work
		this.lRepeatRequery = .t.
	endif
else
	dodefault(m.tnError, m.tcMethod, m.tnLine, m.tcSys16, m.toErrObj, m.tcMessage)
endif
So, if the user pressed ESC and then answered No on the question, you would need to re-run your Select.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform