Migrating from ColdFusion to Railo Part 3

24 November 2014

Continuing my series of notes on the nitty gritty of migrating from ColdFusion 9 to Railo 4.2.

← Migrating from ColdFusion to Railo Part 2: Spreadsheets

Query columns as arrays

Issue

In ColdFusion 9 there's a quirk whereby you can use array functions on individual query columns by passing them in using array notation:


data	= [ 2,3 ];
q = QueryNew( "" );
QueryAddColumn( q,"myColumn","integer",data );
WriteDump( ArraySum( q[ "myColumn" ] ) );

This will correctly dump 5. I say it's a "quirk" because, if you simply dump the column without using an array function, you'll just get the first element in the array, rather than the array itself:


WriteDump( q[ "myColumn" ] );

This just gives you the number 2, rather than the full array of column values.

In Railo if you try to pass the column to an array function you will get an error:

Can't cast Object type [Number] to a value of type [Array]

Fix

Use Railo's QueryColumnData() function to convert the column to an array:


WriteDump( ArraySum( QueryColumnData( q,"myColumn" ) ) );

IIS: file upload size limited by default

Issue

Attempting to use <cffile action="upload"> to upload a file over 4MB in size results in an IIS error:

500 Maximum request length exceeded.

According to the BonCode Connector docs a default maximum of 4MB is imposed by IIS which has nothing to do with Railo or BonCode. However, there is no such limit when using CF 9 via the same IIS installation, so clearly there is something different about the way BonCode works which is causing it to be invoked.

Fix

Anyway, having a per-app limit seems like a good thing and it can be controlled by specifying a value in kilobytes in the web.config:


<system.web>
  <httpRuntime maxRequestLength="5120" /><!-- KB -->
</system.web>

ORM: same-named MappedSuperClass entities cause stack overflow

Issue

If an ORM entity extends a mappedSuperClass entity with the same name (quite possible if it's located in a different directory), Railo will throw a java.lang.StackOverflowError on OrmReload()

MappedSuperClass/Entity.cfc


component accessors="true" mappedSuperClass="true"{}

Entity.cfc


component extends="mappedSuperClass.Entity" accessors="true" persistent="true"{
  property name="ID" fieldType="id";
}

Fix

Make sure child entities which extend a mappedSuperClass have a different name to the super class.

Bug Tracker

Couldn't find this one logged (sometimes feels like I'm the only Railo developer using mappedSuperClass entities!), so created issue 3262

Update Raised against Lucee as Issue #91

REMatch() dot metacharacter doesn't match line breaks by default

Issue

Most people know that a dot in a regular expression will match any character. In fact this isn't strictly true. Early RegEx tools only had to operate on single lines of text and so matching line breaks wasn't part of the dot's implementation. As multi-line matching become possible, the capability was added but often only through the use of a special "DOTALL" flag (?s), with the default left as "don't match new lines".

This was not the case with CFML's regex dot which defaults to matching new line characters. Except for REMatch() in Railo it seems, which I discovered will not match new lines by default.


<cfsavecontent variable="string">
a
b
</cfsavecontent>
<cfscript>
match    =    REMatch( "a.*b",string );
WriteDump( match );// => Empty array in Railo
</cfscript>

However, REFind() in Railo will match the new line:


found    =    REFind( "a.*b",string );
WriteDump( found ); // => 1

Fix

The dotall flag can be set, but my preference is to borrow a trick from Javascript and substitute [\s\S] for the dot. This says: "match a space character or a non-space character", i.e. any character.

Bug Tracker

This is clearly inconsistent behaviour, so have created issue 3260.

Update Raised against Lucee as Issue #90

Migrating from ColdFusion to Railo part 4: null and function arguments →

Posted on . Updated

Comments

  • Formatting comments: See this list of formatting tags you can use in your comments.
  • Want to paste code? Enclose within <pre><code> tags for syntax higlighting and better formatting and if possible use script. If your code includes "self-closing" tags, such as <cfargument>, you must add an explicit closing tag, otherwise it is likely to be mangled by the Disqus parser.
Back to the top