Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Assigning a Variable a Null Value

New Here ,
Dec 03, 2008 Dec 03, 2008
Hi all. I've got a loop that queries a query outside of the loop. The problem is, the query may get defined, and it may not. But if it gets defined, how do I undefine it for the next loop iteration. Here's some code to wrap your head around it (edited for brevity).

<cfloop>
<cfset queryValue = possibleEmptyString >
<cfif Len(queryValue)>
<cfquery name="queryName" dbtype="query">
select * from something
</cfquery>
</cfif>

<cfif IsDefined("queryName") AND queryName.RecordCount>
error="some error message"
</cfif>
</cfloop>

So, is there not a Function that sets the var to Undefined, or Null, or something? If not, what's the alternative?

Thanks all! 😉
591
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Dec 04, 2008 Dec 04, 2008
<cfloop>
<cfset queryValue = possibleEmptyString >
<cfset queryName = QueryNew()> <!--- this ensures that queryName is always defined, and is always a query --->
<cfif Len(queryValue)>
<cfquery name="queryName" dbtype="query">
select * from something
</cfquery>
</cfif>

<cfif queryName.RecordCount>
error="some error message"
</cfif>
</cfloop>
Translate
LEGEND ,
Dec 03, 2008 Dec 03, 2008
You can set a var to an empty string. For what you appear to be attempting, either cftry/cfcatch, or isQuery() might be useful.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 04, 2008 Dec 04, 2008
Thanks Dan. But, that won't quite solve my problem.

The problem is that once it becomes a query, I can't reset it back to a String value because I've already turned it into a complex type so IsQuery() it will always return true.

not sure how using a try/catch will solve it either. Am I missing something here?

Thanks for your reply, I appreciate the attentiont to this issue.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 04, 2008 Dec 04, 2008
LATEST
<cfloop>
<cfset queryValue = possibleEmptyString >
<cfset queryName = QueryNew()> <!--- this ensures that queryName is always defined, and is always a query --->
<cfif Len(queryValue)>
<cfquery name="queryName" dbtype="query">
select * from something
</cfquery>
</cfif>

<cfif queryName.RecordCount>
error="some error message"
</cfif>
</cfloop>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources