Coldfusion Query Param type changes from CF11 -> CF2018
I’m currently migrating from CF11 to CF2018 and one of the issues I’ve come up across is CF2018 being stricter on query param types.
I’d posted in the CFML Slack Channel asking if cfsql_numeric
was no longer a valid query param in CF2018.
I was quickly and correctly told by @bhartsfield that it wasn’t, but cf_sql_numeric
was valid (I had in fact made a typo in my param type).
Searching my code base revealed a mix of numeric
, cf_sql_numeric
and cfsql_numeric
, which confused me. If the cfsql_
prefix was wrong, how was the code working in CF11 and why was it now failing in CF2018?
I ran some example code side by side, using all 3 data types:
So as I now expected, cfsql_
prefix failed. Help from more Slack users @aliaspooryorik and @websolete
clarified how CF11 handled incorrect data types by converting them into a varchar
by default but CF2018 doesn’t do that now (which I think is better anyway)
The answers were of course in the manual all along, as well as the fact you don’t need the prefix anyway:
- CF2018+ Throws exceptions on invalid cfsqltype values, prior versions treated invalid types as varchar
- As of CF 11+ or Lucee 4.5+ you can omit the cf_sql_ prefix.
You can read it and more information at [cfdocs-query-param][CFDocs.org]
So I learnt 2 things from this:
- Making the time to go back through legacy code and drop the prefixes, when I first discovered they could be dropped, would have saved me from having to do it now.
- Be better at reading the manual