Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

[DBAL-81] Add possibility to set the auto-commit mode for a connection #409

Merged
merged 5 commits into from Nov 12, 2013

Conversation

Projects
None yet
3 participants
Member

deeky666 commented Nov 9, 2013

This PR makes auto-commit mode configurable for a connection (as proposed in DBAL-81).
The implementation adds methods to get and set the auto-commit mode on a connection object. When NOT in auto-commit mode, each commit() and rollBack() call automatically start a new transaction after the operation is finished. Aditionally a call to connect() starts a new transaction if not already connected.
When IN auto-commit mode, the behaviour is the same as it is with the current implementation.
When switching auto-commit mode, all current active transactions are committed.

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DBAL-660

We use Jira to track the state of pull requests and the versions they got
included in.

@beberlei beberlei commented on an outdated diff Nov 10, 2013

lib/Doctrine/DBAL/Connection.php
+
+ /**
+ * Sets auto-commit mode for this connection.
+ *
+ * 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.
+ *
+ * NOTE: If this method is called during a transaction and the auto-commit mode is changed, the transaction is
+ * committed. If this method is called and the auto-commit mode is not changed, the call is a no-op.
+ *
+ * @param boolean $autoCommit True to enable auto-commit mode; false to disable it.
+ *
+ * @see getAutoCommit
+ */
+ public function setAutoCommit($autoCommit)
@beberlei

beberlei Nov 10, 2013

Owner

We should offer a way to set autocommit during creation of the connection already, to avoid having to think about the implications of calling this method.

Owner

beberlei commented Nov 10, 2013

great!

Member

deeky666 commented Nov 10, 2013

@beberlei Made auto-commit mode configurable via the configuration container.

@beberlei beberlei and 1 other commented on an outdated diff Nov 10, 2013

lib/Doctrine/DBAL/Connection.php
@@ -1095,6 +1150,28 @@ public function commit()
}
--$this->_transactionNestingLevel;
+
+ if (false === $this->autoCommit && 0 === $this->_transactionNestingLevel) {
+ $this->beginTransaction();
+ }
+ }
+
+ /**
+ * Commits all current nesting transactions.
+ */
+ public function commitAll()
@beberlei

beberlei Nov 10, 2013

Owner

private please.

@beberlei beberlei and 1 other commented on an outdated diff Nov 10, 2013

lib/Doctrine/DBAL/Connection.php
@@ -1141,6 +1222,24 @@ public function rollBack()
}
/**
+ * Cancel any database changes done during all current nesting transactions.
+ */
+ public function rollBackAll()
@deeky666

deeky666 Nov 10, 2013

Member

removed because it is unused when private.

Member

deeky666 commented Nov 11, 2013

@beberlei this is ready now from my point of view. You can have another look on it when you have time to.

@beberlei beberlei added a commit that referenced this pull request Nov 12, 2013

@beberlei beberlei Merge pull request #409 from deeky666/DBAL-81
[DBAL-81] Add possibility to set the auto-commit mode for a connection
95b196f

@beberlei beberlei merged commit 95b196f into doctrine:master Nov 12, 2013

1 check passed

default The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment