Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Inefficient query
Message
De
29/01/2007 14:25:00
 
 
À
27/01/2007 15:38:46
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01188966
Message ID:
01190253
Vues:
16
Thanks for both your help,

I've now got the once-monolithic procedure decomposed a bit.

PrepareQuery - extracts criteria from the web form. At least one must be populated for the query to run. This is to prevent someone from requesting the entire data set. The xml code preserves the result set as XML in a memo in the user table. This allows me to return to previous search results without re-running the query. Upon logout that memo gets cleared.

RunQuery - runs the SQL query
GetFilters - creates the added criteria inserted into the WHERE clause. This will always at least contain one filter criteria, enforced by the calling procedure.

The resulting query is able to benefit from rushmore optimization. All I have left to do now is to try to fix up the TEXTMERGE code as Naomi suggested to improve that part.
Procedure PrepareQuery
	lcFromAccount = Upper(Request.Form("From_Account"))
	lcToAccount = Upper(Request.Form("To_Account"))
	lcContract = Upper(Request.Form("Contract"))
	lcAddress = Upper(Request.Form("Address"))
	lcName = Upper(Request.Form("Borrowername"))
	lcParcel = Upper(Request.Form("Parcel"))
	lcCounty = Upper(Request.Form("County"))
	lcSt = Upper(Request.Form("State"))
	lcCollector = Upper(Request.Form("Collector"))
	lcBranch = Upper(Request.Form("Branch"))

	lcChk = lcFromAccount+lcToAccount+lcContract+lcAddress+lcName+lcParcel+lcCounty+lcSt+lcCollector+lcBranch

	If !Empty(lcChk)

		Select Users
		Do runquery


		Select Users
		Repl workarea1 With datatoxml([temp])

	Else
		If !Empty(Users.workarea1)
			xmltodata(Users.workarea1,[temp])
		Endif
	Endif

Endproc

Procedure runquery
	Local lcWhere, lnX

	lcWhere = GetFilters()
	lnX = Len(lcWhere) - 3	&& get rid of leading [AND] in filter string
	lcWhere = Right(lcWhere,lnX)

	Set Ansi On
	Select a.wcode, Min(d.st+d.cnty+d.unit) As collector, b.display_loan, d.acct, b.borrowername, a.branch, Min(b.Id) As loan_id, Min(a.Id) As property_id ;
		from mtgproperty a , ;
		mtgloan b, ;
		mtgacctnum d;
		INTO Cursor temp ;
		where (a.client_id = Users.client_id);
		AND (b.Id = a.loan_id );
		and (a.Id = d.property_id )And &lcWhere ;
		GROUP By  1, 3, 4, 5, 6

Endproc

Function GetFilters
	Local lcFilter, lcCRLF
*!*		lcFromAccount
*!*		lcToAccount
*!*		lcContract
*!*		lcAddress
*!*		lcName
*!*		lcParcel
*!*		lcCounty
*!*		lcSt
*!*		lcCollector
*!*		lcBranch
	lcFilter = []
	lcCRLF = Chr(13)+Chr(10)
	If !Empty(lcFromAccount)
		lcFilter = lcFilter + [AND (b.loan >= lcFromAccount)]
	Endif
	If !Empty(lcToAccount)
		lcFilter = lcFilter + [AND (b.loan <= lcToAccount)]
	Endif
	If !Empty(lcContract)
		lcFilter = lcFilter + [AND (b.contract == lcContract)]
	Endif
	If !Empty(lcAddress)
		lcFilter = lcFilter + [AND (a.situs_addr1 == lcAddress)]
	Endif
	If !Empty(lcName)
		lcFilter = lcFilter + [AND (b.borrowername == lcName)]
	Endif
	If !Empty(lcParcel)
		lcFilter = lcFilter + [AND (d.acct == lcParcel)]
	Endif
	If !Empty(lcCounty)
		lcFilter = lcFilter + [AND (a.county == lcCounty)]
	Endif
	If !Empty(lcSt)
		lcFilter = lcFilter + [AND (a.st == lcSt)]
	Endif
	If !Empty(lcCollector)
		lcFilter = lcFilter + [AND (d.st+d.cnty+d.unit == lcCollector)]
	Endif
	Return lcFilter
Endfunc
Jim Newsom
IT Director, ICG Inc.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform