Duncan's blog

February 4, 2014

CFStoredproc / Duplicate() bug

Filed under: Coldfusion — duncan @ 1:03 pm
Tags: , , ,

Came across this weird one while doing some unit testing using Testbox.  After much head scratching I realised it was a bug in Adobe ColdFusion rather than our testing framework.

Suppose you have a stored procedure which returns more than one recordset:

        <cfstoredproc procedure="foobar" datasource="DSN">
            <cfprocresult name="rstFoo" resultset="1">
            <cfprocresult name="rstBar" resultset="2">

Then you do something where you need to duplicate the first recordset:

        <cfset foo = duplicate(rstFoo)>

That was throwing an error like:

java.lang.ArrayIndexOutOfBoundsException: 1 at coldfusion.sql.imq.Row.getColumn(Row.java:237) at coldfusion.sql.QueryTable.populate(QueryTable.java:230) at coldfusion.sql.QueryTable.<init>(QueryTable.java:77) at coldfusion.sql.QueryTable.<init>(QueryTable.java:72) at coldfusion.runtime.ObjectDuplicator._duplicate(ObjectDuplicator.java:95) at coldfusion.runtime.ObjectDuplicator.duplicate(ObjectDuplicator.java:63) at coldfusion.runtime.CFPage.Duplicate(CFPage.java:5059)

Strangely, this only happens with the first recordset.  This is fine where I do the same with just the second recordset:

        <cfset foo = duplicate(rstBar)>

And if I just remove the second (and subsequent) cfprocresults (without making any adjustment to the stored procedure itself), this also works:

        <cfstoredproc procedure="foobar" datasource="DSN">
            <cfprocresult name="rstFoo" resultset="1">
        <cfset foo = duplicate(rstFoo)>

I came across a couple of bugs in Adobe’s bugbase that basically have the same problem, although both tickets have been closed:

The second of which included this workaround:

        <cfset foo = duplicate(deserializeJSON(serializeJSON(rstFoo), false))>

Which fixed it for me, but ideally Adobe would reopen this bug.   Update: the first of those bugs has now been reopened.

PS: this was running CF 9.01, version 9,0,1,274733


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: