-
Notifications
You must be signed in to change notification settings - Fork 442
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
base: master
Are you sure you want to change the base?
Conversation
+1 |
This is a very useful feature and can help speed up integration tests which use the DB/fixtures by using savepoints rather than 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should release the savepoint, and I think that should be done here.
http://dev.mysql.com/doc/refman/5.7/en/savepoint.html
http://www.postgresql.org/docs/9.1/static/sql-release-savepoint.html
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); |
There was a problem hiding this comment.
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.
And how does this work with the |
Also, do all PDO adapters support savepoints? I believe only postgres and mysql do, so we might take that into account in the implementation. |
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