Skip to content

Commit 3968588

Browse files
committed
Various bugfixes
1 parent f9664a2 commit 3968588

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/api.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ struct MYSQL_FIELD
4545
field_type::Cuint ## Type of field. See mysql_com.h for types
4646
extension::Ptr{Cvoid}
4747
end
48-
nullable(field) = (field.flags & API.NOT_NULL_FLAG) == 0
49-
isunsigned(field) = (field.flags & API.UNSIGNED_FLAG) == 0
48+
nullable(field) = (field.flags & API.NOT_NULL_FLAG) > 0
49+
isunsigned(field) = (field.flags & API.UNSIGNED_FLAG) > 0
5050

5151
"""
5252
Type mirroring MYSQL_TIME C struct.

src/consts.jl

+4-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function julia_type(mysqltype)
7878
mysqltype == API.MYSQL_TYPE_LONG_BLOB ||
7979
mysqltype == API.MYSQL_TYPE_BLOB ||
8080
mysqltype == API.MYSQL_TYPE_GEOMETRY
81-
return Vector{UInt8}
81+
return String # Vector{UInt8}
8282
elseif mysqltype == API.MYSQL_TYPE_YEAR
8383
return Clong
8484
elseif mysqltype == API.MYSQL_TYPE_TIMESTAMP
@@ -157,6 +157,9 @@ const MYSQL_NO_DATA = 100
157157

158158
const MYSQL_DEFAULT_PORT = 3306
159159

160+
const CR_SERVER_GONE_ERROR = 2006
161+
const CR_SERVER_LOST = 2013
162+
160163
if Compat.Sys.iswindows()
161164
const MYSQL_DEFAULT_SOCKET = "MySQL"
162165
else

src/types.jl

+9-7
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ DB: $(hndl.db)
2424
end
2525

2626
struct MySQLInternalError <: MySQLError
27-
ptr::Ptr{Cvoid}
28-
MySQLInternalError(con::Connection) = new(con.ptr)
29-
MySQLInternalError(ptr) = new(ptr)
27+
errno::Cuint
28+
msg::String
29+
MySQLInternalError(con::Connection) = new(API.mysql_errno(con.ptr), unsafe_string(API.mysql_error(con.ptr)))
30+
MySQLInternalError(ptr) = new(API.mysql_errno(ptr), unsafe_string(API.mysql_error(ptr)))
3031
end
31-
Base.showerror(io::IO, e::MySQLInternalError) = print(io, unsafe_string(API.mysql_error(e.ptr)))
32+
Base.showerror(io::IO, e::MySQLInternalError) = print(io, "($(e.errno)): $(e.msg)")
3233

3334
mutable struct Result
3435
ptr
@@ -54,9 +55,10 @@ mutable struct Query{hasresult, names, T}
5455
nrows::Int
5556
end
5657

57-
function julia_type(field_type, nullable)
58+
function julia_type(field_type, nullable, isunsigned)
5859
T = API.julia_type(field_type)
59-
return nullable ? Union{Missing, T} : T
60+
T2 = isunsigned ? unsigned(T) : T
61+
return nullable ? Union{Missing, T2} : T2
6062
end
6163

6264
function MySQLRowIterator(args...)
@@ -76,7 +78,7 @@ function Query(conn::Connection, sql::String; kwargs...)
7678
nrows = MySQL.API.mysql_num_rows(result.ptr)
7779
fields = MySQL.metadata(result.ptr)
7880
names = Tuple(ccall(:jl_symbol_n, Ref{Symbol}, (Ptr{UInt8}, Csize_t), x.name, x.name_length) for x in fields)
79-
T = Tuple{(julia_type(x.field_type, API.nullable(x)) for x in fields)...}
81+
T = Tuple{(julia_type(x.field_type, API.nullable(x), API.isunsigned(x)) for x in fields)...}
8082
hasresult = true
8183
ncols = length(fields)
8284
ptr = MySQL.API.mysql_fetch_row(result.ptr)

0 commit comments

Comments
 (0)