Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Octogonapus committed Feb 7, 2024
1 parent 6956b1a commit e8003e1
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,39 @@ ret = columntable(res)

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

@testset "transactions" begin
DBInterface.execute(conn, "DROP TABLE IF EXISTS TransactionTest")
DBInterface.execute(conn, "CREATE TABLE TransactionTest (a int)")

conn2 = DBInterface.connect(MySQL.Connection, "", ""; option_file=joinpath(dirname(pathof(MySQL)), "../test/", "my.ini"))

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

# we can see the result inside our transaction
result = DBInterface.execute(conn, "SELECT * FROM TransactionTest") |> Tables.columntable
@test result.a == [1]

# and can't see it outside our transaction
result = DBInterface.execute(conn2, "SELECT * FROM TransactionTest") |> Tables.columntable
@test isempty(result.a)
end
result = DBInterface.execute(conn, "SELECT * FROM TransactionTest") |> Tables.columntable
@test result.a == [1]
result = DBInterface.execute(conn2, "SELECT * FROM TransactionTest") |> Tables.columntable
@test result.a == [1]

# roll back due to exception
@test_throws ErrorException DBInterface.transaction(conn) do
DBInterface.execute(conn, "INSERT INTO TransactionTest (a) VALUES (2)")
error("force rollback")
end
result = DBInterface.execute(conn, "SELECT * FROM TransactionTest") |> Tables.columntable
@test result.a == [1] # the table did not change
finally
close(conn2)
end
end

0 comments on commit e8003e1

Please sign in to comment.