views:

23

answers:

1

I'd like my program to be able to install plugins, and rollback all the changes made if an error occurs. So I create a transaction that keeps all the things that were added while installing the plugin. The problem is that the plugin may want to create tables, and doing so automatically commits the current transaction in MySQL.

See Statements That Cause an Implicit Commit on MySQL web site.

Any idea on how I could do it?

I thought of using temporary tables as they are not automatically committed, unless they are using too much memory, but it looks like temporary tables cannot be rolled back anyway (and I haven't found a way to convert them to permanent tables).

I just found out about "save points", but I don't really understand how/when it should be used nor if it can help me achieve what I want.

A: 

Savepoints aren't the answer; they are committed when the transaction is committed. A savepoint is an intermediate point in a transaction to which you can roll back.

Some DBMS do provide you with full transaction support on DDL (data definition language) statements, such as CREATE TABLE. One such is IBM Informix Dynamic Server.

Many DBMS do not provide you with such support. One such is Oracle.

Basically, you have to decide whether it is better to use/support MySQL and live without transaction support around DDL statements or whether to migrate to another DBMS that provides the functionality you need. There is, in theory, a third option - add support for transactions around DDL in MySQL. That might be a little difficult, though (but immensely worthwhile for the MySQL community as a whole if you do it right).

Jonathan Leffler
OK thanks for the info. Didn't know even Oracle didn't support it.My application uses an abstract layer that allows to support different DBMS, so I can't really dig into each of them and add support to full transaction on DDL...and even if it were just MySQL, it would probably be way too complex for me!