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

<CFQUERYPARAM Null attribute did not work!

Community Beginner ,
Jun 27, 2011 Jun 27, 2011

Hi All!

From what I learned, cfqueryparam's null attribute should be very useful for this scenario:

<CFIF IsDefined("Form.Name") AND Form.Name NEQ "">

Do this

<CFELSE>

Do That

</CFIF>

With the null attribute from cfqueryparam, we can write a clean and more elegant code like this:

<CFIF IsDefined("Form.Name") AND Form.Name NEQ "">

   <CFQUERYPARAM cfsqltype="cf_sql_varchar" value="#Trim(Form.Name)#" null="#NOT Len(Trim(Form.Name))#">

</CFIF>

But when I tried it on my INSERT statement, I got error message saying that the amount of columns don't match it's values. I counted more than once

they exactly matched up.

I modified the same insert statement with values changed to use cfiif cfelse method, it worked. When I changed it back to use cfqueryparam and its null attribute, it did not work again because when form.name is blank/null, cfqueryparam did not insert the NULL value the way cfif Isdefined expression does

I also tried using yesNoFormat and still did not work.

Is this a bug?

TOPICS
Getting started
2.4K
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

Valorous Hero , Jun 27, 2011 Jun 27, 2011

Is this a bug?

No. Your two statements are not equivalent. Unlike the first statement, the second one does nothing if the field does not exist or is empty:

<CFIF IsDefined("Form.Name") AND Form.Name NEQ "">

      create cfqueryparam

<CFELSE>

       do nothing  ....

</CFIF>

If you used <cfparam> to ensure FORM.Name always exists, then you could simply write:

       <CFQUERYPARAM cfsqltype="cf_sql_varchar" value="#Trim(Form.Name)#" null="#NOT Len(Trim(Form.Name))#">
Translate
New Here ,
Jun 27, 2011 Jun 27, 2011

Greetings,

I will be out of the office on Monday and Tuesday, June 27 and 28. I will respond to all emails when I return.

Thanks,

Ron Barth

Alternative Systems

www.altsystem.com

603.537.9473

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
Participant ,
Jun 27, 2011 Jun 27, 2011

You still need the cfelse for when the cfif contition is not true

or you will not have a cfqueryparam to match the insert column.

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
Valorous Hero ,
Jun 27, 2011 Jun 27, 2011

Is this a bug?

No. Your two statements are not equivalent. Unlike the first statement, the second one does nothing if the field does not exist or is empty:

<CFIF IsDefined("Form.Name") AND Form.Name NEQ "">

      create cfqueryparam

<CFELSE>

       do nothing  ....

</CFIF>

If you used <cfparam> to ensure FORM.Name always exists, then you could simply write:

       <CFQUERYPARAM cfsqltype="cf_sql_varchar" value="#Trim(Form.Name)#" null="#NOT Len(Trim(Form.Name))#">
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
LEGEND ,
Jun 27, 2011 Jun 27, 2011

Is this a bug?

Yep.  But it'll be a bug in your code, not CF's.

However to say much beyond that is impossible without actually seeing your code...

--

Adam

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
Valorous Hero ,
Jun 27, 2011 Jun 27, 2011

However to say much beyond that is impossible without

actually seeing your code...

Two words for you "Jive software" ..

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
LEGEND ,
Jun 27, 2011 Jun 27, 2011

However to say much beyond that is impossible without

actually seeing your code...

Two words for you "Jive software" ..

<cfset someCodeHere = "no problem">

--

Adam

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
Valorous Hero ,
Jun 27, 2011 Jun 27, 2011

Two words for you "Jive software" ..

 

<cfset someCodeHere = "no problem">

 

--

Adam

Weird. I thought the code was removed from emails (or sometimes) and that is why you could not see it. But yours came through fine. Go figure ..

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
LEGEND ,
Jun 27, 2011 Jun 27, 2011

<!--- which I am less

confident about working --->

--

Adam

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
LEGEND ,
Jun 27, 2011 Jun 27, 2011

Adam Cameron. wrote:

<!--- which I am less

confident about working --->

No.  No I didn't post that.

I posted *this*:

<cfset previousOne = "done via the web UI">
<cfset thisOne = "done via replying to email"> <!--- which I am less confident about working 😉 --->

--

Adam

Message was edited by: Adam Cameron.

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
Valorous Hero ,
Jun 27, 2011 Jun 27, 2011

<cfset someCodeHere = "no problem">

--

Adam

Testing

    a = "b";

</cfscript

... Once again, in its raw (un-mangled) format:

Testing

<cfset foo = "bar">
<cfquery name="x" datasource="y">
      SELECT getDate() as TheDate
</cfquery>

<cfscript>
    a = "b";
</cfscript>

Message was edited by: -==cfSearching==-

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
LEGEND ,
Jun 27, 2011 Jun 27, 2011

Two words for you "Jive software" ..

Oh, and don't get me wrong.  The software these forums run on is sh!te, I agree.  And it's an embarrassment for the company that created it that they are prepared to put their name on it (at the bottom of every page), and an embarrassment that Adobe chose to use it.

But one can post code.

--

Adam

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
Valorous Hero ,
Jun 27, 2011 Jun 27, 2011

But one can post code.

--

Adam

Oh, I know. But he did post some code. See the two snippets in the first post. Though not a lot of code, it was enough to show his two CFIF statements were not equivalent. I just thought maybe you were responding via email and could not see it.

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
LEGEND ,
Jun 27, 2011 Jun 27, 2011

Oh, I know. But he did post some code. See the two snippets in the first post. Though not a lot of code, it was enough to show his two CFIF statements were not equivalent. I just thought maybe you were responding via email and could not see it.

Ah, I see.  No, I saw what he posted.  But there's not enough code there to point at the bit where it's wrong and go "that's the bit that's wrong".

I'm guessing it's because the conditionals on the column refs and the values are different, but I'm tired of this game we play of "guess what the code says".  You might have noticed an increasing number of my posts are a bit blunt about that 😉

--

Adam

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
Valorous Hero ,
Jun 27, 2011 Jun 27, 2011
LATEST

Ah, I see.  No, I saw what he posted.  But there's not

enough code there to point at the bit where it's wrong and

go "that's the bit that's wrong".

That is what I thought at first too. But looking it over again, I realized there was enough information.

but I'm tired of this

game we play of "guess what the code says".  You might have

noticed an increasing number of my posts are a bit blunt

about that

I will agree with you there. I have definitely seen some "ambiguous" posts that are, shall we say, in need of some bluntness 😉

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