Hello,
I've run into a problem when using uniqueidentifier generated by the SQL Server function newsequentialid() as primary key.
In SQL Management Studio, the UUID looks like this:
825B076B-44EC-E511-80DC-00155D0ABC54
When using App\Mymodel::first()->id and parsing the received bytes using either Ramsey/Uuid or webpatser/laravel-uuid I get this UUID:
6B075B82-EC44-11E5-80DC-00155D0ABC54
The first 8 bytes seem to be interchanged.
My app/database.php looks like this:
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'datetimeformat' => 'Y-m-d H:i:s.u0'
],
Am I missing something?
Edit:
That's my raw result:
>>> App\Mymodel::first()->id
=> b"""
k\x07[‚ìD\x11å€Ü\x00]\n
¼T
"""
Also: When parsing the uuid and converting it back to bytes, I get the same value:
>>> App\Deployment::first()->id->getBytes()
=> b"""
k\x07[‚ìD\x11å€Ü\x00]\n
¼T
"""
Only the string conversion seems to fail.
Sadly I cannot use the byte array like this:
>>> App\Deployment::find(App\Deployment::first()->id->getBytes())
Illuminate\Database\QueryException with message 'SQLSTATE[HY000]: General error: 20018 Incorrect syntax near 'k[�ìDå�Ü'. [20018] (severity 15) [(null)] (SQL: select top 1 * from [deployments] where [deployments].[id] = k[▒▒D▒▒]
▒T)'
>>> App\Deployment::find(App\Deployment::first()->id->toString())
null
Edit 2:
Some more googling led me to this thread: http://dba.stackexchange.com/questions/121869/sql-server-uniqueidentifier-guid-internal-representation
Still I have no clue how properly fix this.