Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
I am the chief technical officer at InVision App, Inc - a prototyping and collaboration platform for designers, built by designers. I also rock out in JavaScript and ColdFusion 24x7.
Meanwhile on Twitter
Loading latest tweet...
Ben Nadel at cf.Objective() 2013 (Bloomington, MN) with:

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

By Ben Nadel on
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

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

Reply to this Comment

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Oops!
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.