PROCESS.SQLAnalysis(PROGRAM(),JUSTEXT(PROGRAM()) + [_FirstSelect2],LINENO(1),.F.,[FiltersApplied: None Applied],[SQLAnalysis.htm])The SQLAnalysis program is:
******************************************************************* FUNCTION SQLAnalysis() ******************************************************************* * Method to track the efficiency of an SQL Select by * using Rushmore Optimization * Sample Call: * * PROCESS.SQLAnalysis(PROGRAM(),JUSTEXT(PROGRAM()) + [_FirstSelect],LINENO(1),.F.,[],[]) * <SQL SELECT TO ANALYZE> * PROCESS.SQLAnalysis(PROGRAM(),JUSTEXT(PROGRAM()) + [_FirstSelect],LINENO(1),.T.,[FiltersApplied: lcSelection= ] + lcSelection,[SQLAnalysis.htm]) ******************************************************************** LPARAMETERS tcMethod, tcSelectName, tnLineNo, tlWriteToFile,tcFiltersApplied,tcFileName LOCAL lcProperty, lnRushmoreType, lcDuration, lcHTMLHeader, lcHTMLFooter * * [*] in cCompanyName indicates to do the analysis otherwise don't do the * analysis at all * IF [*] $ gowcserver.cCompanyName * * Add the Property for the SQL being tested and set value to * current time * lcProperty = [this.] + tcSelectName IF VARTYPE(&lcProperty) = [U] * * Property doesn't exist, add it and use * Sys(2) to set it to the value * of the number of seconds since Midnight * ADDPROPERTY(This,tcSelectName,SYS(2)) ENDIF IF tlWriteToFile = .F. * * Turn on the Rushmore Optimization Assessment * PUBLIC tcSqlSelect * * The number of [*]'s in CompanyName indicates * the type of analysis to do * DO CASE CASE [****] $ gowcserver.cCompanyName lnRushmoreType = 12 CASE [***] $ gowcserver.cCompanyName lnRushmoreType = 2 CASE [**] $ gowcserver.cCompanyName lnRushmoreType = 11 OTHERWISE lnRushmoreType = 1 ENDCASE =SYS(3054,lnRushmoreType,"tcSqlSelect") ELSE lcProperty = [this.] + tcSelectName * * Calculate duration by subtracting current Sys(2) * value from that value stored in the custom * property * lcDuration = ALLTRIM(STR(VAL(SYS(2)) - VAL(&lcProperty))) * * Going with all files an htm file, force it if legacy call has [.txt] * IF PCOUNT() <> 6 tcFileName = ALLTRIM(This.oCurrentUser.oData.in_login) + [_SQLAnalysis.htm] ELSE tcFileName = ALLTRIM(This.oCurrentUser.oData.in_login) + [_] + ALLTRIM(tcFileName) tcFileName = STRTRAN(tcFileName,[.txt],[.htm]) ENDIF IF !FILE(goWCServer.cDataPath + tcFileName) * * First Time creating the Analysis file for the user * Prepend the Header information which includes * CSS styles for colorizing Rushmore analysis results * lcHTMLHeader = This.CreateAnalysisHeader() lcHTMLFooter = [</body></html>] ELSE lcHTMLHeader = [] lcHTMLFooter = [] endif * * StrTran results to get aesthetics in htm file * tcSqlSelect=STRTRAN(tcSqlSelect,CHR(10),[<br>]) tcSqlSelect=STRTRAN(tcSqlSelect,[: full],[:<span class="full"> full</span>]) tcSqlSelect=STRTRAN(tcSqlSelect,[: none],[:<span class="none"> none</span>]) tcSqlSelect=STRTRAN(tcSqlSelect,[: partial],[:<span class="partial"> partial</span>]) * * Write results to file * STRTOFILE( IIF(EMPTY(lcHTMLHeader) ,[<br>], lcHTMLHeader + [<br>]) + ; [Current User: ] + ALLTRIM(This.oCurrentUser.oData.in_login) + ; [<br>] + ; [User Type: ] + ALLTRIM(this.oCurrentUser.oData.in_type) + ; [<br>] + ; [ALIAS: ] + IIF(_tally = 0,[No Records Returned],ALLTRIM(ALIAS())) + ; [<br>] + ; [Records Returned: ] + IIF(_tally = 0,[No Records Returned],ALLTRIM(STR(RECCOUNT(ALIAS())))) + ; [<br>] + ; [DateTime: ] + TTOC(DATETIME()) + [<br>] + ; [Method: ] + ALLTRIM(tcMethod) + [<br>] + ; [Line No: ] + ALLTRIM(STR(tnLineNo)) + [<br>] + ; [Duration: ] + lcDuration + [<br>] + ; tcFiltersApplied + [<br>] + ; [Select: ] + tcSelectName + ; tcSqlSelect + [<br>], goWCServer.cDataPath + tcFileName,1) RELEASE tcSqlSelect =SYS(3054,0) REMOVEPROPERTY(this,tcSelectName) ENDIF ENDIF ENDFUNCWhich gives me an HTML file containing each SQL's analysis in the below format:
Current User: JJB User Type: SP ALIAS: CURSROORDERS Records Returned: 1432 DateTime: 10/10/2006 12:03:49 Method: ARFS.BUILDPREVIOUSORDERS Line No: 212 Duration: 7 FiltersApplied: lcSelection= sro.Case_id ='0000006913' Select: BUILDPREVIOUSORDERS_FirstSelect SELECT sro.firm_id as Firm_ID, sro.sro_id as sro_id, sro.case_id as case_id, MAX(sro.client) as Client, MAX(sro.srref) as SRRefNo FROM Analyzer!sro WHERE &lcSelection AND INLIST(sro.sro_status,10,20,30,33,40) AND sro.type = "I" GROUP BY 1, 2, 3 INTO CURSOR curSROOrders readwrite Using index tag Case_id to rushmore optimize table sro Using index tag Sro_status to rushmore optimize table sro Using index tag Type to rushmore optimize table sro Using index tag _del to rushmore optimize table sro Rushmore optimization level for table sro: fullSorry for the long post, and again, thanks for any help. Hopefully the knowledge I gain on the first select will help in the others.