Hi,
Say I have a page that takes in 8 url parameters (url.A, url.B, url.C, ...). Now I want to insert this into my table using <cfqueryparam>
Now, my problem is some of these variables I am inserting are optional. For example, url.B can be a blank. However, if it's left blank, the code above will trigger an error as it's expecting url.B to be of tinyint value. And a blank is not a tinyint.
I know I can insert a null by using <cfqueryparam null="yes">. However this requires me to check whether url.B is blank.
Since there are quite a few optional variables, I would need to repeat it for each variable. It's cumbersome and ugly.
Does anyone have an idea how I can simplify this?
Thank you.
Min
Say I have a page that takes in 8 url parameters (url.A, url.B, url.C, ...). Now I want to insert this into my table using <cfqueryparam>
Code:
<cfquery>
insert into tableX(colA, colB, colC, ...)
values(<cfqueryparam value="#url.A#" cfsqltype="cf_sql_varchar"),
<cfqueryparam value="#url.B#" cfsqltype="cf_sql_tinyint"),
<cfqueryparam value="#url.C#" cfsqltype="cf_sql_tinyint"), ...)
</cfquery>
Now, my problem is some of these variables I am inserting are optional. For example, url.B can be a blank. However, if it's left blank, the code above will trigger an error as it's expecting url.B to be of tinyint value. And a blank is not a tinyint.
I know I can insert a null by using <cfqueryparam null="yes">. However this requires me to check whether url.B is blank.
Code:
insert into tableX(....)
<cfif url.B neq ''>
<cfqueryparam value="#url.B#" cfsqltype="cf_sql_tinyint">
<cfelse>
<cfqueryparam value="#url.B#" null="yes">
</cfif>
Since there are quite a few optional variables, I would need to repeat it for each variable. It's cumbersome and ugly.
Does anyone have an idea how I can simplify this?
Thank you.
Min