Bug #35041 'Binary(16) as GUID' - columns lose IsGuid value after a NULL value found
Submitted: 4 Mar 2008 16:53 Modified: 16 May 2008 13:19
Reporter: Tim Faust Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:5.2.1 OS:Microsoft Windows (Vista)
Assigned to: CPU Architecture:Any

[4 Mar 2008 16:53] Tim Faust
Description:
Using .NET connector 5.2.1
Visual Studio 2005
MySQL 6.0.3 alpha
Windows Vista Ultimate

Columns that are determined to be Guids (Binary, 16 bytes in length) will lose that setting once a NULl value is retrieved from a row. Subsequent rows that do have a non-NULL value will receive an error:

Type of value has a mismatch with column type Couldn't store <System.Byte[]> in A
GUID Column.  Expected type is Guid.

How to repeat:
A sample program, table and data are attached. You'll need to provide the app with  your DB, pswd, etc.

1.) Create a test DB.
2.) Create the sample table (guidtesttbl.sql)
3.) Create this function, used for inserts - (FNC_CONVERT_CHAR_TO_UUID.sql)
4.) Insert the data - (guidtestinserts.sql)
5.) Build and run the GuidTest C# app (GuidTest.zip), you should see the error.

Suggested fix:
Attached is a copy of MySQlBinary.cs.

look for //PATCH and //ENDPATCH comments in method IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
[4 Mar 2008 16:54] Tim Faust
C# app that  exhibits the problem

Attachment: GUIDTest.zip (application/x-zip-compressed, text), 7.96 KiB.

[4 Mar 2008 16:54] Tim Faust
sample table

Attachment: guidtesttbl.sql (application/octet-stream, text), 207 bytes.

[4 Mar 2008 16:55] Tim Faust
inserts test rows into the table to recreate problem

Attachment: guidtestinserts.sql (application/octet-stream, text), 207 bytes.

[4 Mar 2008 16:55] Tim Faust
helper function to convert GUIDs into Binary(16)

Attachment: FNC_CONVERT_CHAR_TO_UUID.sql (application/octet-stream, text), 338 bytes.

[4 Mar 2008 16:56] Tim Faust
patched code to fix problem

Attachment: MySqlBinary.cs (text/plain), 6.26 KiB.

[4 Mar 2008 17:25] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/43409
[4 Mar 2008 17:25] Reggie Burnett
Fixed in 5.2.2
[16 May 2008 13:19] MC Brown
A note has been added to the 5.2.2 changelog: 

When retreiving data where a field has been identified as containing a GUID value, the incorrect value would be returned when a previous row contained a NULL value for that field.