Reputation: 1418
I am developing an app for owncloud and am using the Owncloud API, not the App Framework.
In this environment I can start SQL-Transactions via \OCP\DB::beginTransaction();
and I can commit the transaction cia \OCP\DB::commit();
.
But I can't find a way to rollback a transaction. I googled it all day and searched through the Owncloud core files but couldn't find a way to do it.
Does anyone know how to do this? Right now I can just leave the transaction uncommited in my ajax requests, because they have only one transaction. But in other scripts I have to do multiple transactions one after another which are independent from another. I have to manually delete all my inserted rows in case anything goes wrong, which is not very nice.
Edit 2014/07/30:
I have found out that the OC_DB_StatementWrapper
-Class, which is return by \OCP\DB::prepare
of Owncloud does not provide a method to do this. However, it passes all unknown calls to the underlying \Doctrine\DBAL\Driver\Statement
-object. This class is described here: Doctrine.DBAL.Statement
It has a private $_conn
(instance of \Doctrine\DBAL\Connection) which has a method rollback
to rollback a transaction. However, $_conn
is private, so I can not access it.
Upvotes: 2
Views: 208
Reputation: 1418
I have finally found a solution myself. To those interested in how it works, here is the solution:
$conn = \OC::$server->getDatabaseConnection();
$conn->rollBack();
This will rollback the previously via \OCP\DB::beginTransaction()
opened transaction. To start a new transaction, just call \OCP\DB::beginTransaction()
again - works like a charm.
Upvotes: 1