当前位置: 首页>>代码示例>>PHP>>正文


PHP Connection::rollBack方法代码示例

本文整理汇总了PHP中Doctrine\DBAL\Connection::rollBack方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::rollBack方法的具体用法?PHP Connection::rollBack怎么用?PHP Connection::rollBack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\DBAL\Connection的用法示例。


在下文中一共展示了Connection::rollBack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: exportData

 public function exportData($export, $reporter)
 {
     $this->conn->beginTransaction();
     try {
         $lastExportedAt = (int) $export['lastExportedAt'];
         $areas = $this->conn->fetchAll('SELECT a.`id`, a.`name`, t.`id` AS `territoryId`, t.`name` AS `territoryName`, a.`customData`, a.`lastUpdatedAt` ' . 'FROM `' . CoreTables::AREA_TBL . '` a ' . 'INNER JOIN `' . CoreTables::TERRITORY_TBL . '` t ON t.`id` = a.`territoryId` ' . 'WHERE a.`projectId` = :projectId AND a.`statusId` = :statusId', [':projectId' => $export['projectId'], ':statusId' => $export['areaStatusId']]);
         $block = new ExportBlock();
         foreach ($areas as $area) {
             $block->addId($area['id']);
             if ($area['lastUpdatedAt'] > $lastExportedAt) {
                 $area['customData'] = json_decode($area['customData']);
                 $block->addUpdatedId($area['id']);
                 $block->addUpdate($area);
             }
         }
         $event = new ExportEvent($export['projectId'], $export['lastExportedAt'], $reporter);
         $event->addBlock('area', $block);
         $event = $this->eventDispatcher->dispatch(ExportEvents::EXPORT_ONGOING, $event);
         $this->conn->executeQuery('UPDATE `' . ExportTables::DATA_EXPORT_TBL . '` SET `lastExportedAt` = :time WHERE `id` = :id', [':time' => time(), ':id' => $export['id']]);
         $this->conn->commit();
         return $event->output();
     } catch (Exception $ex) {
         $this->conn->rollBack();
         throw $ex;
     }
 }
开发者ID:zyxist,项目名称:cantiga,代码行数:26,代码来源:ExportEngine.php

示例2: tearDown

 /**
  * @inheritdoc
  */
 protected function tearDown()
 {
     parent::tearDown();
     if ($this->shouldPreventCommits === true && $this->sharedConnection !== null) {
         $this->sharedConnection->rollBack();
         $this->sharedConnection = null;
     }
     Mockery::close();
 }
开发者ID:limoncello-php,项目名称:app,代码行数:12,代码来源:TestCase.php

示例3: doEnd

 protected function doEnd()
 {
     $this->cleanUpExecutionStateTable();
     $this->cleanUpExecutionTable();
     if (!$this->isCancelled()) {
         $this->conn->commit();
     } else {
         $this->conn->rollBack();
         // ?
     }
 }
开发者ID:beberlei,项目名称:Doctrine-Workflow,代码行数:11,代码来源:DoctrineExecution.php

示例4: closeTransaction

 /**
  * Closes the transaction. If the transaction has been marked to rollback, it is rolled back. Otherwise
  * it is committed. The method does nothing, if the transaction is not open.
  */
 public function closeTransaction()
 {
     if ($this->inTransaction) {
         $this->inTransaction = false;
         if ($this->shouldCommit) {
             $this->conn->commit();
         } else {
             $this->conn->rollBack();
         }
         $this->shouldCommit = true;
     }
 }
开发者ID:zyxist,项目名称:cantiga,代码行数:16,代码来源:Transaction.php

示例5: performRollBack

 protected function performRollBack($identifier = NULL)
 {
     if ($identifier === NULL) {
         return $this->conn->rollBack();
     }
     $this->conn->rollbackSavepoint($identifier);
 }
开发者ID:koolkode,项目名称:database,代码行数:7,代码来源:Connection.php

示例6: convertToCharacterSetAndCollation

 /**
  * Convert the tables in the current database to use given character set and collation.
  *
  * @param string $characterSet Character set to convert to
  * @param string $collation Collation to set, must be compatible with the character set
  * @param string $outputPathAndFilename
  * @param boolean $verbose
  * @throws ConnectionException
  * @throws DBALException
  */
 protected function convertToCharacterSetAndCollation($characterSet = 'utf8', $collation = 'utf8_unicode_ci', $outputPathAndFilename = null, $verbose = false)
 {
     $statements = ['SET foreign_key_checks = 0'];
     $statements[] = 'ALTER DATABASE ' . $this->connection->quoteIdentifier($this->persistenceSettings['backendOptions']['dbname']) . ' CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
     $tableNames = $this->connection->getSchemaManager()->listTableNames();
     foreach ($tableNames as $tableName) {
         $statements[] = 'ALTER TABLE ' . $this->connection->quoteIdentifier($tableName) . ' DEFAULT CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
         $statements[] = 'ALTER TABLE ' . $this->connection->quoteIdentifier($tableName) . ' CONVERT TO CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
     }
     $statements[] = 'SET foreign_key_checks = 1';
     if ($outputPathAndFilename === null) {
         try {
             $this->connection->beginTransaction();
             foreach ($statements as $statement) {
                 if ($verbose) {
                     $this->outputLine($statement);
                 }
                 $this->connection->exec($statement);
             }
             $this->connection->commit();
         } catch (\Exception $exception) {
             $this->connection->rollBack();
             $this->outputLine($exception->getMessage());
             $this->outputLine('[ERROR] The transaction was rolled back.');
         }
     } else {
         file_put_contents($outputPathAndFilename, implode(';' . PHP_EOL, $statements) . ';');
     }
 }
