Skip to content
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

MSSQL uniqueidentfier not preserved when read #366

Open
deltadecay opened this issue Apr 24, 2023 · 2 comments
Open

MSSQL uniqueidentfier not preserved when read #366

deltadecay opened this issue Apr 24, 2023 · 2 comments

Comments

@deltadecay
Copy link

deltadecay commented Apr 24, 2023

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")
@ahjulstad
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants