Reactor and MS SQL uniqueidentifiers

I ran into an issue last week while trying to use MGU scaffolding with a table which had a uniqueidentifer primary key. If a uniqueidentifer field has a default value of "(newid())" then it seemed to me that the reactor generated project TO should set a default value for that field, however this was not happening. I did some digging and found that due to a bug in the MS SQL ObjectDao.cfc the field's default value is not properly set. The problem is that the ObjectDao's getDefault method has a case statement based on the cfDataType of the field, however the case near line 128 is for the dbDataType "uniqueidentifier." I updated that case statement to the following and it seemed to resolve the issue.

<cfcase value="guid">
<cfif ReFindNoCase("'*newId()'*", arguments.sqlDefaultValue)>
<cfreturn "##Insert(""-"",CreateUUID(),23)##" />
<cfreturn "" />

This code will create valid MS GUIDs for the TO default value. Given this and the fact that the validator will check that TO uniqueidentifier fields match the MS GUID format, I also simplified the dao.project.xsl by removing the statements for uniqueidentifer dbdatatypes. (The uniqueidentifer values should be valid MS GUIDs so there is no need to do conversion in the DAO.)

I submitted this as Reactor Ticket #122 if you care to track this issue or download the actual patches.

BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.