MySQL Create tables without committing current transaction
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开发者_JAVA百科 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.
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).
精彩评论