Skip to content

Commit

Permalink
Couple bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Mar 10, 2018
1 parent 3968588 commit eca52e7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down
1 change: 1 addition & 0 deletions src/consts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand All @@ -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)
Expand Down

0 comments on commit eca52e7

Please sign in to comment.