ColdFusion CFQueryParam List / Null Attributes Do Not Require YesNoFormat() (Thanks Elliott Sprehn!)

Posted July 17, 2007 at 2:01 PM by Ben Nadel

Tags: ColdFusion

I used to think that ColdFusion CFQueryParam's List and Null attributes required a "Yes" or "No" string. I always thought this was unusual, since so much of ColdFusion Yes/No attributes simply require a boolean value (ex. True, 1, 0, False). And, more than that, I could have sworn that I even tested this and was disappointed to see that true/false values actually threw ColdFusion exceptions!

But, apparently I read that somewhere and just accepted it like some ColdFusion Sheep in the herd. Thankfully, Elliott Sprehn has shown me the error of my ways. He told me that, like most of ColdFusion, the CFQueryParam Null and List attributes can, in fact, take standard boolean values:

  • <cfquery name="qTest" datasource="#REQUEST.DSN.Source#">
  • SELECT
  • id,
  • name
  • FROM
  • blog_entry
  • WHERE
  • date_created =
  • <cfqueryparam
  • value="2007/07/17"
  • cfsqltype="CF_SQL_TIMESTAMP"
  • null="#NOT IsNumericDate( '2007/07/17' )#"
  • />
  • OR
  • id IN
  • (
  • <cfqueryparam
  • value="1,2,3"
  • cfsqltype="CF_SQL_INTEGER"
  • list="true"
  • />
  • )
  • </cfquery>

When I run that, I get a ColdFusion query returned, not the formerly expected ColdFusion error. This is sweet-ass-sweet news! I always hated using the YesNoFormat() method as it adds so much noise to the already verbose ColdFusion CFQueryParam tag. This is gonna be so much nicer to use!




Reader Comments

Jul 17, 2007 at 5:18 PM // reply »
132 Comments

You're Welcome!


Jul 17, 2007 at 5:24 PM // reply »
11,243 Comments

I love learning these little things that end up having a huge impact on the way I code.


Jul 17, 2007 at 6:47 PM // reply »
17 Comments

Nice one Ben, for more reading: http://www.chapter31.com/2007/02/04/cfqueryparam-and-conditional-handling-of-nulls/


Feb 9, 2012 at 10:52 AM // reply »
2 Comments

Thank god for Ben Nadel blog posts. I've spent the last 30 mins trying to work out why my query was throwing an error.

Looking at your example I realised I was missing the brackets around the list. School boy error.

Thanks


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 22, 2013 at 5:35 PM
Script Tags, jQuery, And Html(), Text() And Contents()
This is still an issue 2 years later. jQuery is supposed to remediate these cross browser issues, no? I have been unable to find any statement from the jQuery team calling this behavior "by de ... read »
May 22, 2013 at 12:44 PM
Ask Ben: Query Loop Inside CFScript Tags
In cf10, if you call a function that has: local.result = {}; local.result.msg = ""; local.svc = new query(); local.svc.setSQL("SELECT * FROM..."); local.obj = local.svc.exe ... read »
May 22, 2013 at 12:29 PM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben: What version of Java are you using? Also, did you test users.id to see what Java reports as the data type? I wonder if it's not a Java primitive data type, but getting returned as something ... read »
May 22, 2013 at 11:47 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Dana, Awesome - so it looks like this bug was fixed in ColdFusion 10. Thanks so much for double-checking that. ... read »
May 22, 2013 at 11:37 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
When I c&p and run on cf10, I get: Selected User IDs: 1,4 User 1 selected: YES - YES User 2 selected: NO - NO User 3 selected: NO - NO User 4 selected: YES - YES User 5 selected: NO - ... read »
May 22, 2013 at 11:27 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Tom, Good thought, but no dice. Both of these still exhibit the same behavior: users.id[ users.currentRow ] users[ "id" ][ users.currentRow ] It's just something whacky happening with ... read »
May 22, 2013 at 11:07 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
Could your problem be that "users.id" is actually an ARRAY, not a single value? Perhaps try it again with "users.id[1]" (I only have CF8 here at work). ... read »
May 22, 2013 at 7:52 AM
Nested Views, Routing, And Deep Linking With AngularJS
Hi, Just a quick thank you. As it happens, for my own purposes, the pending ui-router work being done in native angular is likely the one I'll adopt, but your exploration, code and documentation of ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools