diff --git a/src/api.jl b/src/api.jl index 16b1acd..9a63ccf 100644 --- a/src/api.jl +++ b/src/api.jl @@ -45,7 +45,7 @@ struct MYSQL_FIELD field_type::Cuint ## Type of field. See mysql_com.h for types extension::Ptr{Cvoid} end -nullable(field) = (field.flags & API.NOT_NULL_FLAG) > 0 +notnullable(field) = (field.flags & API.NOT_NULL_FLAG) > 0 isunsigned(field) = (field.flags & API.UNSIGNED_FLAG) > 0 """ diff --git a/src/consts.jl b/src/consts.jl index 93f7328..9857b8e 100644 --- a/src/consts.jl +++ b/src/consts.jl @@ -35,6 +35,7 @@ struct Bit bits::UInt64 end Base.show(io::IO, b::Bit) = print(io, "MySQL.API.Bit(\"$(lstrip(bitstring(b.bits), '0'))\")") +Base.unsigned(::Type{Bit}) = Bit mysql_type(::Type{Bit}) = MYSQL_TYPE_BIT mysql_type(::Type{Cchar}) = MYSQL_TYPE_TINY diff --git a/src/types.jl b/src/types.jl index 00da3b3..97f9000 100644 --- a/src/types.jl +++ b/src/types.jl @@ -55,10 +55,10 @@ mutable struct Query{hasresult, names, T} nrows::Int end -function julia_type(field_type, nullable, isunsigned) +function julia_type(field_type, notnullable, isunsigned) T = API.julia_type(field_type) T2 = isunsigned ? unsigned(T) : T - return nullable ? Union{Missing, T2} : T2 + return notnullable ? T2 : Union{Missing, T2} end function MySQLRowIterator(args...) @@ -78,7 +78,7 @@ function Query(conn::Connection, sql::String; kwargs...) nrows = MySQL.API.mysql_num_rows(result.ptr) fields = MySQL.metadata(result.ptr) names = Tuple(ccall(:jl_symbol_n, Ref{Symbol}, (Ptr{UInt8}, Csize_t), x.name, x.name_length) for x in fields) - T = Tuple{(julia_type(x.field_type, API.nullable(x), API.isunsigned(x)) for x in fields)...} + T = Tuple{(julia_type(x.field_type, API.notnullable(x), API.isunsigned(x)) for x in fields)...} hasresult = true ncols = length(fields) ptr = MySQL.API.mysql_fetch_row(result.ptr)