开发者ID:neos,项目名称:flow-development-collection,代码行数:39,代码来源:DatabaseCommandController.php

示例7: rollBack

 /**
  * Rolls back the transaction.
  * It makes sure that the connection is in the correct state regardless of what happened before.
  * Correct state means that connection is not rollback only and does not have a transaction nesting level > 0
  *
  * @throws \Exception
  */
 public function rollBack()
 {
     try {
         /**
          * Roll back all the way as this is supposed to be the top level transaction and we want to reset
          * the nesting level
          */
         $transactionNestingLevel = $this->connection->getTransactionNestingLevel();
         for ($i = 0; $i < $transactionNestingLevel - 1; $i++) {
             $this->connection->rollBack();
         }
         $this->connection->rollBack();
     } catch (\Exception $e) {
         $rethrowable = $this->attemptToReconnectPresumedLostConnection($e);
         /**
          * If connection is functional we need to make sure the connection is not rollback only.
          * This can only be achieved by starting a transaction and rolling it back (the "why" is found in
          * lines 1277-1279 of Doctrine\DBAL\Connection).
          */
         if ($rethrowable === $e) {
             $this->connection->beginTransaction();
             $this->connection->rollBack();
         }
         throw $rethrowable;
     }
 }
开发者ID:phpservicebus,项目名称:persistence-doctrine2,代码行数:33,代码来源:OutboxPersister.php

示例8: massUpsert

 /**
  * Insert multiple rows, if a row with a duplicate key is found will update the row
  * This function assumes that 'id' is the primary key, and is used as a fallback for databases that don't support real upserts
  *
  * @param string $table
  * @param array $rows array of column => value
  * @param null $lastInsertId Optional reference to populate with the last auto increment id
  * @return int The number of affected rows
  *
  * @throws \Doctrine\DBAL\ConnectionException
  * @throws \Exception
  */
 public function massUpsert($table, array $rows, &$lastInsertId = null)
 {
     if (empty($rows)) {
         return 0;
     }
     $rowsToInsert = [];
     $rowsToUpdate = [];
     foreach ($rows as $row) {
         if (!empty($row['id'])) {
             $rowsToUpdate[] = $row;
         } else {
             $rowsToInsert[] = $row;
         }
     }
     $this->db->beginTransaction();
     try {
         $effected = $this->massInsert($table, $rowsToInsert);
         $lastInsertId = $this->getLastInsertId($table) - (count($rowsToInsert) - 1);
         foreach ($rowsToUpdate as $row) {
             $id = $row['id'];
             unset($row['id']);
             $effected += $this->db->update($this->db->quoteIdentifier($table), $this->quoteIdentifiers($row), ['id' => $id]);
         }
         $this->db->commit();
     } catch (\Exception $e) {
         $this->db->rollBack();
         throw $e;
     }
     return $effected;
 }
开发者ID:thewunder,项目名称:corma,代码行数:42,代码来源:QueryHelper.php

示例9: fixVersion

 /**
  * @param string $version
  * @param \DateTime $apply_at
  * @throws \Exception
  */
 public function fixVersion($version, \DateTime $apply_at = null)
 {
     if ($apply_at === null) {
         $apply_at = new \DateTime();
     }
     $this->createTable();
     $this->doctrine->beginTransaction();
     try {
         $this->doctrine->delete(self::TABLE_NAME, array('version' => $version));
         $this->doctrine->insert(self::TABLE_NAME, array('version' => $version, 'apply_at' => $apply_at->format('Y-m-d\\TH:i:s')));
         $this->doctrine->commit();
     } catch (\Exception $ex) {
         $this->doctrine->rollBack();
         throw $ex;
     }
 }
开发者ID:sickhye,项目名称:php-db-migrate,代码行数:21,代码来源:DbTable.php

示例10: rollBack

 /**
  * Rollback a transaction.
  *
  * @return void
  */
 public function rollBack()
 {
     try {
         $this->connection->rollBack();
     } catch (DBALException $e) {
         throw new QueryException($e->getMessage(), $e->getCode(), $e);
     }
 }
开发者ID:nlescure,项目名称:ezpublish-kernel,代码行数:13,代码来源:ConnectionHandler.php

示例11: executeTransactionalQuery

 /**
  * @param callable $callback
  *
  * @return bool|int
  * @throws \Doctrine\DBAL\ConnectionException
  */
 public function executeTransactionalQuery(callable $callback)
 {
     $this->connection->beginTransaction();
     try {
         $result = $callback();
         $this->connection->commit();
     } catch (\Exception $e) {
         $this->connection->rollBack();
         $this->logger->error('database', $e);
         $result = false;
     }
     return $result;
 }
