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

support nested transactions #514

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

gluk-w
Copy link

@gluk-w gluk-w commented Aug 30, 2015

I added support for nested transactions. So it is safe to start transaction and call methods that also use transactions. Implementation idea is taken from http://php.net/manual/en/pdo.begintransaction.php#116669

@thijsw
Copy link
Contributor

thijsw commented Sep 23, 2015

+1

@jpfuentes2
Copy link
Owner

This is a very useful feature and can help speed up integration tests which use the DB/fixtures by using savepoints rather than DELETE or TRUNCATE esp. for Postgres.

Thanks a lot for adding a test, @gluk-w. Would you mind fixing your formatting to match the style of this codebase?

}

/**
* Commits the current transaction.
*/
public function commit()
{
// Nested transaction simply decrease number
if (--static::$transaction_counter) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@koenpunt
Copy link
Collaborator

Thanks @gluk-w! Apart from my notes and @jpfuentes2 note about the formatting I'm ok with this.

throw new DatabaseException($this);
// Transaction started already
if (static::$transaction_counter++) {
$this->connection->exec('SAVEPOINT trans'.static::$transaction_counter);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will never be a trans0 like this, which I think is kinda odd.

@koenpunt
Copy link
Collaborator

And how does this work with the transaction method on the model? Can you add a test for that as well?

@koenpunt
Copy link
Collaborator

Also, do all PDO adapters support savepoints? I believe only postgres and mysql do, so we might take that into account in the implementation.

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.

4 participants