rollback() public method

Rollback a transaction
public rollback ( ) : boolean
return boolean True on success, false on fail (i.e. if the database/model does not support transactions, or a transaction has not started).
コード例 #1
0
 /**
  * Test nested transaction
  *
  * @return void
  */
 public function testNestedTransaction()
 {
     $nested = $this->Dbo->useNestedTransactions;
     $this->Dbo->useNestedTransactions = true;
     if ($this->Dbo->nestedTransactionSupported() === false) {
         $this->Dbo->useNestedTransactions = $nested;
         $this->skipIf(true, 'The MySQL server do not support nested transaction');
     }
     $this->loadFixtures('Inno');
     $model = ClassRegistry::init('Inno');
     $model->hasOne = $model->hasMany = $model->belongsTo = $model->hasAndBelongsToMany = array();
     $model->cacheQueries = false;
     $this->Dbo->cacheMethods = false;
     $this->assertTrue($this->Dbo->begin());
     $this->assertNotEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->begin());
     $this->assertTrue($model->delete(1));
     $this->assertEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->rollback());
     $this->assertNotEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->begin());
     $this->assertTrue($model->delete(1));
     $this->assertEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->commit());
     $this->assertEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->rollback());
     $this->assertNotEmpty($model->read(null, 1));
     $this->Dbo->useNestedTransactions = $nested;
 }
コード例 #2
0
 /**
  * Run migration
  *
  * @param string $direction, up or down direction of migration process
  * @return boolean Status of the process
  * @throws MigrationException
  */
 public function run($direction)
 {
     if (!in_array($direction, array('up', 'down'))) {
         throw new MigrationException($this, sprintf(__d('migrations', 'Migration direction (%s) is not one of valid directions.'), $direction), E_USER_NOTICE);
     }
     $this->direction = $direction;
     $null = null;
     $this->db = ConnectionManager::getDataSource($this->connection);
     $this->db->cacheSources = false;
     $this->db->begin($null);
     $this->Schema = new CakeSchema(array('connection' => $this->connection));
     try {
         $this->_invokeCallbacks('beforeMigration', $direction);
         $result = $this->_run();
         $this->_clearCache();
         $this->_invokeCallbacks('afterMigration', $direction);
         if (!$result) {
             return false;
         }
     } catch (Exception $e) {
         $this->db->rollback($null);
         throw $e;
     }
     return $this->db->commit($null);
 }
コード例 #3
0
ファイル: SqliteTest.php プロジェクト: saihe/reservation
 /**
  * Test nested transaction
  *
  * @return void
  */
 public function testNestedTransaction()
 {
     $this->skipIf($this->Dbo->nestedTransactionSupported() === false, 'The Sqlite version do not support nested transaction');
     $this->loadFixtures('User');
     $model = new User();
     $model->hasOne = $model->hasMany = $model->belongsTo = $model->hasAndBelongsToMany = array();
     $model->cacheQueries = false;
     $this->Dbo->cacheMethods = false;
     $this->assertTrue($this->Dbo->begin());
     $this->assertNotEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->begin());
     $this->assertTrue($model->delete(1));
     $this->assertEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->rollback());
     $this->assertNotEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->begin());
     $this->assertTrue($model->delete(1));
     $this->assertEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->commit());
     $this->assertEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->rollback());
     $this->assertNotEmpty($model->read(null, 1));
 }
コード例 #4
0
 /**
  * Rollback a transaction
  *
  * @param unknown_type $model
  * @return boolean True on success, false on fail
  * (i.e. if the database/model does not support transactions,
  * or a transaction has not started).
  */
 function rollback(&$model)
 {
     if (parent::rollback($model)) {
         return $this->execute('ROLLBACK TRAN');
     }
     return false;
 }
