Thursday 22 August 2013

Minor common-sense tweak to CFML from Railo

G'day:
This is just a quick confirmation I was wrong about something.

On Twitter this afternoon, Gert observed that Railo supports this sort of thing:

<cfscript>
    rainbow = queryNew("");
    queryAddColumn(rainbow, "id", "integer", [1,2,3,4,5,6,7]);
    queryAddColumn(rainbow, "maori", "varchar", ["whero","karaka","kowhai","kakariki","kikorangi","tawatawa","mawhero"]);
    queryAddColumn(rainbow, "english", "varchar", ["red","orange","yellow","green","blue","indigo","violet"]);

    writeDump(rainbow);
</cfscript>

<cfquery name="colour" dbtype="query">
    SELECT    *
    FROM    rainbow
    WHERE    id = <cfqueryparam value="#URL.id#" cfsqltype="integer">
</cfquery>
<cfdump var="#colour#">

See how the SQL type in the <cfqueryparam> tag isn't CF_SQL_INTEGER, but is simply the more common-sense / natural integer.

I piped up that I'd heard that ColdFusion 10 now supports this too, but as it turns out I was wrong: it doesn't.

It'd be something good for a small tweak to CF11 though, eh (3616682)?  It's not the end of the world, or the most exciting thing since [the previous most exciting thing], but it makes good sense. I've always wondered why we've been forced to key in all that CF_SQL_ nonsense in CFML. CF might have all these specially-named constants under the hood, but it doesn't need to bleed out into the CFML code.

I tested OpenBD, and it doesn't support this syntactical sugar either.

On a whim I tried sqltype and type as attribute names instead of cfsqltype, but no dice on Railo. Is there any reason it's not just type, guys?

Anyway, good work Railo, for doing sensible stuff like this.

--
Adam