Monday, November 10, 2008

Mysql Nested transaction

The last time I checked, transaction only supported for InnoDB and BerkeleyDB table format. One thing I didn't know before, that those table format doesn't support nested transaction, you can only do flat transaction that is, you cannot start a new transaction without end/commit previous one. In my case I'm using php pdo extension, everytime i start a new transaction with PDO->beginTransaction() the previous transaction automatically commited.

Simply said it's imposible to use nested transaction using pdo (and maybe most of the php database library) for php.

but from the command line you can however, use mysql savepoint and rollback to savepoint to stimulate nested transactions for example

START TRANSACTION
-- parent sql goes here
SAVEPOINT save_id1
-- nested sql goes here
ROLLBACK TO SAVEPOINT save_id1
COMMIT


hope this would be usefull..

No comments: