protected function _execute($sql) { $this->stmt_id = FALSE; $this->_set_stmt_id($sql); oci_set_prefetch($this->stmt_id, 1000); return @oci_execute($this->stmt_id, $this->_commit); }
protected function _prefetch() { if (!$this->need_pager) { if ($total_row_count = $this->stmt->count()) { oci_set_prefetch($this->queryId, $total_row_count); } } else { oci_set_prefetch($this->queryId, $this->limit); } }
public static function oci_set_prefetch($connection, $statement, $rows) { self::checkOCIExtension('oci_set_prefetch'); $result = @oci_set_prefetch($statement, $rows); if ($result === FALSE) { $error = self::oci_error($statement); throw new IllegalStateException(t( 'Could not set number of pre fetched records: %error', array('%error' => t($error['message'])))); } }
/** * @param $query * @param $params * @param $action */ public function execute($query, $action, $params = array()) { $this->stid = oci_parse($this->conn, $query); if ($this->prefetch >= 0) { oci_set_prefetch($this->stid, $this->prefetch); } foreach ($params as $bv) { oci_bind_by_name($this->stid, $bv[0], $bv[1], $bv[2]); } oci_set_action($this->conn, $action); oci_execute($this->stid); }
/** * Execute the query * * @param string $sql an SQL query * @return resource */ protected function _execute($sql) { /* Oracle must parse the query before it is run. All of the actions with * the query are based on the statement id returned by oci_parse(). */ $this->stmt_id = FALSE; $this->_set_stmt_id($sql); oci_set_prefetch($this->stmt_id, 1000); return oci_execute($this->stmt_id, $this->commit_mode); }
function &paged_result(&$conn, $select, $binds, $start_row, $rows_per_page) { $end_row = $start_row + $rows_per_page - 1; $sql = "SELECT * FROM ( SELECT r.*, ROWNUM AS row_number FROM ( {$select} ) r WHERE ROWNUM <= :end_row ) WHERE :start_row <= row_number"; $stmt = oci_parse($conn, $sql); $binds[':start_row'] = $start_row; $binds[':end_row'] = $end_row; foreach ($binds as $handle => $var) { oci_bind_by_name($stmt, $handle, $binds[$handle]); } oci_execute($stmt); oci_set_prefetch($stmt, $rows_per_page); return $stmt; }
/** * Execute the query * * @access protected called by the base class * @param string an SQL query * @return resource */ protected function _execute($sql) { // oracle must parse the query before it is run. All of the actions with // the query are based on the statement id returned by ociparse $this->stmt_id = FALSE; $this->_set_stmt_id($sql); oci_set_prefetch($this->stmt_id, 1000); return @oci_execute($this->stmt_id, $this->_commit); }
function pq($query, $args = array()) { if ($this->debug) { print '<h1 class="debug">Debug: Oracle</h1>'; print SqlFormatter::format($query); print_r($args); } if ($this->stats) { $query = preg_replace('/SELECT /', 'SELECT /*+ gather_plan_statistics */ ', $query, 1); } $stid = oci_parse($this->conn, $query); if (!$stid) { $e = oci_error($this->conn); $this->error('There was an error with Oracle', htmlentities($e['message'])); } oci_set_prefetch($stid, 100); // Get variables for prepared query $arg_count = preg_match_all('/:\\d+/', $query, $mat); for ($i = 0; $i < $arg_count; $i++) { oci_bind_by_name($stid, ':' . ($i + 1), $args[$i]); } // Add a bound variable incase we need it if (strpos($query, ':id') !== false) { oci_bind_by_name($stid, ":id", $this->id, 8); } // Add Explain Plan if requested if ($this->explain) { $exp = oci_parse($this->conn, 'EXPLAIN PLAN FOR ' . $query); $arg_count = preg_match_all('/:\\d+/', $query, $mat); $r = oci_execute($exp); oci_free_statement($exp); $plan = oci_parse($this->conn, 'SELECT * FROM TABLE(dbms_xplan.display)'); $pl = oci_execute($plan); $this->plan .= "{$query}\n" . implode(', ', $args) . "\n"; while ($row = oci_fetch_array($plan, OCI_ASSOC + OCI_RETURN_NULLS)) { $this->plan .= $row['PLAN_TABLE_OUTPUT'] . "\n"; } oci_free_statement($plan); } // Perform the logic of the query $r = oci_execute($stid); if (!$r) { $e = oci_error($stid); //trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); $this->error('There was an error with Oracle', htmlentities($e['message'])); } $data = array(); if (strpos($query, 'SELECT') !== false) { while ($row = oci_fetch_array($stid, OCI_ASSOC + OCI_RETURN_NULLS)) { #array_push($data, json_decode(json_encode($row), FALSE)); array_push($data, $row); } } oci_free_statement($stid); if ($this->stats) { $stat = oci_parse($this->conn, "select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST'))"); $pl = oci_execute($stat); $this->stat .= "{$query}\n" . implode(', ', $args) . "\n"; while ($row = oci_fetch_array($stat, OCI_ASSOC + OCI_RETURN_NULLS)) { $this->stat .= $row['PLAN_TABLE_OUTPUT'] . "\n"; } oci_free_statement($stat); } return sizeof($data) == 0 ? array() : $data; }
/** * returns query ID if successful, otherwise false * this version supports: * * 1. $db->execute('select * from table'); * * 2. $db->prepare('insert into table (a,b,c) values (:0,:1,:2)'); * $db->execute($prepared_statement, array(1,2,3)); * * 3. $db->execute('insert into table (a,b,c) values (:a,:b,:c)',array('a'=>1,'b'=>2,'c'=>3)); * * 4. $db->prepare('insert into table (a,b,c) values (:0,:1,:2)'); * $db->bind($stmt,1); $db->bind($stmt,2); $db->bind($stmt,3); * $db->execute($stmt); */ function _query($sql, $inputarr = false) { if (is_array($sql)) { // is prepared sql $stmt = $sql[1]; // we try to bind to permanent array, so that oci_bind_by_name is persistent // and carried out once only - note that max array element size is 4000 chars if (is_array($inputarr)) { $bindpos = $sql[3]; if (isset($this->_bind[$bindpos])) { // all tied up already $bindarr = $this->_bind[$bindpos]; } else { // one statement to bind them all $bindarr = array(); foreach ($inputarr as $k => $v) { $bindarr[$k] = $v; oci_bind_by_name($stmt, ":{$k}", $bindarr[$k], is_string($v) && strlen($v) > 4000 ? -1 : 4000); } $this->_bind[$bindpos] = $bindarr; } } } else { $stmt = oci_parse($this->_connectionID, $sql); } $this->_stmt = $stmt; if (!$stmt) { return false; } if (defined('ADODB_PREFETCH_ROWS')) { @oci_set_prefetch($stmt, ADODB_PREFETCH_ROWS); } if (is_array($inputarr)) { foreach ($inputarr as $k => $v) { if (is_array($v)) { // suggested by g.giunta@libero. if (sizeof($v) == 2) { oci_bind_by_name($stmt, ":{$k}", $inputarr[$k][0], $v[1]); } else { oci_bind_by_name($stmt, ":{$k}", $inputarr[$k][0], $v[1], $v[2]); } if ($this->debug == 99) { if (is_object($v[0])) { echo "name=:{$k}", ' len=' . $v[1], ' type=' . $v[2], '<br>'; } else { echo "name=:{$k}", ' var=' . $inputarr[$k][0], ' len=' . $v[1], ' type=' . $v[2], '<br>'; } } } else { $len = -1; if ($v === ' ') { $len = 1; } if (isset($bindarr)) { // is prepared sql, so no need to oci_bind_by_name again $bindarr[$k] = $v; } else { // dynamic sql, so rebind every time oci_bind_by_name($stmt, ":{$k}", $inputarr[$k], $len); } } } } $this->_errorMsg = false; $this->_errorCode = false; if (oci_execute($stmt, $this->_commit)) { if (count($this->_refLOBs) > 0) { foreach ($this->_refLOBs as $key => $value) { if ($this->_refLOBs[$key]['TYPE'] == true) { $tmp = $this->_refLOBs[$key]['LOB']->load(); if ($this->debug) { ADOConnection::outp("<b>OUT LOB</b>: LOB has been loaded. <br>"); } //$_GLOBALS[$this -> _refLOBs[$key]['VAR']] = $tmp; $this->_refLOBs[$key]['VAR'] = $tmp; } else { $this->_refLOBs[$key]['LOB']->save($this->_refLOBs[$key]['VAR']); $this->_refLOBs[$key]['LOB']->free(); unset($this->_refLOBs[$key]); if ($this->debug) { ADOConnection::outp("<b>IN LOB</b>: LOB has been saved. <br>"); } } } } switch (@oci_statement_type($stmt)) { case "SELECT": return $stmt; case 'DECLARE': case "BEGIN": if (is_array($sql) && !empty($sql[4])) { $cursor = $sql[4]; if (is_resource($cursor)) { $ok = oci_execute($cursor); return $cursor; } return $stmt; } else { if (is_resource($stmt)) { oci_free_statement($stmt); return true; } return $stmt; } break; default: return true; } } return false; }
protected function _execute() { if (!@oci_execute($this->_result, $this->_driver->autocommit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT)) { $this->_set_stmt_error(null, PDO::ERRMODE_SILENT, 'execute'); return false; } foreach ($this->lobs as $k => &$v) { $lob =& $v[0]; $data =& $v[1]; if (is_resource($data)) { while (!feof($data)) { $lob->write(fread($data, 8192)); } } else { $lob->write($data); } } if (0 < ($rows = $this->getAttribute(PDO::ATTR_PREFETCH))) { oci_set_prefetch($this->_result, $rows); } return true; }
public function SepPrefetch(int $rows) { return oci_set_prefetch($this->conn_handle, $rows); }
/** * Executes given SQL statement. This is an overloaded method. * * @param string $sql SQL statement * @return resource Result resource identifier or null * @access protected */ function _execute($sql, $params = array(), $prepareOptions = array()) { if (!$this->connection) { $this->_statementId = false; return false; } $this->_statementId = oci_parse($this->connection, $sql); if (!$this->_statementId) { $this->_setError($this->connection); return false; } if ($this->__transactionStarted) { $mode = OCI_DEFAULT; } else { $mode = OCI_COMMIT_ON_SUCCESS; } if (!oci_execute($this->_statementId, $mode)) { $this->_setError($this->_statementId); error_log($sql); return false; } $this->_setError(null, true); switch (oci_statement_type($this->_statementId)) { case 'DESCRIBE': case 'SELECT': $this->_scrapeSQL($sql); break; default: return $this->_statementId; } if ($this->_limit >= 1) { oci_set_prefetch($this->_statementId, $this->_limit); } else { oci_set_prefetch($this->_statementId, 3000); } $this->_numRows = oci_fetch_all($this->_statementId, $this->_results, $this->_offset, $this->_limit, OCI_NUM | OCI_FETCHSTATEMENT_BY_ROW); $this->_currentRow = 0; $this->limit(); return $this->_statementId; }
public function setPrefetch($rows) { set_error_handler(static::getErrorHandler()); $isSuccess = oci_set_prefetch($this->resource, $rows); restore_error_handler(); return $isSuccess; }
public function query($query, array $bindVariables = null) { $statment = null; if (!array_key_exists($query, $this->_statementCache) && is_array($bindVariables)) { // To keep memory constraints down, only cache those statements which can be used // with bind variables. $this->_statementCache[$query] = oci_parse($this->getConnection(), $query); $statement = $this->_statementCache[$query]; if (count($bindVariables) > 0) { foreach ($bindVariables as $bindName => $variable) { oci_bind_by_name($statment, $bindName, $variable); } } } else { $statement = oci_parse($this->getConnection(), $query); } oci_set_prefetch($statement, $this->getPrefetch()); oci_execute($statement); if (!preg_match('/^\\s*select/i', $query)) { $this->commit(); } return $statement; }