Skip to main content
Participant
September 23, 2010
Question

Cached Query

  • September 23, 2010
  • 3 replies
  • 595 views

I have a situation that shows up every once in awhile and I'm not sure why it's occuring.

I have a query that is cached and just below the query I display information from that query. Sometimes coldfusion will say the variable from the query does not exist. I don't understand why this happens since the query is directly above the output and I'm asking for the number of records so I should atleast get a number.

Example:

<cfquery name="NumLogins" datasource="#application.datasource#" dbtype="ODBC" cachedwithin="#application.admin_query_cache_time#">
select login_id from logins where company_id = #company_id# and company_login_id = #company_login_id#
</cfquery>

Number of Logins: <cfoutput>#NumLogins.recordcount#</cfoutput>

Any help would be greatly appreciated.

Thanks!

Torri

This topic has been closed for replies.

3 replies

BKBK
Community Expert
Community Expert
October 11, 2010

Two suggestions: first remove the dbtype attribute. There is no reason for it. Secondly, the variable application.admin_query_cache_time might have something to do with your problem.

How is the variable application.admin_query_cache_time defined? What datatype is it?

The following should help you solve the problem completely:

<cftry>

<cfquery  name="NumLogins" datasource="#application.datasource#" dbtype="ODBC"  cachedwithin="#application.admin_query_cache_time#">
select login_id from logins where company_id = #company_id# and company_login_id = #company_login_id#
</cfquery>

Number of Logins: <cfoutput>#NumLogins.recordcount#</cfoutput>

<cfcatch type="any">

<cfdump var="#cfcatch#">

</cfcatch>

</cftry>

BreakawayPaul
Inspiring
September 30, 2010

Not sure if it's the cause of your problem, but I've had horrible luck with trying to assign cache timespans to variables and getting them to work.  I always seem to have to hard code a createtimespan() value into a cachedwithin().  Maybe you're trying to read from a cached query that isn't there.

September 24, 2010

Please check whether the variable is defined before display using IsDefined()