Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/load.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ end
function DBInterface.transaction(f::Function, conn::Connection)
DBInterface.execute(conn, "START TRANSACTION")
try
f()
result = f()
API.commit(conn.mysql)
return result
catch
API.rollback(conn.mysql)
rethrow()
Expand Down
2 changes: 2 additions & 0 deletions src/prepare.jl
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ function bind!(helper, binds, i, x::Missing)
return
end

bind!(helper, binds, i, ::Nothing) = bind!(helper, binds, i, missing)

function bind!(helper, binds, i, x::Real)
if !helper.typeset
inithelper!(helper, x)
Expand Down
13 changes: 12 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,15 @@ end
DBInterface.execute(stmt, [missing, missing, missing, missing, missing, missing, missing, missing, missing, DateTime("2015-09-05T12:31:30"), missing, missing, missing, missing, missing])
DBInterface.close!(stmt)

DBInterface.execute(conn, "CREATE TABLE NullBindingTest (value INT NULL)")
stmt = DBInterface.prepare(conn, "INSERT INTO NullBindingTest (value) VALUES (?)")
DBInterface.execute(stmt, (nothing,))
DBInterface.execute(stmt, (1,))
DBInterface.execute(stmt, (missing,))
DBInterface.close!(stmt)
res = DBInterface.execute(conn, "SELECT value FROM NullBindingTest") |> columntable
@test isequal(res.value, [missing, 1, missing])

stmt = DBInterface.prepare(conn, "select * from Employee")
res = DBInterface.execute(stmt) |> columntable
DBInterface.close!(stmt)
Expand Down Expand Up @@ -511,7 +520,7 @@ ret = columntable(res)

try
# happy path
DBInterface.transaction(conn) do
result = DBInterface.transaction(conn) do
DBInterface.execute(conn, "INSERT INTO TransactionTest (a) VALUES (1)")

# we can see the result inside our transaction
Expand All @@ -521,7 +530,9 @@ ret = columntable(res)
# and can't see it outside our transaction
result = DBInterface.execute(conn2, "SELECT * FROM TransactionTest") |> Tables.columntable
@test isempty(result.a)
return 42
end
@test result == 42
result = DBInterface.execute(conn, "SELECT * FROM TransactionTest") |> Tables.columntable
@test result.a == [1]
result = DBInterface.execute(conn2, "SELECT * FROM TransactionTest") |> Tables.columntable
Expand Down
Loading