Bug: Binary Fields

2 views
Skip to first unread message

Don

unread,
Nov 6, 2009, 4:19:25 PM11/6/09
to ColdFusion on Wheels
I'm using a VARBINARY field in SQL Server to store encrypted values
for a merchant table and am having some problems when saving my
models. The binary fields are correctly read into ColdFusion binary
objects from the database, but when some of the underlying model
methods are called in crud.cfm (i.e. hasChanged(), $update, etc...)
there is a Compare() call being made to compare the current model
property values with the ones stored in $persistedProperties. This
causes a bad ColdFusion crash "ByteArray objects cannot be converted
to strings." Note: this happens even when trying to save an
unmodified/"not dirty" model and has to do with Compare assuming that
the arguments are simple string values, not values assigned by the
user.

... || Compare(this[loc.key], variables.$persistedProperties[loc.key])
&& ...

The above code (lines 567 & 1157 in crud.cfm in 0.9.4) is the problem
in all the places I have seen this error when saving (or even checking
for changes) on binary fields. I suggest writing a new method into the
model section of Wheels similar to this:

<cffunction name="$compareProperty" returntype="boolean">
<cfargument name="valueOne" type="any" required="true" />
<cfargument name="valueTwo" type="any" required="true" />
<cfscript>
var loc = {};

if (IsBinary(arguments.valueOne)) {
arguments.valueOne = BinaryEncode(arguments.valueOne, "Base64");
arguments.valueTwo = BinaryEncode(arguments.valueTwo, "Base64");
}

return Compare(arguments.valueOne, arguments.valueTwo);
</cfscript>
</cfargument>

And then calling like before to check for changes

... || $compareProperty(this[loc.key], variables.$persistedProperties
[loc.key]) && ...

This would be sufficient to allow for lots of special treatment with
other data types instead of just assuming every column is going to be
a simple type. A similar issue was found a while back but I don't know
if it was fully addressed:

http://groups.google.com/group/cfwheels/browse_thread/thread/d9977cad161ba6c6/398f83a185ecf6df?lnk=gst&q=binary#398f83a185ecf6df

Let me know how this fix comes along or if you need any more
information.

Don

Per Djurner

unread,
Nov 8, 2009, 4:53:38 PM11/8/09
to cfwh...@googlegroups.com
Thanks, Don.
That sounds like a good solution.
I will log an issue for it on the Google Code site.

Don

unread,
Nov 8, 2009, 5:22:00 PM11/8/09
to ColdFusion on Wheels
Would you prefer I enter tiny things like this in "Issues: on the
GoogleCode site in the future?

On Nov 8, 4:53 pm, Per Djurner <per.djur...@gmail.com> wrote:
> Thanks, Don.
> That sounds like a good solution.
> I will log an issue for it on the Google Code site.
>
> >http://groups.google.com/group/cfwheels/browse_thread/thread/d9977cad...

Per Djurner

unread,
Nov 8, 2009, 5:51:19 PM11/8/09
to cfwh...@googlegroups.com
It depends I guess, if it's something that requires some discussion
first it makes sense to post to the Google group.
Either way is fine with me, the important thing is that it gets logged
as an issue at some point so we don't just forget about it.
Reply all
Reply to author
Forward
0 new messages