Odd Issue w/ CFQueryParam
So, I ran into an interesting bug yesterday. Consider the following query:
datasource="#attributes.datasource#">
SELECT *
FROM #attributes.type#
WHERE id = <cfqueryparam
cfsqltype="CF_SQL_INTEGER" value="#attributes.id#" list="No" null="No">
</cfquery>
This was running fine, but all of a sudden began throwing the following error:
[Macromedia][SQLServer JDBC Driver]Value can not be converted to requested type.
I did a quick google search, but couldn't find anything clearly related - except for one post that suggested simply modifying the query by adding a semicolon. I did and the error went away.
It turns out that this error would return everytime I modified the table. I either had to modify the query or restart CF.
Apparently there is some caching involved of the table schema when using queryparam, and the change to the table schema confused CF.
However, it is not reproduceable. I tried to reproduce it again this morning and was not able to. My coworkers at Mindseye have also seen this and have not been able to reproduce it at will.
So - something to watch out for!

Only time it comes back to life is after a restart of the CF service.
Like yours, it seems to be random and I haven't been able to reproduce it at will.
I have been dealing with these issues for some time, and for while I thought no one believed me. Yes, CF does cache the schema of the db when using cfqueryparam... and if you change the table definition (even if you add fields that aren't used by the query), cfqueryparam will choke.
I can almost always reproduce it if the query is inside a CFC that's in a shared scope. I think the reason it doesn't seem reproducible is that CF caches a certain number of queries, and as ones that don't use cfqueryparam come in, yours get pushed out out the cache (and are reloaded, and don't error).
I made a few posts about it on the MM forums... Ike Dealy also mentioned it on his blog.
Not sure how shared scopes would affect this. Maybe the prepared statement is cached right in the persisted CFC instance, rather than the normal repository (where it can be knocked out of the queue like Dave said)?
Thanks for the entry!
select *
and I'm curious if anyone has had this problem with queries that don't use that? Has anyone submitted a bug report?
Helpful thread....
Has anyone submitted a bug request? I think this should qualify as one.
Thanks.
reinforces my general rule with coldfusion caching craziness "When in doubt kick it in the guts (restart JRUN)"
I'll bet just adding (or removing) a space in the query would have the same effect as adding a semicolon: it becomes a "new" CallableStatement, and will therefore appropriately map to the updated schema.
I got similar problem with this queries
<CFQUERY NAME="getMemberInfo" DATASOURCE="#Request.dsn#" USERNAME="#Request.uid#" PASSWORD="#Request.pwd#">
SELECT a.mem_id, a.firstname, a.lastname, b.status, c.role
FROM t_mems a, t_usrs b, t_roles c
WHERE a.mem_id = <CFQUERYPARAM CFSQLTYPE="cf_sql_integer" VALUE="10">
AND a.mem_id = b.usr_id
AND a.mem_id = c.mem_id
</CFQUERY>
It seems that when I put value 10 on cfqueryparam I got the error message but any other number except 10 is working fine.
Is number 10 some kind of magic number or I am missing something.
Regards
- Haris -
Just spent 45 minutes trying to figure out why after updating a table in my DB with two new rows any data I updated would succeed but then error upon request of the new data. Any record I had not updated would not error at all but all the data looked the same. Gack! Requesting updated data would generate the "[Macromedia][SQLServer JDBC Driver]Value can not be converted to requested type" error from this line of code, which worked perfectly for all data that hadn't been updated (and all data looked the same... sigh)
"WHERE game_id = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#url.id#">"
At a loss I googled the error, this page was the number one hit and one cold restart later I'm back to work! Speaking of cold, here's a cold one tipped in your general direction. Cheers mate!
I'm glad I found this page though, I was going crazy trying to figure out what the deal was.
You know, I'd wondered if caching was somehow involved and I thought I *had* modified the query in such a way that any cache should have been flushed. I had commented out everything between CFQUERY and /CFQUERY, and typed in its place a shorter, hardcoded version of the query to bypass CFQUERYPARAM. Of course the query worked so I undid my changes. By "recycling" the original CFQUERY tag, with an unchanged name attrib, I expected I'd eliminated the notion of caching as a culprit, per docs w/r/t CACHEDWITHIN and CACHEDAFTER. I'd be looking for the answer into my old age if I hadn't found your blog...
I guess my assumption having been wrong makes sense (for lack of a better term) in light of Daniel D's post, if the deal is indeed that the bug is related to having all where items built w/ CFQUERYPARAM. But talk about a needle in a haystack.
1. Go in the settings of the current datasource an UNCHECK 'Maintain Connections' --> submit the change
2. Rerun the page with the changed view/table/sp and make sure it's running fine.
3. Go back into the odbc settings an re-enable the 'Maintain Connections' --> submit the change
4. done!
Now everything should be working fine without restarting CF where a lot more i cached, like templates etc.
I have beat my head against a wall with this issue several times. Finding your post was like finding a pot of gold. Prefect fix - Thanks big time!
All other queries in CF without CFQUERYPARAMS are dynamically executed.
thanks bro