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 transaction() not actually using a transaction #213

Merged
merged 2 commits into from
Feb 16, 2024

Conversation

Octogonapus
Copy link
Contributor

@Octogonapus Octogonapus commented Feb 7, 2024

transaction() used to just turn off autocommit, which means that rollback doesn't work:

julia> transaction(db) do
           stmt = prepare(db, "insert into foo (a) values (?);")
           execute(stmt, [6])
           error("force rollback")
       end
ERROR: force rollback
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] (::var"#1#2")()
   @ Main ./REPL[6]:4
 [3] transaction(f::var"#1#2", ::MySQL.Connection)
   @ DBInterface ~/.julia/packages/DBInterface/1Gmxx/src/DBInterface.jl:166
 [4] top-level scope
   @ REPL[6]:1

julia> DataFrame(execute(db, "select * from foo"))
6×1 DataFrame
 Row │ a      
     │ Int32? 
─────┼────────
   11
   21
   31
   42
   51
   66

I didn't find any C API for starting a transaction, so I am using the SQL instead. ref. https://dev.mysql.com/doc/c-api/8.0/en/c-api-basic-function-reference.html

@quinnj quinnj merged commit e0b1564 into JuliaDatabases:main Feb 16, 2024
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants