'ODBC.jl Cursor to DataFrame converts "000" to "0000/0/0"

I am using ODBC.jl to pull data and convert to a DataFrame. The driver is SQL Server used to connect to MS SQL Server.

conn = ODBC.Connection("""Driver=$driver;Server=$server;database=$database;UID=$uid;PWD=$pwd""")
results = DBInterface.execute(conn, "select $query from $table") |> DataFrame
DBInterface.close!(conn)

Everything comes out fine except I have an NVARCHAR column that contains strings ranging from "000" to "005" etc. These are nominal data and the character length is helpful for merging with other systems. The .execute returns a dataframe as expected and everything is fine except that the one column gets converted to "0000/0/0" or "0000/0/5", etc. The column type in the returned DataFrame is a String.

I also have zero issues making this same query using R's DBI interface.

I do not have write access nor can I alter the db I pull from, though I could ostensibly make a request to the admin, but would rather avoid it if possible.

Here's the stdout from the raw cursor object. the column in questions is named new_chlocation.

ODBC.Cursor{false, false}(ODBC.API.Handle(3, Ptr{Nothing} @0x00000000797cd360), -1, 1, 
[:new_chlocation], Type[Union{Missing, String}], Dict(:new_chlocation => 1), 0, 1, 
ODBC.Binding[ODBC.Binding(1, -9, ODBC.Buffer(UInt8[0x30, 0x02, 0x01, 0x02, 0x00, 0x00]), 6, 
[224975840], false, 0)], AbstractVector[], Any["column name" "column type" "sql type" "c type" 
"sizes" "nullable" "long data"; :new_chlocation Union{Missing, String} "SQL_WVARCHAR" "SQL_C_CHAR"
6 true false])

Any ideas on what's happening or how to force an un-changed result? I looked through the somewhat sparse ODBC documentation and couldn't find anything to say, designate a type when making the pull, or otherwise override whatever default conversion is gunking up the column.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source