MySQL.jl
MySQL.jl copied to clipboard
MariaDB version 11 is incompatible with MySQL - String columns are detected as Dec64
column types are not correctly inferred when updating mariadb to version 11. It's probably worthwhile switching to the latest mariadb c connector with MariaDB Server 10:
julia> DataFrame(DBInterface.execute(conn, "select * from `benutzer`"))
2×1 DataFrame
Row │ uname
│ String?
─────┼─────────
1 │ test
2 │ rest
with MariaDB Server 11:
julia> DBInterface.execute(conn, "select * from `benutzer`") |> DataFrame
ERROR: ArgumentError: invalid number format test
Stacktrace:
[1] parse(#unused#::Type{DecFP.Dec64}, s::String)
@ DecFP C:\Users\helmu\.julia\packages\DecFP\Cud5F\src\DecFP.jl:323
If I store strings that can be parsed as numbers in the field 'uname' the columns are indeed read as Dec64.
julia> DataFrame(hh)
3×1 DataFrame
Row │ uname
│ Dec64
─────┼───────
1 │ 10.0
2 │ 11.0
3 │ 14.0
This behaviour is consistent with the (wrong) column type stored in the query result:
julia> res = DBInterface.execute(conn, "select * from `benutzer`");
julia> res.types
1-element Vector{Type}:
Union{Missing, DecFP.Dec64}
Hello,
Same here, must fall back on branch 10 of MariaDb.
The C Lib used seems quite old, released in December. 2019.
In fact, after some debugging, the library returns a zero in field_type, causing it to be misinterpreted as Dec64
/src/MySQL.jl
# --> Here, the real type is VARCHAR
function juliatype(field_type, notnullable, isunsigned, isbinary, date_and_time)
@info field_type # --> 0
T = API.juliatype(field_type)
@info T # --> Dec64
T2 = isunsigned && !(T <: AbstractFloat) ? unsigned(T) : T
T3 = !isbinary && T2 == Vector{UInt8} ? String : T2
T4 = date_and_time && T3 <: DateTime ? DateAndTime : T3
return notnullable ? T4 : Union{Missing, T4}
end
Regards, Pascal.