/** * Rollbacks started database transaction. * * @return void * @throws \Bitrix\Main\Db\SqlQueryException */ public function rollbackTransaction() { $this->connectInternal(); OCIRollback($this->resource); $this->transaction = OCI_COMMIT_ON_SUCCESS; }
function _close() { if (!$this->autoCommit) { OCIRollback($this->_connectionID); } OCILogoff($this->_connectionID); $this->_stmt = false; $this->_connectionID = false; }
function _close() { if (!$this->_connectionID) return; if (!$this->autoCommit) OCIRollback($this->_connectionID); if (count($this->_refLOBs) > 0) { foreach ($this ->_refLOBs as $key => $value) { $this->_refLOBs[$key]['LOB']->free(); unset($this->_refLOBs[$key]); } } OCILogoff($this->_connectionID); $this->_stmt = false; $this->_connectionID = false; }
public function write($id, $data) { $query = "MERGE INTO " . self::$_table["saveHandler"]["options"]["name"] . " M "; $query .= "USING (SELECT '" . $id . "' AS ID, :TIME AS LIFETIME, :DADOS AS DATAVAL FROM DUAL) N "; $query .= "ON (M." . self::$_table["saveHandler"]["options"]["primary"][0] . " = N.ID ) "; $query .= "WHEN MATCHED THEN "; $query .= "UPDATE SET M." . self::$_table["saveHandler"]["options"]["lifetimeColumn"] . " = N.LIFETIME, "; $query .= "M." . self::$_table["saveHandler"]["options"]["dataColumn"] . " = N.DATAVAL "; $query .= "WHEN NOT MATCHED THEN INSERT( " . self::$_table["saveHandler"]["options"]["primary"][0] . ", "; $query .= self::$_table["saveHandler"]["options"]["lifetimeColumn"] . ", "; $query .= self::$_table["saveHandler"]["options"]["dataColumn"] . " ) "; $query .= "VALUES(N.ID, N.LIFETIME, N.DATAVAL) "; $stmt = OCIParse(self::$_db, $query); $clob = OCINewDescriptor(self::$_db, OCI_D_LOB); OCIBindByName($stmt, ':TIME', time()); OCIBindByName($stmt, ':DADOS', $clob, -1, OCI_B_CLOB); $clob->WriteTemporary($data, OCI_TEMP_CLOB); $exe = OCIExecute($stmt, OCI_DEFAULT); if ($exe === true) { $ret = true; OCICommit(self::$_db); } else { $ret = false; OCIRollback(self::$_db); } $clob->close(); $clob->free(); OCIFreeStatement($stmt); return $ret; }
/** * Reverts the current transaction * * @return int DB_OK on success. A DB_Error object on failure. */ function rollback() { $result = @OCIRollback($this->connection); if (!$result) { return $this->oci8RaiseError(); } return DB_OK; }
/** * 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 (!is_null($savepoint)) { $query = 'ROLLBACK TO SAVEPOINT ' . $savepoint; return $this->_doQuery($query, true); } if ($this->uncommitedqueries) { $connection = $this->getConnection(); if (PEAR::isError($connection)) { return $connection; } if (!@OCIRollback($connection)) { return $this->raiseError(null, null, null, 'Unable to rollback transaction', __FUNCTION__); } $this->uncommitedqueries = 0; } $this->in_transaction = false; return MDB2_OK; }
function DBRollback($connection) { // Vuelve para atrĂ¡s las transacciones pendientes.. OCIRollback($connection); }
/** * all the RDBMS specific things needed close a DB connection * * @access private */ function _doQuery($query, $first = 0, $limit = 0, $prepared_query = 0) { $lobs = 0; $success = MDB_OK; $result = 0; $descriptors = array(); if ($prepared_query) { $columns = ''; $variables = ''; for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) { $position = key($this->clobs[$prepared_query]); if (gettype($descriptors[$position] = @OCINewDescriptor($this->connection, OCI_D_LOB)) != 'object') { $success = $this->raiseError(MDB_ERROR, NULL, NULL, 'Do query: Could not create descriptor for clob parameter'); break; } $columns .= ($lobs == 0 ? ' RETURNING ' : ',') . $this->prepared_queries[$prepared_query - 1]['Fields'][$position - 1]; $variables .= ($lobs == 0 ? ' INTO ' : ',') . ':clob' . $position; $lobs++; } if (!MDB::isError($success)) { for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) { $position = key($this->blobs[$prepared_query]); if (gettype($descriptors[$position] = @OCINewDescriptor($this->connection, OCI_D_LOB)) != 'object') { $success = $this->raiseError(MDB_ERROR, NULL, NULL, 'Do query: Could not create descriptor for blob parameter'); break; } $columns .= ($lobs == 0 ? ' RETURNING ' : ',') . $this->prepared_queries[$prepared_query - 1]['Fields'][$position - 1]; $variables .= ($lobs == 0 ? ' INTO ' : ',') . ':blob' . $position; $lobs++; } $query .= $columns . $variables; } } if (!MDB::isError($success)) { if ($statement = @OCIParse($this->connection, $query)) { if ($lobs) { for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) { $position = key($this->clobs[$prepared_query]); if (!@OCIBindByName($statement, ':clob' . $position, $descriptors[$position], -1, OCI_B_CLOB)) { $success = $this->oci8RaiseError(NULL, 'Do query: Could not bind clob upload descriptor'); break; } } if (!MDB::isError($success)) { for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) { $position = key($this->blobs[$prepared_query]); if (!@OCIBindByName($statement, ':blob' . $position, $descriptors[$position], -1, OCI_B_BLOB)) { $success = $this->oci8RaiseError(NULL, 'Do query: Could not bind blob upload descriptor'); break; } } } } if (!MDB::isError($success)) { if ($result = @OCIExecute($statement, $lobs == 0 && $this->auto_commit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT)) { if ($lobs) { for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) { $position = key($this->clobs[$prepared_query]); $clob_stream = $this->prepared_queries[$prepared_query - 1]['Values'][$position - 1]; for ($value = ''; !$this->endOfLOB($clob_stream);) { if ($this->readLOB($clob_stream, $data, $this->getOption('lob_buffer_length')) < 0) { $success = $this->raiseError(); break; } $value .= $data; } if (!MDB::isError($success) && !$descriptors[$position]->save($value)) { $success = $this->oci8RaiseError(NULL, 'Do query: Could not upload clob data'); } } if (!MDB::isError($success)) { for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) { $position = key($this->blobs[$prepared_query]); $blob_stream = $this->prepared_queries[$prepared_query - 1]['Values'][$position - 1]; for ($value = ''; !$this->endOfLOB($blob_stream);) { if ($this->readLOB($blob_stream, $data, $this->getOption('lob_buffer_length')) < 0) { $success = $this->raiseError(); break; } $value .= $data; } if (!MDB::isError($success) && !$descriptors[$position]->save($value)) { $success = $this->oci8RaiseError(NULL, 'Do query: Could not upload blob data'); } } } } if ($this->auto_commit) { if ($lobs) { if (MDB::isError($success)) { if (!@OCIRollback($this->connection)) { $success = $this->oci8RaiseError(NULL, 'Do query: ' . $success->getUserinfo() . ' and then could not rollback LOB updating transaction'); } } else { if (!@OCICommit($this->connection)) { $success = $this->oci8RaiseError(NULL, 'Do query: Could not commit pending LOB updating transaction'); } } } } else { $this->uncommitedqueries++; } if (!MDB::isError($success)) { switch (@OCIStatementType($statement)) { case 'SELECT': $result_value = intval($statement); $this->current_row[$result_value] = -1; if ($limit > 0) { $this->limits[$result_value] = array($first, $limit, 0); } $this->highest_fetched_row[$result_value] = -1; break; default: $this->affected_rows = @OCIRowCount($statement); @OCIFreeCursor($statement); break; } $result = $statement; } } else { return $this->oci8RaiseError($statement, 'Do query: Could not execute query'); } } } else { return $this->oci8RaiseError(NULL, 'Do query: Could not parse query'); } } for (reset($descriptors), $descriptor = 0; $descriptor < count($descriptors); $descriptor++, next($descriptors)) { @OCIFreeDesc($descriptors[key($descriptors)]); } return $result; }
function rollback() { if ($this->autoCommit) { $this->halt("Nothing to rollback because AUTO COMMIT is on."); } return OCIRollback($this->Link_ID); }
/** * Execute a query * @param string $query the SQL query * @return mixed result identifier if query executed, else MDB2_error * @access private **/ function _doQuery($query, $ismanip = null, $prepared_query = 0) { $lobs = 0; $success = MDB2_OK; $result = 0; $descriptors = array(); if ($prepared_query) { $columns = ''; $variables = ''; for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) { $clob_stream = key($this->clobs[$prepared_query]); $descriptors[$clob_stream] = @OCINewDescriptor($this->connection, OCI_D_LOB); if (!is_object($descriptors[$clob_stream])) { $success = $this->raiseError(MDB2_ERROR, null, null, 'Could not create descriptor for clob parameter'); break; } $parameter = $GLOBALS['_MDB2_LOBs'][$clob_stream]->parameter; $columns .= ($lobs == 0 ? ' RETURNING ' : ',') . $this->prepared_queries[$prepared_query - 1]['fields'][$parameter - 1]; $variables .= ($lobs == 0 ? ' INTO ' : ',') . ':clob' . $parameter; ++$lobs; } if (!MDB2::isError($success)) { for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) { $blob_stream = key($this->blobs[$prepared_query]); $descriptors[$blob_stream] = @OCINewDescriptor($this->connection, OCI_D_LOB); if (!is_object($descriptors[$blob_stream])) { $success = $this->raiseError(MDB2_ERROR, null, null, 'Could not create descriptor for blob parameter'); break; } $parameter = $GLOBALS['_MDB2_LOBs'][$blob_stream]->parameter; $columns .= ($lobs == 0 ? ' RETURNING ' : ',') . $this->prepared_queries[$prepared_query - 1]['fields'][$parameter - 1]; $variables .= ($lobs == 0 ? ' INTO ' : ',') . ':blob' . $parameter; ++$lobs; } $query .= $columns . $variables; } } if (!MDB2::isError($success)) { if ($statement = @OCIParse($this->connection, $query)) { if ($lobs) { for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) { $clob_stream = key($this->clobs[$prepared_query]); $parameter = $GLOBALS['_MDB2_LOBs'][$clob_stream]->parameter; if (!OCIBindByName($statement, ':clob' . $parameter, $descriptors[$clob_stream], -1, OCI_B_CLOB)) { $success = $this->raiseError(); break; } } if (!MDB2::isError($success)) { for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) { $blob_stream = key($this->blobs[$prepared_query]); $parameter = $GLOBALS['_MDB2_LOBs'][$blob_stream]->parameter; if (!OCIBindByName($statement, ':blob' . $parameter, $descriptors[$blob_stream], -1, OCI_B_BLOB)) { $success = $this->raiseError(); break; } } } } if (!MDB2::isError($success)) { $mode = $lobs == 0 && $this->auto_commit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT; $result = @OCIExecute($statement, $mode); if ($result) { if ($lobs) { for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) { $clob_stream = key($this->clobs[$prepared_query]); for ($value = ''; !$this->datatype->endOfLOB($clob_stream);) { if ($this->datatype->readLOB($clob_stream, $data, $this->options['lob_buffer_length']) < 0) { $success = $this->raiseError(); break; } $value .= $data; } if (!MDB2::isError($success) && !$descriptors[$clob_stream]->save($value)) { $success = $this->raiseError(); } } if (!MDB2::isError($success)) { for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) { $blob_stream = key($this->blobs[$prepared_query]); for ($value = ''; !$this->datatype->endOfLOB($blob_stream);) { if ($this->datatype->readLOB($blob_stream, $data, $this->options['lob_buffer_length']) < 0) { $success = $this->raiseError(); break; } $value .= $data; } if (!MDB2::isError($success) && !$descriptors[$blob_stream]->save($value)) { $success = $this->raiseError(); } } } } if ($this->auto_commit) { if ($lobs) { if (MDB2::isError($success)) { if (!OCIRollback($this->connection)) { $success = $this->raiseError(); } } else { if (!OCICommit($this->connection)) { $success = $this->raiseError(); } } } } else { ++$this->uncommitedqueries; } if (!MDB2::isError($success)) { if (is_null($ismanip)) { $ismanip = MDB2::isManip($query); } if ($ismanip) { $this->affected_rows = @OCIRowCount($statement); @OCIFreeCursor($statement); } $result = $statement; } } else { return $this->raiseError($statement); } } } else { return $this->raiseError(); } } for (reset($descriptors), $descriptor = 0; $descriptor < count($descriptors); $descriptor++, next($descriptors)) { @$descriptors[key($descriptors)]->free(); } if (MDB2::isError($success)) { return $success; } return $result; }
function RollbackTransaction() { $this->Debug("Rollback Transaction"); if ($this->auto_commit) { return $this->SetError("Rollback transaction", "transactions can not be rolled back when changes are auto commited"); } if ($this->uncommitedqueries) { if (!OCIRollback($this->connection)) { return $this->SetOCIError("Rollback transaction", "Could not rollback pending transaction", OCIError()); } $this->uncommitedqueries = 0; } return 1; }
function db_trans_rollback($connection) { global $DatabaseType; if ($DatabaseType == 'oracle') { OCIRollback($connection); } elseif ($DatabaseType == 'postgres') { pg_query($connection, "ROLLBACK"); } }
function Rollback() { $this->DoConnect(); OCIRollback($this->db_Conn); $this->transaction = OCI_COMMIT_ON_SUCCESS; }
function sql_query($query = "", $transaction = FALSE) { // Remove any pre-existing queries unset($this->query_result); // Put us in transaction mode because with Oracle as soon as you make a query you're in a transaction $this->in_transaction = TRUE; if ($query != "") { $this->last_query = $query; $this->num_queries++; if (eregi("LIMIT", $query)) { preg_match("/^(.*)LIMIT ([0-9]+)[, ]*([0-9]+)*/s", $query, $limits); $query = $limits[1]; if ($limits[3]) { $row_offset = $limits[2]; $num_rows = $limits[3]; } else { $row_offset = 0; $num_rows = $limits[2]; } } if (eregi("^(INSERT|UPDATE) ", $query)) { $query = preg_replace("/\\\\'/s", "''", $query); } $this->query_result = @OCIParse($this->db_connect_id, $query); $success = @OCIExecute($this->query_result, OCI_DEFAULT); } if ($success) { if ($transaction == END_TRANSACTION) { OCICommit($this->db_connect_id); $this->in_transaction = FALSE; } unset($this->row[$this->query_result]); unset($this->rowset[$this->query_result]); $this->last_query_text[$this->query_result] = $query; return $this->query_result; } else { if ($this->in_transaction) { OCIRollback($this->db_connect_id); } return false; } }