[thelist] CF: IsDefined() and Len() in one?

Joshua OIson joshua at alphashop.net
Tue May 8 06:31:36 CDT 2001


CF 5.0 will include custom functions, which should provide some relief for
these sorts of issues.  You will be able to do something along the lines of:

<cfquery>
  SELECT id, name
  FROM mytable
  WHERE field1 = 5
    #ConditionalAnd("field2", "myvar")#
</cfquery>

where ConditionalAnd is a function that returns AND field2 = #myvar# if
myvar fulfills requirements and returns nothing if myvar fails those
requirements.  In this case, the requirements would me that its defined and
has a length.

In the meanwhile, you could use a custom tag to accomplish the same thing.
Such as the following definition for a "QueryAnd" tag:

<cfquery>
  SELECT id, name
  FROM mytable
  WHERE field1 = 5
    <cf_qAND var="myvar" field="field2"></cf_qAND>
</cfquery>

The custom tag would take the inputs, do the checks (isDefined and Len)
based on the values of the attribute "var" and set its GeneratedContent to
the appropriate SQL code.

This obfuscation clearly shows one place where most other languages
(unfortunately) have a huge leg up on CF.  But, like Frank said, where
there's a will, there's a way.

HTH,
-joshua






More information about the thelist mailing list