Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

Showing a status when long queries are running

I was wondering if there was a way to display a message, or some sort of status when a page is loading with a cfquery which takes a while to run.
0
mor4eus
Asked:
mor4eus
  • 5
  • 4
1 Solution
 
mor4eusAuthor Commented:
Close, but maybe I didn't explain properly.  It's not the data that it's returning that is taking a long time, its the query.  I am doing a select distinct(name) on a rather large table and it is taking a while to complete the sql command.  It only returns about 30 rows of data.
0
 
jimmy282Commented:
yes i agree but still this si what you want. you only wnt to display a message while the data is being loaded...these tags will solve your purpose....wont they?

Jimmy
0
[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

 
mor4eusAuthor Commented:
I tried using these tags, but I have found out(maybe wrong) that cold fusion will process a cfquery first.  This is why it takes for ever with a long query.  The scripts you suggested work, but only when displaying the data. Not reading it. What is happening is the cfm page waits until the query finishes, then starts loading the data.  If there is lots of data returned(eg over 20000 lines) the scripts display, but they don't display until the data is received from the sql query.  It was a good idea though.
0
 
mor4eusAuthor Commented:
I tried using these tags, but I have found out(maybe wrong) that cold fusion will process a cfquery first.  This is why it takes for ever with a long query.  The scripts you suggested work, but only when displaying the data. Not reading it. What is happening is the cfm page waits until the query finishes, then starts loading the data.  If there is lots of data returned(eg over 20000 lines) the scripts display, but they don't display until the data is received from the sql query.  It was a good idea though.
0
 
YogCommented:
maybe u need to optimise then - have you tried running the query over a Query analyser or converting it to a stored proc etc - can u paste the query - lol
0
 
mor4eusAuthor Commented:
I cannot optimise the query anymore.  It runs on a large table and just has to take a while.  I have found though with ColdFusion Server 5 a command called cfflush which will work for this problem.  Maybe I will have to wait for this unless anyone has anymore good ideas.  FYI the select query chooses the distinct on only one column but over 900,000 records.
0
 
jimmy282Commented:
<CFSETTING ENABLECFOUTPUTONLY="YES">
<!--- Optional Attributes --->
<CFPARAM NAME="Attributes.DISPLAY" DEFAULT="HTML">
<CFPARAM NAME="Attributes.JAVASCRIPT" DEFAULT="NO">
<CFPARAM NAME="Attributes.CHECKFOR" DEFAULT="PleaseWait">
<CFPARAM NAME="Attributes.BGCOLOR" DEFAULT="##FFFFFF">
<CFPARAM NAME="Attributes.FONTFACE" DEFAULT="Arial">
<CFPARAM NAME="Attributes.FONTSIZE" DEFAULT="2">
<CFPARAM NAME="Attributes.TITLE" DEFAULT="">
<CFPARAM NAME="Attributes.MESSAGE" DEFAULT="">
<CFPARAM NAME="Attributes.RequestTimeout" DEFAULT="">
<CFPARAM NAME="Attributes.SERVER_NAME" DEFAULT="#CGI.SERVER_NAME#">
<CFPARAM NAME="Attributes.PROTOCOL" DEFAULT="#CGI.SERVER_PORT#">
<CFIF ParameterExists(Caller.FORM.fieldnames)>
    <CFPARAM NAME="Attributes.FIELDNAMES" DEFAULT="#FORM.fieldnames#">
<CFELSE>
    <CFPARAM NAME="Attributes.FIELDNAMES" DEFAULT="">
</CFIF>

<CFSET Attributes.PROTOCOL = LCase(Attributes.PROTOCOL)>
<CFIF Attributes.PROTOCOL IS "443">
    <CFSET Attributes.PROTOCOL = "https">
<CFELSEIF Lcase(Attributes.PROTOCOL) NEQ "https">
    <CFSET Attributes.PROTOCOL = "http">
</CFIF>

<CFSET Attributes.FIELDNAMES = UCase(Attributes.FIELDNAMES)>

<CFSET Attributes.DISPLAY = Ucase(Attributes.DISPLAY)>
<CFSET Attributes.JAVASCRIPT = Ucase(Attributes.JAVASCRIPT)>

<CFIF (Attributes.JAVASCRIPT NEQ "YES") AND (Attributes.JAVASCRIPT NEQ "NO")>
    <CFSET Attributes.JAVASCRIPT = "NO">
</CFIF>

<CFIF Attributes.DISPLAY IS "JAVASCRIPT">
    <CFSET Attributes.JAVASCRIPT = "YES">
</CFIF>

<CFIF ((Trim(Attributes.TITLE) IS "") AND (IsDefined("Attributes.FIELDNAMES")) AND (Attributes.JAVASCRIPT

IS "NO")) OR (Attributes.DISPLAY IS "JAVASCRIPT")>
    <CFSET Attributes.TITLE = "Warning!">
<CFELSEIF Trim(Attributes.TITLE) IS "">
    <CFSET Attributes.TITLE = "Please Wait... Processing Request.">
</CFIF>

<CFIF ((Trim(Attributes.MESSAGE) IS "") AND (Trim(Attributes.FIELDNAMES) NEQ "") AND (Attributes.JAVASCRIPT

IS "NO")) OR (Attributes.DISPLAY IS "JAVASCRIPT")>
    <CFSET Attributes.MESSAGE = "The action you have chosen" & Chr(13) & Chr(10)>
    <CFSET Attributes.MESSAGE = Attributes.MESSAGE & "may take several minutes to complete.">
<CFELSEIF Trim(Attributes.MESSAGE) IS "">
    <CFSET Attributes.MESSAGE = "Please wait... This script is processing" & Chr(13) & Chr(10)>
    <CFSET Attributes.MESSAGE = Attributes.MESSAGE & "and may take several minutes to run.">
</CFIF>

<CFSET Query_String = CGI.QUERY_STRING>
<CFIF (Trim(Attributes.RequestTimeout) NEQ "") AND (Val(Attributes.RequestTimeout) GT 0)>
    <CFIF Len(Query_String) GT 0>
    <CFSET Query_String = Query_String & "&">
    </CFIF>
    <CFSET Query_String = Query_String & "RequestTimeout=#Attributes.RequestTimeout#">
</CFIF>

<CFSET PageToReload = "#Attributes.PROTOCOL#://#Attributes.SERVER_NAME##CGI.SCRIPT_NAME#?#Variables.Query_String#">
<CFIF Right(PageToReload,1) NEQ "?">
    <CFSET PageToReload = PageToReload & "&">
</CFIF>
<CFSET PageToReload = PageToReload & Attributes.CHECKFOR & "=OK">

<CFIF CGI.HTTP_REFERER IS "">
    <CFSET HTTP_REFERER = "#Attributes.PROTOCOL#://#Attributes.SERVER_NAME#/">
<CFELSE>
    <CFSET HTTP_REFERER = CGI.HTTP_REFERER>
</CFIF>

<CFIF Trim(Attributes.FIELDNAMES) NEQ "">
    <CFSET strHiddenForm = "<FORM ACTION=""#Variables.PageToReload#"" METHOD=""POST"" NAME=""cfPleaseWait"">"

& Chr(13) & Chr(10)>
    <CFLOOP INDEX="strVar" LIST="#Attributes.FIELDNAMES#" DELIMITERS=",">
         <CFSET strHiddenForm = strHiddenForm & "<INPUT TYPE=""HIDDEN"" NAME=""#strVar#"" VALUE=""#Evaluate(strVar)#"">"

& Chr(13) & Chr(10)>
    </CFLOOP>
    <CFIF Attributes.JAVASCRIPT IS "NO">
         <CFSET strHiddenForm = strHiddenForm & "<CENTER><INPUT TYPE=""Submit"" VALUE=""Click to Continue""></CENTER>"

& Chr(13) & Chr(10)>
    </CFIF>
    <CFSET strHiddenForm = strHiddenForm & "</FORM>" & Chr(13) & Chr(10)>
</CFIF>

<CFIF (IsDefined("URL.#Attributes.CHECKFOR#") IS "No") AND (Attributes.DISPLAY IS "JAVASCRIPT")>

<CFOUTPUT>
<HTML>
<HEAD>
    <TITLE>#Attributes.TITLE#</TITLE>
</HEAD>
<BODY BGCOLOR="#Attributes.BGCOLOR#"<CFIF Trim(Attributes.FIELDNAMES) NEQ ""> onLoad="this.document.forms[0].submit()"</CFIF>>

<CFIF Trim(Attributes.FIELDNAMES) NEQ "">
#strHiddenForm#
</CFIF>

<SCRIPT LANGUAGE="JavaScript">
<!--
result = confirm('#REReplace(Attributes.MESSAGE, "#Chr(13)##Chr(10)#", "\n", "ALL")#\n\nClick "OK" to

continue,\nclick "CANCEL" to go back');
if( result==true ) {
<CFIF Trim(Attributes.FIELDNAMES) NEQ "">
    this.document.forms[0].submit();
<CFELSE>
    self.location = '#Variables.PageToReload#';
</CFIF>
} else {
    self.location = '#Variables.HTTP_REFERER#';
}
//-->
</SCRIPT>

</BODY>
</HTML>
</CFOUTPUT>


<CFELSEIF (IsDefined("URL.#Attributes.CHECKFOR#") IS "No") AND (Attributes.DISPLAY IS "HTML")>


<CFOUTPUT>
<HTML>
<HEAD>
    <TITLE>#Attributes.TITLE#</TITLE>
<CFIF Trim(Attributes.FIELDNAMES) IS "">
    <META HTTP-EQUIV="REFRESH" CONTENT="0; URL=#Variables.PageToReload#">
</CFIF>
</HEAD>
<BODY BGCOLOR="#Attributes.BGCOLOR#"<CFIF Trim(Attributes.FIELDNAMES) NEQ ""> onLoad="this.document.forms[0].submit()"</CFIF>>


<FONT FACE="#Attributes.FONTFACE#" SIZE="#Attributes.FONTSIZE#">

<CENTER><H4>#Attributes.TITLE#</H4></CENTER>

<P><CENTER><TABLE WIDTH="300" BORDER="0"><TR><TD><FONT FACE="#Attributes.FONTFACE#" SIZE="#Attributes.FONTSIZE#">
#Attributes.MESSAGE#
</FONT></TD></TR></TABLE></CENTER></P>

<CFIF Trim(Attributes.FIELDNAMES) NEQ "">
#strHiddenForm#
</CFIF>

<CFIF (Trim(Attributes.FIELDNAMES) NEQ "") AND (Attributes.JAVASCRIPT IS "YES")>
<SCRIPT LANGUAGE="JavaScript">
<!--
    //document.cfPleaseWait.submit()
    //this.document.forms[0].submit();
//-->
</SCRIPT>
</CFIF>

</FONT>
</BODY>
</HTML>
</CFOUTPUT>


</CFIF>

<CFIF IsDefined("URL.#Attributes.CHECKFOR#") IS "No">
    <CFABORT>
</CFIF>

<CFSETTING ENABLECFOUTPUTONLY="NO">

i hope it helps

jimmy
0
 
jimmy282Commented:
here is a working example
p.s. the tag name is pleasewait.cfm


<!--- This prints the wait message --->
<CF_PleaseWait DISPLAY="HTML">

<CFIF ParameterExists(URL.PleaseWait)>
    <CFSET TimeStarted = Now()>
    <!--- This loop should take a little time to run --->
    <CFLOOP CONDITION="DateDiff('s', TimeStarted, Now()) LTE 5">

    </CFLOOP>
</CFIF>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

<HTML>
<HEAD>
    <TITLE>CF_PleaseWait Example Page</TITLE>
</HEAD>

<BODY BGCOLOR="#FFFFFF" VLINK="#800000" ALINK="#800000">
<FONT FACE="Arial" SIZE="2">

<CENTER><H3>CF_PleaseWait Example</H3></CENTER>

<P>This is an example of how CF_PleaseWait can be used. CF_PleaseWait
is easy to implement, and is designed to take care of of over-anxious
users who insist on repeatively clicking on hyperlinks and submit buttons
because they don't see an immediate result.</P>

<P>If you have any questions, comments or bugs to reportplease
e-mail me at <A HREF="mailto:drizzt@erinet.com">drizzt@erinet.com</A>.</P>

<FORM ACTION="example.cfm" METHOD="POST">
<CFPARAM NAME="Name" DEFAULT="">
<CFOUTPUT><INPUT TYPE="Text" NAME="Name" VALUE="#Name#"></CFOUTPUT>
<INPUT TYPE="Submit">
</FORM>

</FONT>
</BODY>
</HTML>
0
 
mor4eusAuthor Commented:
This is great.  Thanks jimmy282.  BTW here is their site.
http://www.pengoworks.com/index.cfm?action=cfPleaseWait
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now