Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue loading Int8/UInt8 values into mysql table #199

Merged
merged 1 commit into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/MySQL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ function DBInterface.close!(conn::Connection)
end

Base.close(conn::Connection) = DBInterface.close!(conn)
Base.isopen(conn::Connection) = API.isopen(conn.mysql)
Base.isopen(conn::Connection) = conn.mysql.ptr != C_NULL && API.isopen(conn.mysql)

function juliatype(field_type, notnullable, isunsigned, isbinary, date_and_time)
T = API.juliatype(field_type)
Expand Down
1 change: 1 addition & 0 deletions src/load.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function load end
load(conn::Connection, table::AbstractString="mysql_"*Random.randstring(5); kw...) = x->load(x, conn, table; kw...)

function load(itr, conn::Connection, name::AbstractString="mysql_"*Random.randstring(5); append::Bool=true, quoteidentifiers::Bool=true, debug::Bool=false, limit::Integer=typemax(Int64), kw...)
isopen(conn) || throw(ArgumentError("`MySQL.Connection` is closed"))
# get data
rows = Tables.rows(itr)
sch = Tables.schema(rows)
Expand Down
2 changes: 1 addition & 1 deletion src/prepare.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ end

inithelper!(helper, x::Union{Bool, UInt8, Int8}) = helper.uint8 = UInt8[Core.bitcast(UInt8, x)]
ptrhelper(helper, x::Union{Bool, UInt8, Int8}) = pointer(helper.uint8)
sethelper!(helper, x::Union{Bool, UInt8, Int8}) = helper.uint8[1] = Core.bitcast(Bool, x)
sethelper!(helper, x::Union{Bool, UInt8, Int8}) = helper.uint8[1] = Core.bitcast(UInt8, x)
getvalue(stmt, helper, values, i, ::Type{T}) where {T <: Union{Bool, UInt8, Int8}} = Core.bitcast(T, helper.uint8[1])

inithelper!(helper, x::Union{UInt16, Int16}) = helper.uint16 = UInt16[Core.bitcast(UInt16, x)]
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,15 @@ DBInterface.execute(stmt, [SubString("foo")])
# escaping AbstractString
@test MySQL.escape(conn, SubString("'); DROP TABLE Employee; --")) == "\\'); DROP TABLE Employee; --"

# https://github.com/JuliaDatabases/MySQL.jl/issues/194
ct = (x = UInt8[1, 2, 3],)
MySQL.load(ct, conn, "test194")
ct2 = columntable(DBInterface.execute(conn, "select * from test194"))

# 156
res = DBInterface.execute(conn, "select * from Employee")
DBInterface.close!(conn)
ret = columntable(res)

# load on closed connection should throw
@test_throws ArgumentError MySQL.load(ct, conn, "test194")