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

JdbcDriver - current transaction statements won't work for every dialect #1693

Closed
nikolajakshic opened this issue May 30, 2020 · 3 comments · Fixed by #1706
Closed

JdbcDriver - current transaction statements won't work for every dialect #1693

nikolajakshic opened this issue May 30, 2020 · 3 comments · Fixed by #1706

Comments

@nikolajakshic
Copy link
Contributor

If you run BEGIN TRANSACTION in MySQL, it'll crash.

getConnection().prepareStatement("BEGIN TRANSACTION").execute()

if (successful) {
getConnection().prepareStatement("END TRANSACTION").execute()
} else {
getConnection().prepareStatement("ROLLBACK TRANSACTION").execute()
}

Maybe it should be made dialect independent, by toggling Connection.setAutoCommit(boolean) and calling Connection.commit() / Connection.rollback() ?

@AlecKazakova
Copy link
Collaborator

Yup makes sense. What does setAutoCommit do?

@nikolajakshic
Copy link
Contributor Author

From the docs:

If a connection is in auto-commit mode, then all its SQL statements will be executed and committed as individual transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either the method commit or the method rollback. By default, new connections are in auto-commit mode.

@AlecKazakova
Copy link
Collaborator

Got it, so turning off autoCommit effectively starts a new transaction

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 a pull request may close this issue.

2 participants