开发者ID:acp3,项目名称:core,代码行数:19,代码来源:Connection.php

示例12: insertNewList

 /**
  * Salva a lista de presença (salva as faltas) de uma data específica no banco de dados.
  * 
  * @param Connection $conn
  * @param DateTime $date Data da lista de presença
  * @param array $types Tipos de presença
  * @param array $students Alunos
  * @throws Exception
  */
 public static function insertNewList(Connection $conn, DateTime $date, array $types, array $students = [])
 {
     $conn->beginTransaction();
     try {
         foreach ($types as $type) {
             $conn->delete('attendance', ['attendance_date' => $date, 'attendance_type_id' => $type], ['date', PDO::PARAM_INT]);
         }
         foreach ($students as $student) {
             $conn->insert('attendance', ['enrollment_id' => $student['id'], 'attendance_type_id' => $student['type'], 'attendance_date' => $date], [PDO::PARAM_INT, PDO::PARAM_INT, 'date']);
         }
         $conn->commit();
     } catch (Exception $ex) {
         $conn->rollBack();
         throw $ex;
     }
 }
开发者ID:CATSInformatica,项目名称:CatsSys,代码行数:25,代码来源:AttendanceRepository.php

示例13: applySqlPatch

/**
 * @param DBPatcher\PatchFile $patchFile
 * @param \Doctrine\DBAL\Connection $connection
 * @return DBPatcher\PatchFile
 */
function applySqlPatch($patchFile, $connection)
{
    if ($patchFile->extension === 'sql') {
        $sqlCommands = file_get_contents($patchFile->filename);
        $connection->beginTransaction();
        try {
            $connection->exec($sqlCommands);
        } catch (\Doctrine\DBAL\DBALException $e) {
            $connection->rollBack();
            return array(DBPatcher\PatchFile::copyWithNewStatus($patchFile, DBPatcher\PatchFile::STATUS_ERROR), $e->getMessage());
        }
        $connection->commit();
        return array(DBPatcher\PatchFile::copyWithNewStatus($patchFile, DBPatcher\PatchFile::STATUS_INSTALLED));
    }
    return array(DBPatcher\PatchFile::copyWithNewStatus($patchFile, DBPatcher\PatchFile::STATUS_ERROR));
}
开发者ID:jamayka,项目名称:db-patcher,代码行数:21,代码来源:functions.php

示例14: delete

 /**
  * Deletes all nodes with edges from database
  *
  * @throws DatabaseErrorException
  */
 public function delete()
 {
     try {
         $this->dbal->setAutoCommit(false);
         $this->dbal->beginTransaction();
         $this->dbal->executeQuery('DELETE FROM relations');
         $this->dbal->executeQuery('DELETE FROM organizations');
         $this->dbal->commit();
         $this->dbal->setAutoCommit(true);
     } catch (\Doctrine\DBAL\ConnectionException $exception) {
         throw new DatabaseErrorException($exception);
     } catch (\Doctrine\DBAL\DBALException $exception) {
         $this->dbal->rollBack();
         $this->dbal->setAutoCommit(true);
         throw new DatabaseErrorException($exception);
     }
 }
开发者ID:EugeneKirillov,项目名称:organization-relationships,代码行数:22,代码来源:OrganizationsRepository.php

示例15: write

 /**
  * @param array $data
  * @param string $namespace
  * @param int $localeId
  * @param int $shopId
  * @throws \Exception
  */
 public function write($data, $namespace, $localeId, $shopId)
 {
     if (empty($data)) {
         throw new \Exception('You called write() but provided no data to be written');
     }
     if (!isset($this->db)) {
         throw new \Exception('Required database connection is missing');
     }
     $this->db->beginTransaction();
     try {
         // If no update are allowed, we can speed up using INSERT IGNORE
         if (!$this->update) {
             $this->insertBatch($data, $namespace, $localeId, $shopId);
         } else {
             $rows = $this->db->fetchAll('SELECT * FROM s_core_snippets WHERE shopID = :shopId AND localeID = :localeId AND namespace = :namespace', array('shopId' => $shopId, 'localeId' => $localeId, 'namespace' => $namespace));
             foreach ($data as $name => $value) {
                 $row = null;
                 // Find the matching value in db, if it exists
                 foreach ($rows as $key => $values) {
                     if ($values['name'] == $name) {
                         $row = $values;
                         unset($rows[$key]);
                         break;
                     }
                 }
                 if ($row !== null) {
                     // Found a matching value, try update
                     $this->updateRecord($value, $row);
                 } else {
                     // No matching value, just insert a new one
                     $this->insertRecord($name, $value, $namespace, $localeId, $shopId);
                 }
             }
         }
         $this->db->commit();
     } catch (\Exception $e) {
         $this->db->rollBack();
         throw new \Exception(sprintf('An error occurred when importing namespace "%s" for locale "%s"', $namespace, $localeId), 0, $e);
     }
 }
开发者ID:GerDner,项目名称:luck-docker,代码行数:47,代码来源:DatabaseWriter.php


注:本文中的Doctrine\DBAL\Connection::rollBack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。