-
Notifications
You must be signed in to change notification settings - Fork 509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Help needed with uniqueidentifier #56
Comments
First four parts of guid are integers 32 16 16 16 bit respectively, looks like Parse function incorrectly interprets data big-endian/little-endian (http://en.wikipedia.org/wiki/Endianness) mixup. You can swap order of bytes to get correct byte order for your function or maybe Parse function can take parameters specifying endianness of the input. |
Thanks - I was playing around with this and had come up with: and that resolved it. My setup is running a GO program on a Mac and retrieving (obviously) from a Windows Machine. If the program was to be cross-compiled onto PC, Mac, Linux (I don't have a PC to test on) - would I need to test for the OS and if PC not do the byte swapping? |
Thanks @scohen28 this was really helpful. |
When grabbing the GUID from the MS SQL database, the first half of the GUID becomes scrambled, due to the parser mixing up the Little Endian and Big Endian data types, and this is due to the way Microsoft handles GUIDs. The proposed pull request correctly swaps the byte order by implementing the fix proposed in denisenkom#56
@kardianos one problem with requiring an app to scan to *mssql.UniqueIdentifier instead of *interface{} is the scanner doesn't currently support a null uniqueidentifier. |
I'm retrieving the ID from a sql server database as follows:
import ("github.com/nu7hatch/gouuid")
var theID []byte
err := db.QueryRow("select id from table where item='xxx').Scan(&theID)
fmt.Println(theID)
idStr, _ := uuid.Parse(theID)
fmt.Println(idStr)
Prints:
[249 214 3 106 70 136 42 75 185 33 204 184 168 141 203 14]
f9d6036a-4688-2a4b-b921-ccb8a88dcb0e
When I directly query the table using Sql Management Studio, for the same query I get:
6A03D6F9-8846-4B2A-B921-CCB8A88DCB0E
I also tried the following, but it returns the same 'f9d...' value
b := theID
b[6] = (b[6] & 0x0F) | 0x40
b[8] = (b[8] &^ 0x40) | 0x80
theIDStr := fmt.Sprintf("%x-%x-%x-%x-%x", b[:4], b[4:6], b[6:8], b[8:10]
What is the correct parsing function to use on the returned []byte to resolve to the same value that Sql Server is presenting?
The text was updated successfully, but these errors were encountered: