/** * Rollback or revert to a savepoint if your queries encounter problems * If you encounter a problem at any point during a transaction, you may * need to rollback that particular query, or return to a savepoint */ public function transactionRollback() { $result = sqlsrv_rollback($this->dbConn); if (!$result) { $this->databaseError("Couldn't rollback the transaction."); } }
public function rollbackTransaction() { if ($this->transactionOn) { //$this->execute('ROLLBACK TRANSACTION'); sqlsrv_rollback($this->connection); $this->transactionOn = false; } }
function trans_rollback() { if (!$this->trans_enabled) { return TRUE; } if ($this->_trans_depth > 0) { return TRUE; } return sqlsrv_rollback($this->conn_id); }
/** * SQL Transaction * @access private */ function _sql_transaction($status = 'begin') { switch ($status) { case 'begin': return sqlsrv_begin_transaction($this->db_connect_id); break; case 'commit': return sqlsrv_commit($this->db_connect_id); break; case 'rollback': return sqlsrv_rollback($this->db_connect_id); break; } return true; }
/** * 事务回滚 * @access public * @return boolean */ public function rollback() { if ($this->transTimes > 0) { $result = sqlsrv_rollback($this->_linkID); $this->transTimes = 0; if (!$result) { $this->error(); return false; } } return true; }
/** * Roll back a transaction and return to autocommit mode. * * @return void * @throws Zend_Db_Adapter_Sqlsrv_Exception */ protected function _rollBack() { if (!sqlsrv_rollback($this->_connection)) { require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php'; throw new Zend_Db_Adapter_Sqlsrv_Exception(sqlsrv_errors()); } }
public function rollback_transaction() { sqlsrv_rollback($this->connection); }
/** * Rollback Transaction * * @access public * @return bool */ function trans_rollback() { if (!$this->trans_enabled) { return TRUE; } // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 0) { return TRUE; } return sqlsrv_rollback($this->conn_id); }
/** * Rollback */ public function rollback() { // http://msdn.microsoft.com/en-us/library/cc296176.aspx if (!$this->resource) { throw new Exception\RuntimeException('Must be connected before you can rollback.'); } return sqlsrv_rollback($this->resource); }
/** * Rollbacks started database transaction. * * @return void * @throws \Bitrix\Main\Db\SqlQueryException */ public function rollbackTransaction() { $this->connectInternal(); sqlsrv_rollback($this->resource); }
function rollback_trans() { sqlsrv_rollback($this->conn); $this->in_trans = false; }
/** * Rollback changes in a transaction. * @param string optional savepoint name * @return void * @throws Dibi\DriverException */ public function rollback($savepoint = NULL) { sqlsrv_rollback($this->connection); }
/** * Roll back a transaction and return to autocommit mode. * * @return void * @throws \Zend\Db\Adapter\SqlsrvException */ protected function _rollBack() { if (!sqlsrv_rollback($this->_connection)) { throw new SqlsrvException(sqlsrv_errors()); } }
/** * Execute data manipulation statement, then roll it back * @param $type * @param $table * @param $query * @return string */ protected function verifyGenericQueryRollback($type, $table, $query) { $this->log->debug("verifying {$type} statement"); if (!sqlsrv_begin_transaction($this->database)) { return "Failed to create transaction"; } $this->query($query, false); $error = $this->lastError(); sqlsrv_rollback($this->database); return $error; }
/** * Rolls back the sql transaction. * * @return boolean (Returns TRUE on success or FALSE on failure.) */ function dbTransactionRollback() { return sqlsrv_rollback(Database::getConnection()); // Rolls back a transaction. }
/** * Rollback a transaction. * No-op on non-transactional databases. */ protected function doRollback($fname = __METHOD__) { sqlsrv_rollback($this->mConn); $this->mTrxLevel = 0; }
/** * Driver specific abort of real database transaction, * this can not be used directly in code. * @return void */ protected function rollback_transaction() { $this->query_start('native sqlsrv_rollback', NULL, SQL_QUERY_AUX); $result = sqlsrv_rollback($this->sqlsrv); $this->query_end($result); }
/** * Rollback a transaction * * @return boolean */ public function rollBack() { return sqlsrv_rollback($this->connection); }
/** * @brief 롤백 **/ function rollback() { if ($this->is_connected == false || !$this->transaction_started) { return; } $this->transaction_started = false; sqlsrv_rollback($this->conn); }
/** * DB transaction rollback * this method is private * @return boolean */ function _rollback($transactionLevel = 0) { $connection = $this->_getConnection('master'); $point = $transactionLevel - 1; if ($point) { $this->_query("ROLLBACK TRANS SP" . $point, $connection); } else { sqlsrv_rollback($connection); } return true; }
protected function _rollback() { return sqlsrv_rollback($this->handle); }
/** * Rollback Transaction * * @return bool */ protected function _trans_rollback() { return sqlsrv_rollback($this->conn_id); }
/** * Cancel any database changes done during a transaction or since a specific * savepoint that is in progress. This function may only be called when * auto-committing is disabled, otherwise it will fail. Therefore, a new * transaction is implicitly started after canceling the pending changes. * * @param string name of a savepoint to rollback to * @return mixed MDB2_OK on success, a MDB2 error on failure * * @access public */ function rollback($savepoint = null) { $this->debug('Rolling back transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint)); if (!$this->in_transaction) { return $this->raiseError(MDB2_ERROR_INVALID, null, null, 'rollback cannot be done changes are auto committed', __FUNCTION__); } if (null !== $savepoint) { $query = 'ROLLBACK TRANSACTION ' . $savepoint; return $this->_doQuery($query, true); } if (MDB2::isError(sqlsrv_rollback($this->connection))) { return MDB2_ERROR; } $this->in_transaction = false; return MDB2_OK; }
/** * Rollback a transaction. * No-op on non-transactional databases. */ function rollback($fname = 'DatabaseMssql::rollback') { sqlsrv_rollback($this->mConn); $this->mTrxLevel = 0; }
/** * {@inheritDoc} */ public function rollBack() { if (!sqlsrv_rollback($this->conn)) { throw SQLSrvException::fromSqlSrvErrors(); } }
/** * Makes sure each database and extension handles BEGIN, COMMIT and ROLLBACK * * @param string|fStatement &$statement The SQL to check for a transaction query * @param string $result_class The type of result object to create * @return mixed `FALSE` if normal processing should continue, otherwise an object of the type $result_class */ private function handleTransactionQueries(&$statement, $result_class) { if (is_object($statement)) { $sql = $statement->getSQL(); } else { $sql = $statement; } // SQL Server supports transactions, but the statements are slightly different. // For the interest of convenience, we do simple transaction right here. if ($this->type == 'mssql') { if (preg_match('#^\\s*(BEGIN|START(\\s+TRANSACTION)?)\\s*$#i', $sql)) { $statement = 'BEGIN TRANSACTION'; } elseif (preg_match('#^\\s*SAVEPOINT\\s+("?\\w+"?)\\s*$#i', $sql, $match)) { $statement = 'SAVE TRANSACTION ' . $match[1]; } elseif (preg_match('#^\\s*ROLLBACK\\s+TO\\s+SAVEPOINT\\s+("?\\w+"?)\\s*$#i', $sql, $match)) { $statement = 'ROLLBACK TRANSACTION ' . $match[1]; } } $begin = FALSE; $commit = FALSE; $rollback = FALSE; // Track transactions since most databases don't support nesting if (preg_match('#^\\s*(BEGIN|START)(\\s+(TRAN|TRANSACTION|WORK))?\\s*$#iD', $sql)) { if ($this->inside_transaction) { throw new fProgrammerException('A transaction is already in progress'); } $this->inside_transaction = TRUE; $begin = TRUE; } elseif (preg_match('#^\\s*COMMIT(\\s+(TRAN|TRANSACTION|WORK))?\\s*$#iD', $sql)) { if (!$this->inside_transaction) { throw new fProgrammerException('There is no transaction in progress'); } $this->inside_transaction = FALSE; $commit = TRUE; } elseif (preg_match('#^\\s*ROLLBACK(\\s+(TRAN|TRANSACTION|WORK))?\\s*$#iD', $sql)) { if (!$this->inside_transaction) { throw new fProgrammerException('There is no transaction in progress'); } $this->inside_transaction = FALSE; $rollback = TRUE; // MySQL needs to use this construct for starting transactions when using LOCK tables } elseif ($this->type == 'mysql' && preg_match('#^\\s*SET\\s+autocommit\\s*=\\s*(0|1)#i', $sql, $match)) { $this->inside_transaction = TRUE; if ($match[1] == '0') { $this->schema_info['mysql_autocommit'] = TRUE; } else { unset($this->schema_info['mysql_autocommit']); } // We have to track LOCK TABLES for MySQL because UNLOCK TABLES only implicitly commits if LOCK TABLES was used } elseif ($this->type == 'mysql' && preg_match('#^\\s*LOCK\\s+TABLES#i', $sql)) { // This command always implicitly commits $this->inside_transaction = FALSE; $this->schema_info['mysql_lock_tables'] = TRUE; // MySQL has complex handling of UNLOCK TABLES } elseif ($this->type == 'mysql' && preg_match('#^\\s*UNLOCK\\s+TABLES#i', $sql)) { // This command only implicitly commits if LOCK TABLES was used if (isset($this->schema_info['mysql_lock_tables'])) { $this->inside_transaction = FALSE; } unset($this->schema_info['mysql_lock_tables']); // These databases issue implicit commit commands when the following statements are run } elseif ($this->type == 'mysql' && preg_match('#^\\s*(ALTER|CREATE(?!\\s+TEMPORARY)|DROP|RENAME|TRUNCATE|LOAD|UNLOCK|GRANT|REVOKE|SET\\s+PASSWORD|CACHE|ANALYSE|CHECK|OPTIMIZE|REPAIR|FLUSH|RESET)\\b#i', $sql)) { $this->inside_transaction = FALSE; } elseif ($this->type == 'oracle' && preg_match('#^\\s*(CREATE|ALTER|DROP|TRUNCATE|GRANT|REVOKE|REPLACE|ANALYZE|AUDIT|COMMENT)\\b#i', $sql)) { $this->inside_transaction = FALSE; } elseif ($this->type == 'db2' && preg_match('#^\\s*CALL\\s+SYSPROC\\.ADMIN_CMD\\(\'REORG\\s+TABLE\\b#i', $sql)) { $this->inside_transaction = FALSE; // It appears PDO tracks the transactions, but doesn't know about implicit commits if ($this->extension == 'pdo') { $this->connection->commit(); } } // If MySQL autocommit it set to 0 a new transaction is automatically started if (!empty($this->schema_info['mysql_autocommit'])) { $this->inside_transaction = TRUE; } if (!$begin && !$commit && !$rollback) { return FALSE; } // The PDO, OCI8 and SQLSRV extensions require special handling through methods and functions $is_pdo = $this->extension == 'pdo'; $is_oci = $this->extension == 'oci8'; $is_sqlsrv = $this->extension == 'sqlsrv'; $is_ibm_db2 = $this->extension == 'ibm_db2'; if (!$is_pdo && !$is_oci && !$is_sqlsrv && !$is_ibm_db2) { return FALSE; } $this->statement = $statement; // PDO seems to act weird if you try to start transactions through a normal query call if ($is_pdo) { try { $is_mssql = $this->type == 'mssql'; $is_oracle = $this->type == 'oracle'; if ($begin) { // The SQL Server PDO object hasn't implemented transactions if ($is_mssql) { $this->connection->exec('BEGIN TRANSACTION'); } elseif ($is_oracle) { $this->connection->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE); } else { $this->connection->beginTransaction(); } } elseif ($commit) { if ($is_mssql) { $this->connection->exec('COMMIT'); } elseif ($is_oracle) { $this->connection->exec('COMMIT'); $this->connection->setAttribute(PDO::ATTR_AUTOCOMMIT, TRUE); } else { $this->connection->commit(); } } elseif ($rollback) { if ($is_mssql) { $this->connection->exec('ROLLBACK'); } elseif ($is_oracle) { $this->connection->exec('ROLLBACK'); $this->connection->setAttribute(PDO::ATTR_AUTOCOMMIT, TRUE); } else { $this->connection->rollBack(); } } } catch (Exception $e) { $db_type_map = array('db2' => 'DB2', 'mssql' => 'MSSQL', 'mysql' => 'MySQL', 'oracle' => 'Oracle', 'postgresql' => 'PostgreSQL', 'sqlite' => 'SQLite'); throw new fSQLException('%1$s error (%2$s) in %3$s', $db_type_map[$this->type], $e->getMessage(), $sql); } } elseif ($is_oci) { if ($commit) { oci_commit($this->connection); } elseif ($rollback) { oci_rollback($this->connection); } } elseif ($is_sqlsrv) { if ($begin) { sqlsrv_begin_transaction($this->connection); } elseif ($commit) { sqlsrv_commit($this->connection); } elseif ($rollback) { sqlsrv_rollback($this->connection); } } elseif ($is_ibm_db2) { if ($begin) { db2_autocommit($this->connection, FALSE); } elseif ($commit) { db2_commit($this->connection); db2_autocommit($this->connection, TRUE); } elseif ($rollback) { db2_rollback($this->connection); db2_autocommit($this->connection, TRUE); } } if ($result_class) { $result = new $result_class($this); $result->setSQL($sql); $result->setResult(TRUE); return $result; } return TRUE; }
function RollbackTrans() { if ($this->transOff) { return true; } if ($this->debug) { error_log('<hr>rollback transaction'); } if ($this->transCnt) { $this->transCnt -= 1; } sqlsrv_rollback($this->_connectionID); return true; }
/** * Rollback or revert to a savepoint if your queries encounter problems * If you encounter a problem at any point during a transaction, you may * need to rollback that particular query, or return to a savepoint */ public function transactionRollback($savepoint = false) { if ($savepoint) { DB::query("ROLLBACK TRANSACTION \"{$savepoint}\""); } else { if ($this->mssql) { DB::query('ROLLBACK TRANSACTION'); } else { $result = sqlsrv_rollback($this->dbConn); if (!$result) { $this->databaseError("Couldn't rollback the transaction.", E_USER_ERROR); } } } }
/** * Makes sure each database and extension handles BEGIN, COMMIT and ROLLBACK * * @param string &$sql The SQL to check for a transaction query * @param string $result_class The type of result object to create * @return mixed `FALSE` if normal processing should continue, otherwise an object of the type $result_class */ private function handleTransactionQueries(&$sql, $result_class) { // SQL Server supports transactions, but starts then with BEGIN TRANSACTION if ($this->type == 'mssql' && preg_match('#^\\s*(begin|start(\\s+transaction)?)\\s*#i', $sql)) { $sql = 'BEGIN TRANSACTION'; } $begin = FALSE; $commit = FALSE; $rollback = FALSE; // Track transactions since most databases don't support nesting if (preg_match('#^\\s*(begin|start)(\\s+(transaction|work))?\\s*$#iD', $sql)) { if ($this->inside_transaction) { throw new fProgrammerException('A transaction is already in progress'); } $this->inside_transaction = TRUE; $begin = TRUE; } elseif (preg_match('#^\\s*(commit)(\\s+(transaction|work))?\\s*$#iD', $sql)) { if (!$this->inside_transaction) { throw new fProgrammerException('There is no transaction in progress'); } $this->inside_transaction = FALSE; $commit = TRUE; } elseif (preg_match('#^\\s*(rollback)(\\s+(transaction|work))?\\s*$#iD', $sql)) { if (!$this->inside_transaction) { throw new fProgrammerException('There is no transaction in progress'); } $this->inside_transaction = FALSE; $rollback = TRUE; } if (!$begin && !$commit && !$rollback) { return FALSE; } // The PDO, OCI8 and SQLSRV extensions require special handling through methods and functions $is_pdo = $this->extension == 'pdo'; $is_oci = $this->extension == 'oci8'; $is_sqlsrv = $this->extension == 'sqlsrv'; $is_ibm_db2 = $this->extension == 'ibm_db2'; if (!$is_pdo && !$is_oci && !$is_sqlsrv && !$is_ibm_db2) { return FALSE; } $this->statement = $sql; // PDO seems to act weird if you try to start transactions through a normal query call if ($is_pdo) { try { $is_mssql = $this->type == 'mssql' && substr($this->database, 0, 4) != 'dsn:'; $is_oracle = $this->type == 'oracle' && substr($this->database, 0, 4) != 'dsn:'; if ($begin) { // The SQL Server PDO object hasn't implemented transactions if ($is_mssql) { $this->connection->exec('BEGIN TRANSACTION'); } elseif ($is_oracle) { $this->connection->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE); } else { $this->connection->beginTransaction(); } } elseif ($commit) { if ($is_mssql) { $this->connection->exec('COMMIT'); } elseif ($is_oracle) { $this->connection->exec('COMMIT'); $this->connection->setAttribute(PDO::ATTR_AUTOCOMMIT, TRUE); } else { $this->connection->commit(); } } elseif ($rollback) { if ($is_mssql) { $this->connection->exec('ROLLBACK'); } elseif ($is_oracle) { $this->connection->exec('ROLLBACK'); $this->connection->setAttribute(PDO::ATTR_AUTOCOMMIT, TRUE); } else { $this->connection->rollBack(); } } } catch (Exception $e) { $db_type_map = array('db2' => 'DB2', 'mssql' => 'MSSQL', 'mysql' => 'MySQL', 'oracle' => 'Oracle', 'postgresql' => 'PostgreSQL', 'sqlite' => 'SQLite'); throw new fSQLException('%1$s error (%2$s) in %3$s', $db_type_map[$this->type], $e->getMessage(), $sql); } } elseif ($is_oci) { if ($commit) { oci_commit($this->connection); } elseif ($rollback) { oci_rollback($this->connection); } } elseif ($is_sqlsrv) { if ($begin) { sqlsrv_begin_transaction($this->connection); } elseif ($commit) { sqlsrv_commit($this->connection); } elseif ($rollback) { sqlsrv_rollback($this->connection); } } elseif ($is_ibm_db2) { if ($begin) { db2_autocommit($this->connection, FALSE); } elseif ($commit) { db2_commit($this->connection); db2_autocommit($this->connection, TRUE); } elseif ($rollback) { db2_rollback($this->connection); db2_autocommit($this->connection, TRUE); } } if ($result_class) { $result = new $result_class($this); $result->setSQL($sql); $result->setResult(TRUE); return $result; } return TRUE; }
/** +---------------------------------------------------------- * 事务回滚 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @return boolen +---------------------------------------------------------- */ public function rollback() { if ($this->transTimes > 0) { $result = sqlsrv_rollback($this->_linkID); $this->transTimes = 0; if (!$result) { throw_exception($this->error()); } } return true; }