From 87dc38923b0bea04de874c43d4b3e81bf2be845a Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Mon, 1 Jun 2020 08:14:35 -0600 Subject: [PATCH] Check whether column is numeric along with unsigned check (#163) Attempt to fix #159. It seems there are cases when `API.isunsigned` will return true for a timestamp column; this is probably due to some kind of database or column setting when the table was created, but nonetheless, it causes issues because if `API.isunsigned`, then we try to call `unsigned(T)`, which isn't defined for `DateTime`. As opposed to pirating that definition in MySQL.jl, here we attempt to also check the `NUM_FLAG`, which should tell us whether the field is numeric or not and hopefully avoid ever seeing `API.isunsigned` for timestamp columns. --- src/api/apitypes.jl | 2 +- src/api/consts.jl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/api/apitypes.jl b/src/api/apitypes.jl index 9f0fa75..60413ae 100644 --- a/src/api/apitypes.jl +++ b/src/api/apitypes.jl @@ -89,7 +89,7 @@ struct MYSQL_FIELD extension::Ptr{Cvoid} end notnullable(field) = (field.flags & NOT_NULL_FLAG) > 0 -isunsigned(field) = (field.flags & UNSIGNED_FLAG) > 0 +isunsigned(field) = (field.flags & NUM_FLAG) > 0 && (field.flags & UNSIGNED_FLAG) > 0 isbinary(field) = (field.flags & BINARY_FLAG) > 0 const MYSQL_FIELD_OFFSET = Cuint diff --git a/src/api/consts.jl b/src/api/consts.jl index 24a5a27..8a86845 100644 --- a/src/api/consts.jl +++ b/src/api/consts.jl @@ -206,6 +206,7 @@ const MYSQL_TIMESTAMP_TIME = 2 const NOT_NULL_FLAG = UInt32(1) const UNSIGNED_FLAG = UInt32(32) const BINARY_FLAG = UInt32(128) +const NUM_FLAG = UInt32(32768) const MYSQL_NO_DATA = 100 const MYSQL_DEFAULT_PORT = 3306