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