I generate UUIDs by using UUID_TO_BIN(UUID(), true)
and storing them as BINARY(16)
.
However, when fetching the values:
var uuid = dataReader.GetGuid(name);
Console.WriteLine(uuid.ToString());
I do get an uuid string printed, but it is not the same string as when running SELECT BIN_TO_UUID("col")
on the column.
What am I doing wrong?
OldGuids
in connection string to true
but still got the same incorrect uuid back.UUID_TO_BIN(UUID(), true)
and storing them as BINARY(16)
is that, according to my readings, I thought this was the most efficient way to store uuids and using them as primary keys.Thanks
Operation | Returns |
---|---|
GetGuid(col) |
3da4ec11-3568-cfb4-92aa-b42e99eb957f |
BIN_TO_UUID(col) |
11eca43d-6835-b4cf-92aa-b42e99eb957f |
BIN_TO_UUID(col, true) |
6835b4cf-a43d-11ec-92aa-b42e99eb957f |
If you're creating and storing them with UUID_TO_BIN(UUID(), true)
, then you will need to read them back with BIN_TO_UUID(columnName, true)
.
MySqlDataReader.GetGuid
in MySQL Connector/NET (i.e., MySql.Data) has no ability to do this. Some options are:
BIN_TO_UUID(columnName, true)
everywhere, remove Old Guids=true
from your connection string, and use GetGuid
to read the string that is returned.true
flag when using UUID_TO_BIN
to store the GUID (and just use UUID_TO_BIN(UUID())
); this will put the bytes in the order that GetGuid
expects.GuidFormat = TimeSwapBinary16
in your connection string.