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

Decimal numbers are not fetched correctly because the receiving buffer is too small #380

Open
xitology opened this issue Mar 6, 2024 · 0 comments

Comments

@xitology
Copy link
Contributor

xitology commented Mar 6, 2024

When I use ODBC.jl to execute the query like SELECT CAST(-1.5 AS DECIMAL(2,1)), I get back the value -1.0 instead of the expected -1.5. Depending on the database server, a query as simple as SELECT -1.5 can demonstrate the issue. The problem is that the receiving buffer allocated by ODBC.jl is too small to hold the complete value.

Here's the code to quickly reproduce the issue:

using ODBC
using DataFrames

const dsn = ENV["DSN"]
const sql = "SELECT CAST(-1.5 AS DECIMAL(2,1))"
#const sql = "SELECT -1.5"
const conn = ODBC.Connection(dsn)
const cr = DBInterface.execute(conn, sql)
display(cr.metadata)
display(DataFrame(cr))

The output, for MS SQL Server, is:

2×7 Matrix{Any}:
 "column name"   "column type"          "sql type"     "c type"       "sizes"      "nullable"       "long data"
 Symbol("-1.5")  Union{Missing, Dec64}  "SQL_DECIMAL"  "SQL_C_CHAR"  3         true            false
1×1 DataFrame
 Row │ -1.5  
     │ Dec64 
─────┼───────
   1 │  -1.0

Notably, the column size reported by the ODBC driver is 3-1=2, apparently, the precision of the decimal number and not the size of the receiving buffer. I also ran this code and got the same result against three other drivers: for PostgreSQL, MariaDB, and Databricks.

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

1 participant