Copy link to clipboard
Copied
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?
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))#">
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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))#">
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
However to say much beyond that is impossible without
actually seeing your code...
Two words for you "Jive software" ..
Copy link to clipboard
Copied
However to say much beyond that is impossible without
actually seeing your code...
Two words for you "Jive software" ..
<cfset someCodeHere = "no problem">
--
Adam
Copy link to clipboard
Copied
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 ..
Copy link to clipboard
Copied
<!--- which I am less
confident about working --->
--
Adam
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
<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==-
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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 😉