[TYPO3-dev] Idea: add transaction support to t3lib_db

"Christian Müller (Kitsunet)" christian.mueller at typo3.org
Fri Mar 4 15:34:48 CET 2011


Hi,

I think that would be a great idea. I had the need of transactions 
before and finally did everything myself, but that is somewhat 
unsatisfactory.

I think if someone wants to use transactions they should now this needs 
to be supported by DB so that I don't see as a big problem, but of 
course support from DBAL should be there.

Christian

On 04.03.2011 14:25, Dmitry Dulepov wrote:
> Hi!
>
> I propose to add several new functions to t3lib_db:
>
> public function startTransaction();
> public function commit();
> public function rollback();
> public function hasFailedTransactions();
>
> Why it is necessary? Quite often you need to make changes to various
> tables. If a single change fails, that may leave the system in the
> corrupted state. Transactions solve that. Currently you can just use a
> simple way:
>
> $GLOBALS['TYPO3_DB']->sql_query('START TRANSACTION');
>
> However if your code is complex, transactions may be started multiple
> times by the code on various levels. Imagine something like that:
>
> updateUser -> start transaction
> updateGroups -> start trasaction / commit
> updateMediaAssets -> start trasaction / commit
> ...
> TCEmainHook::processDatamap() -> start trasaction / commit
> ...
> -> commit
>
> Here we have a major issue: transactions cannot be nested (it is a
> error). Thus we need a way to track that transaction is already started
> and not to issue another START TRANSACTION call. Also we need to watch
> amount of COMMIT statements and COMMIT only when it matches the number
> of START TRANSACTION calls. On the other hand, ROLLBACK should be
> possible from any point. So the first three new functions will handle
> that. The last function would tell if the transaction is rolled back by
> any inner levels or a error happened during execution.
>
> I could simply make and RFC but I want this to be discussed first. Also
> I would like to know Xavier's opinion because that affects DBAL. DBAL
> has its own methods like this, which I would copy from the MySQL driver.
> But still I would like to know what people think.
>
> P.S. I know that transactions do not work in MyISAM :)
>





More information about the TYPO3-dev mailing list