Skip to content

Commit

Permalink
Various bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Mar 8, 2018
1 parent f9664a2 commit 3968588
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ 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
isunsigned(field) = (field.flags & API.UNSIGNED_FLAG) == 0
nullable(field) = (field.flags & API.NOT_NULL_FLAG) > 0
isunsigned(field) = (field.flags & API.UNSIGNED_FLAG) > 0

"""
Type mirroring MYSQL_TIME C struct.
Expand Down
5 changes: 4 additions & 1 deletion src/consts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function julia_type(mysqltype)
mysqltype == API.MYSQL_TYPE_LONG_BLOB ||
mysqltype == API.MYSQL_TYPE_BLOB ||
mysqltype == API.MYSQL_TYPE_GEOMETRY
return Vector{UInt8}
return String # Vector{UInt8}
elseif mysqltype == API.MYSQL_TYPE_YEAR
return Clong
elseif mysqltype == API.MYSQL_TYPE_TIMESTAMP
Expand Down Expand Up @@ -157,6 +157,9 @@ const MYSQL_NO_DATA = 100

const MYSQL_DEFAULT_PORT = 3306

const CR_SERVER_GONE_ERROR = 2006
const CR_SERVER_LOST = 2013

if Compat.Sys.iswindows()
const MYSQL_DEFAULT_SOCKET = "MySQL"
else
Expand Down
16 changes: 9 additions & 7 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ DB: $(hndl.db)
end

struct MySQLInternalError <: MySQLError
ptr::Ptr{Cvoid}
MySQLInternalError(con::Connection) = new(con.ptr)
MySQLInternalError(ptr) = new(ptr)
errno::Cuint
msg::String
MySQLInternalError(con::Connection) = new(API.mysql_errno(con.ptr), unsafe_string(API.mysql_error(con.ptr)))
MySQLInternalError(ptr) = new(API.mysql_errno(ptr), unsafe_string(API.mysql_error(ptr)))
end
Base.showerror(io::IO, e::MySQLInternalError) = print(io, unsafe_string(API.mysql_error(e.ptr)))
Base.showerror(io::IO, e::MySQLInternalError) = print(io, "($(e.errno)): $(e.msg)")

mutable struct Result
ptr
Expand All @@ -54,9 +55,10 @@ mutable struct Query{hasresult, names, T}
nrows::Int
end

function julia_type(field_type, nullable)
function julia_type(field_type, nullable, isunsigned)
T = API.julia_type(field_type)
return nullable ? Union{Missing, T} : T
T2 = isunsigned ? unsigned(T) : T
return nullable ? Union{Missing, T2} : T2
end

function MySQLRowIterator(args...)
Expand All @@ -76,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)) for x in fields)...}
T = Tuple{(julia_type(x.field_type, API.nullable(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 3968588

Please sign in to comment.