function begin_trans() { if (sqlsrv_begin_transaction($this->conn) == false) { echo "Could not begin transaction.\n"; die(print_r(sqlsrv_errors(), true)); } $this->in_trans = true; }
public function begin_transaction() { sqlsrv_begin_transaction($this->connection); }
/** * Begin Transaction * * @access public * @return bool */ function trans_begin($test_mode = FALSE) { 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; } // Reset the transaction failure flag. // If the $test_mode flag is set to TRUE transactions will be rolled back // even if the queries produce a successful result. $this->_trans_failure = $test_mode === TRUE ? TRUE : FALSE; return sqlsrv_begin_transaction($this->conn_id); }
function trans_begin($test_mode = FALSE) { if (!$this->trans_enabled) { return TRUE; } if ($this->_trans_depth > 0) { return TRUE; } $this->_trans_failure = $test_mode === TRUE ? TRUE : FALSE; return sqlsrv_begin_transaction($this->conn_id); }
/** * This function begins a transaction. * * @access public * @override * @throws Throwable_SQL_Exception indicates that the executed * statement failed * * @see http://msdn.microsoft.com/en-us/library/ms188929.aspx * @see http://php.net/manual/en/function.sqlsrv-begin-transaction.php */ public function begin_transaction() { if (!$this->is_connected()) { throw new Throwable_SQL_Exception('Message: Failed to begin SQL transaction. Reason: Unable to find connection.'); } $command = @sqlsrv_begin_transaction($this->resource); if ($command === FALSE) { $errors = @sqlsrv_errors(SQLSRV_ERR_ALL); $reason = (is_array($errors) and isset($errors[0]['message'])) ? $errors[0]['message'] : 'Unable to perform command.'; throw new Throwable_SQL_Exception('Message: Failed to begin the transaction. Reason: :reason', array(':reason' => $reason)); } $this->sql = 'BEGIN TRAN;'; }
/** * 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; }
/** * Starts new database transaction. * * @return void * @throws \Bitrix\Main\Db\SqlQueryException */ public function startTransaction() { $this->connectInternal(); sqlsrv_begin_transaction($this->resource); }
/** * Driver specific start of real database transaction, * this can not be used directly in code. * @return void */ protected function begin_transaction() { // Recordsets do not work well with transactions in SQL Server, // let's prefetch the recordsets to memory to work around these problems. foreach ($this->recordsets as $rs) { $rs->transaction_starts(); } $this->query_start('native sqlsrv_begin_transaction', NULL, SQL_QUERY_AUX); $result = sqlsrv_begin_transaction($this->sqlsrv); $this->query_end($result); }
/** * Begin a transaction, committing any previously open transaction */ protected function doBegin($fname = __METHOD__) { sqlsrv_begin_transaction($this->mConn); $this->mTrxLevel = 1; }
/** * 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; }
/** * 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; }
protected function _start_trans() { return sqlsrv_begin_transaction($this->handle) ? true : false; }
/** * Start a transaction or set a savepoint. * * @param string name of a savepoint to set * @return mixed MDB2_OK on success, a MDB2 error on failure * * @access public */ function beginTransaction($savepoint = null) { $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint)); if (null !== $savepoint) { if (!$this->in_transaction) { return $this->raiseError(MDB2_ERROR_INVALID, null, null, 'savepoint cannot be released when changes are auto committed', __FUNCTION__); } $query = 'SAVE TRANSACTION ' . $savepoint; return $this->_doQuery($query, true); } if ($this->in_transaction) { return MDB2_OK; //nothing to do } if (!$this->destructor_registered && $this->opened_persistent) { $this->destructor_registered = true; register_shutdown_function('MDB2_closeOpenTransactions'); } if (MDB2::isError(sqlsrv_begin_transaction($this->connection))) { return MDB2_ERROR; } $this->in_transaction = true; return MDB2_OK; }
/** * DB transaction start * this method is private * @return boolean */ function _begin($transactionLevel = 0) { $connection = $this->_getConnection('master'); if (!$transactionLevel) { if (sqlsrv_begin_transaction($connection) === false) { return; } } else { $this->_query("SAVE TRANS SP" . $transactionLevel, $connection); } return true; }
//get_area_settings($area); //$notify_by_email = $mail_settings['on_delete'] && $need_to_send_mail; /*if ($notify_by_email) { require_once "functions_mail.inc"; // Gather all fields values for use in emails. $mail_previous = get_booking_info($id, FALSE); // If this is an individual entry of a series then force the entry_type // to be a changed entry, so that when we create the iCalendar object we know that // we only want to delete the individual entry if (!$series && ($mail_previous['rep_type'] != REP_NONE)) { $mail_previous['entry_type'] = ENTRY_RPT_CHANGED; } }*/ sqlsrv_begin_transaction($conn); $start_times = mrbsDelEntry('test', $id, $series, 1); sqlsrv_commit($conn); // [At the moment MRBS does not inform the user if it was not able to delete // an entry, or, for a series, some entries in a series. This could happen for // example if a booking policy is in force that prevents the deletion of entries // in the past. It would be better to inform the user that the operation has // been unsuccessful or only partially successful] if ($start_times !== FALSE && count($start_times) > 0) { // Send a mail to the Administrator if ($notify_by_email) { // Now that we've finished with mrbsDelEntry, change the id so that it's // the repeat_id if we're looking at a series. (This is a complete hack, // but brings us back into line with the rest of MRBS until the anomaly // of del_entry is fixed) if ($series) {
/** * Begins a transaction (if supported). * @param string optional savepoint name * @return void * @throws Dibi\DriverException */ public function begin($savepoint = NULL) { sqlsrv_begin_transaction($this->connection); }
/** * Leave autocommit mode and begin a transaction. * * @return void * @throws \Zend\Db\Adapter\SqlsrvException */ protected function _beginTransaction() { if (!sqlsrv_begin_transaction($this->_connection)) { throw new SqlsrvException(sqlsrv_errors()); } }
/** * @brief 트랜잭션 시작 **/ function begin() { if ($this->is_connected == false || $this->transaction_started) { return; } if (sqlsrv_begin_transaction($this->conn) === false) { return; } $this->transaction_started = true; }
/** * Begin Transaction * * @return bool */ protected function _trans_begin() { return sqlsrv_begin_transaction($this->conn_id); }
/** * Begin transaction */ public function beginTransaction() { if (!$this->resource) { $this->connect(); } if (sqlsrv_begin_transaction($this->resource) === false) { throw new Exception\RuntimeException('Begin transaction failed', null, new ErrorException(sqlsrv_errors())); } $this->inTransaction = true; }
/** * Begin a transaction, committing any previously open transaction */ function begin($fname = 'DatabaseMssql::begin') { sqlsrv_begin_transaction($this->mConn); $this->mTrxLevel = 1; }
/** * Driver specific start of real database transaction, * this can not be used directly in code. * @return void */ protected function begin_transaction() { $this->query_start('native sqlsrv_begin_transaction', NULL, SQL_QUERY_AUX); $result = sqlsrv_begin_transaction($this->sqlsrv); $this->query_end($result); }
/** * {@inheritDoc} */ public function beginTransaction() { if (!$this->isConnected()) { $this->connect(); } if (sqlsrv_begin_transaction($this->resource) === false) { throw new Exception\RuntimeException(new ErrorException(sqlsrv_errors())); } $this->inTransaction = true; return $this; }
/** * 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; }
/** * Start transaction. READ ONLY not supported. */ public function transactionStart($transaction_mode = false, $session_characteristics = false) { if ($this->mssql) { DB::query('BEGIN TRANSACTION'); } else { $result = sqlsrv_begin_transaction($this->dbConn); if (!$result) { $this->databaseError("Couldn't start the transaction.", E_USER_ERROR); } } }
/** * 启动事务 * @access public * @return void */ public function startTrans() { $this->initConnect(true); if (!$this->_linkID) { return false; } //数据rollback 支持 if ($this->transTimes == 0) { sqlsrv_begin_transaction($this->_linkID); } $this->transTimes++; return; }
function BeginTrans() { if ($this->transOff) { return true; } $this->transCnt += 1; if ($this->debug) { error_log('<hr>begin transaction'); } sqlsrv_begin_transaction($this->_connectionID); return true; }
/** * Leave autocommit mode and begin a transaction. * * @return void * @throws Zend_Db_Adapter_Sqlsrv_Exception */ protected function _beginTransaction() { if (!sqlsrv_begin_transaction($this->_connection)) { require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php'; throw new Zend_Db_Adapter_Sqlsrv_Exception(sqlsrv_errors()); } }
/** * {@inheritDoc} */ public function beginTransaction() { if (!sqlsrv_begin_transaction($this->conn)) { throw SQLSrvException::fromSqlSrvErrors(); } }
/** * Start transaction. READ ONLY not supported. */ public function transactionStart() { $result = sqlsrv_begin_transaction($this->dbConn); if (!$result) { $this->databaseError("Couldn't start the transaction."); } }