The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> ColdFusion Development
|
check if recordset exists?
Discuss check if recordset exists? in the ColdFusion Development forum on Dev Shed. check if recordset exists? ColdFusion Development forum discussing CFML coding practices, tips on CFML, and other CFML related topics. Find out why ColdFusion is the tool of choice for many e-commerce developers.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 2nd, 2005, 01:03 PM
|
|
Contributing User
|
|
Join Date: Aug 2003
Posts: 199
Time spent in forums: 15 h 47 m 4 sec
Reputation Power: 0
|
|
|
check if recordset exists?
how do i check if a recordset exists? i can't use isDefined() that wont work for queries. can't user .recordcount or len() because they assume and the recordset exists in the first place. any ideas?
|

March 2nd, 2005, 02:00 PM
|
|
Contributing User
|
|
Join Date: Dec 2004
Posts: 34
Time spent in forums: 3 h 13 m 46 sec
Reputation Power: 9
|
|
|
<cfif queryName.recordCount gt 0>
record set exists
</cfif>
|

March 2nd, 2005, 02:10 PM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
isDefined() will certainly work on a query name. You can also do:
<cfif structKeyExists( variables, 'myQueryName' )>
(assuming the query is in the variables scope of course).
|

March 3rd, 2005, 09:31 AM
|
|
Contributing User
|
|
Join Date: Aug 2003
Posts: 199
Time spent in forums: 15 h 47 m 4 sec
Reputation Power: 0
|
|
|
but isDefined() did NOT work, i got an error saying isDefined() will not work on complex variables, such as a recordset. and again, .recordcount did NOT work because that assumes the recordset exists in the first place. if the recordset does not exist it'll blow up saying ".recordcount is not defined in variable [insert name here]" or something along those lines
|

March 3rd, 2005, 09:49 AM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
You might try being a bit less emphatic, because I am telling you that you are doing something wrong. I think what you mean is "I can't make it work" or "It's not working for me". This code works fine and both conditions are met.
Code:
<cfquery name="qryGetCatalog" datasource="wegotwidgets">
select productID,
productName,
productDescription,
imageFile,
price
from Products
order by productName
</cfquery>
<cfif isDefined( 'qryGetCatalog' )>
its defined
</cfif>
<br><br>
<cfif structKeyExists( variables, 'qryGetCatalog' )>
the struct key exists
</cfif>
I recommend using structKeyExists() instead of isDefined() because it is more specific (it's forcing a lookup in only the variables scope, while isDefined() will automatically look for the variable in any of the auto-lookup scopes beyond the variables scope).
Last edited by kiteless : March 3rd, 2005 at 09:54 AM.
|

March 3rd, 2005, 12:07 PM
|
|
Contributing User
|
|
Join Date: Aug 2003
Posts: 199
Time spent in forums: 15 h 47 m 4 sec
Reputation Power: 0
|
|
|
oh ok i see... thanks!
|

December 4th, 2012, 05:17 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 1
Time spent in forums: 2 m 56 sec
Reputation Power: 0
|
|
|
Reason was Quotes
Just to clear things for future readers: this is a common error coldfusion programmers do - forgetting the quotes. I do not want to test if the variable in the content of qryGetCatalog exists, but the variable "qryGetCatalog" itself, so quotes are needed.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|