ODBC.jl icon indicating copy to clipboard operation
ODBC.jl copied to clipboard

MSSQL uniqueidentfier not preserved when read

Open deltadecay opened this issue 1 year ago • 2 comments

There seems to be an issue reading MSSQL identifiers of type uniqueidentifier. See example below. To test you need to set up an ODBC connection to a MSSQL database. I've tested in Julia 1.8.5 and ODBC.jl 1.1.2.

using ODBC
using DataFrames

conn = ODBC.Connection("<your connection name>")

query = "SELECT CONVERT(uniqueidentifier, '99685768-257e-462e-a29f-e6902550f030') AS anid, '99685768-257e-462e-a29f-e6902550f030' AS strid"
cursor = DBInterface.execute(conn, query)
df = DataFrame(cursor)

DBInterface.close!(conn)

Reading the value from the dataframe we get following evaluated to true:

first(df.anid) == Base.UUID("30f05025-90e6-9fa2-462e-257e99685768")

The expected value should be as below evaluated to true:

first(df.anid) == Base.UUID("99685768-257e-462e-a29f-e6902550f030")

deltadecay avatar Apr 24 '23 10:04 deltadecay

I also experience this. The bug does not appear when testing the same ODBC driver from Python; this seems to be an issue in ODBC.jl, or possibly Base.UUID?

(Julia 1.9.3 and ODBC 1.1.2), ODBC Driver 18 for SQL Server.

ahjulstad avatar Oct 11 '23 13:10 ahjulstad

Looks very much like something related to byte order:


res = DBInterface.execute(mssql, 
"SELECT CONVERT(uniqueidentifier, 'ABCD0000-0000-0000-1234-000000000000') AS anid, 'ABCD0000-0000-0000-1234-000000000000' AS strid",
debug=true)

for r in Tables.rows(res)
    print(r)
end

# ODBC.Row:
#  :anid   UUID("00000000-0000-3412-0000-0000abcd0000")
#  :strid  "ABCD0000-0000-0000-1234-000000000000"

If someone wants to have a look, this repo reproduces it easily: https://github.com/ahjulstad/debug-julia-odbc

ahjulstad avatar Oct 11 '23 20:10 ahjulstad