コード例 #5
0
 /**
  * Rollback a transaction
  *
  * @param unknown_type $model
  * @return boolean True on success, false on fail
  * (i.e. if the database/model does not support transactions,
  * or a transaction has not started).
  */
 function rollback(&$model)
 {
     if (parent::rollback($model)) {
         $this->_transactionStarted = false;
         db2_autocommit($this->connection, DB2_AUTOCOMMIT_ON);
         return db2_rollback($this->connection);
     }
     return false;
 }
コード例 #6
0
ファイル: dbo_adodb.php プロジェクト: jerzzz777/cake-cart
 /**
  * Rollback a transaction
  *
  * @param unknown_type $model
  * @return boolean True on success, false on fail
  * (i.e. if the database/model does not support transactions,
  * or a transaction has not started).
  */
 function rollback(&$model)
 {
     if (parent::rollback($model)) {
         return $this->_adodb->RollbackTrans();
     }
     return false;
 }
コード例 #7
0
ファイル: Adodb.php プロジェクト: cahs/datasources
 /**
  * Rollback a transaction
  *
  * @return boolean True on success, false on fail
  * (i.e. if the database/model does not support transactions,
  * or a transaction has not started).
  */
 public function rollback()
 {
     if (parent::rollback()) {
         return $this->_adodb->RollbackTrans();
     }
     return false;
 }
コード例 #8
0
ファイル: dbo_sqlite3.php プロジェクト: JCVI-Cloud/METAREP
 /**
  * Rollback a transaction
  *
  * @param unknown_type $model
  * @return boolean True on success, false on fail
  * (i.e. if the database/model does not support transactions,
  * or a transaction has not started).
  */
 function rollback(&$model)
 {
     if (parent::rollback($model)) {
         return $this->pdo_statement->rollBack();
     }
     return false;
 }
コード例 #9
0
 /**
  * Rollback a transaction
  *
  * @param unknown_type $model
  * @return boolean True on success, false on fail
  * (i.e. if the database/model does not support transactions,
  * or a transaction has not started).
  */
 function rollback(&$model)
 {
     if (parent::rollback($model)) {
         $this->_transactionStarted = false;
         return odbc_rollback($this->connection);
     }
     return false;
 }
コード例 #10
0
ファイル: dbo_oci.php プロジェクト: hikmanet/HnsAutomobiles
 /**
  * Rollback a transaction
  *
  * @param unknown_type $model
  * @return boolean True on success, false on fail
  * (i.e. if the database/model does not support transactions,
  * or a transaction has not started).
  */
 function rollback(&$model)
 {
     if (parent::rollback($model)) {
         return oci_rollback($this->connection);
     }
     return false;
 }
コード例 #11
0
ファイル: PostgresTest.php プロジェクト: mrbadao/api-official
 /**
  * Test nested transaction
  *
  * @return void
  */
 public function testNestedTransaction()
 {
     $this->Dbo->useNestedTransactions = TRUE;
     $this->skipIf($this->Dbo->nestedTransactionSupported() === FALSE, 'The Postgres server do not support nested transaction');
     $this->loadFixtures('Article');
     $model = new Article();
     $model->hasOne = $model->hasMany = $model->belongsTo = $model->hasAndBelongsToMany = array();
     $model->cacheQueries = FALSE;
     $this->Dbo->cacheMethods = FALSE;
     $this->assertTrue($this->Dbo->begin());
     $this->assertNotEmpty($model->read(NULL, 1));
     $this->assertTrue($this->Dbo->begin());
     $this->assertTrue($model->delete(1));
     $this->assertEmpty($model->read(NULL, 1));
     $this->assertTrue($this->Dbo->rollback());
     $this->assertNotEmpty($model->read(NULL, 1));
     $this->assertTrue($this->Dbo->begin());
     $this->assertTrue($model->delete(1));
     $this->assertEmpty($model->read(NULL, 1));
     $this->assertTrue($this->Dbo->commit());
     $this->assertEmpty($model->read(NULL, 1));
     $this->assertTrue($this->Dbo->rollback());
     $this->assertNotEmpty($model->read(NULL, 1));
 }