Skip to content

support nested transactions#514

Open
gluk-w wants to merge 1 commit into
jpfuentes2:masterfrom
gluk-w:master
Open

support nested transactions#514
gluk-w wants to merge 1 commit into
jpfuentes2:masterfrom
gluk-w:master

Conversation

@gluk-w

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

Copy link
Copy Markdown

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

thijsw commented Sep 23, 2015

Copy link
Copy Markdown
Contributor

+1

@jpfuentes2

Copy link
Copy Markdown
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?

Comment thread lib/Connection.php
public function commit()
{
// Nested transaction simply decrease number
if (--static::$transaction_counter) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@koenpunt

Copy link
Copy Markdown
Collaborator

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

Comment thread lib/Connection.php
throw new DatabaseException($this);
// Transaction started already
if (static::$transaction_counter++) {
$this->connection->exec('SAVEPOINT trans'.static::$transaction_counter);

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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