Skip to content

Commit

Permalink
- reset row_limit and row_offset after calling prepare() just like we…
Browse files Browse the repository at this point in the history
… do for query() and exec()

- rewrite queries for limit/offset (taken from ezc) instead of emulating


git-svn-id: http://svn.php.net/repository/pear/packages/MDB2/trunk@205387 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Lukas Smith committed Jan 16, 2006
1 parent 6720f3a commit 7a78c14
Showing 1 changed file with 18 additions and 50 deletions.
68 changes: 18 additions & 50 deletions MDB2/Driver/oci8.php
Expand Up @@ -79,7 +79,7 @@ function __construct()
$this->supported['current_id'] = true;
$this->supported['affected_rows'] = true;
$this->supported['transactions'] = true;
$this->supported['limit_queries'] = 'emulated';
$this->supported['limit_queries'] = true;
$this->supported['LOBs'] = true;
$this->supported['replace'] = 'emulated';
$this->supported['sub_selects'] = true;
Expand Down Expand Up @@ -458,13 +458,18 @@ function &standaloneQuery($query, $types = null, $is_manip = false)
* @return the new (modified) query
* @access protected
*/
function _modifyQuery($query)
function _modifyQuery($query, $is_manip, $limit, $offset)
{
// "SELECT 2+2" must be "SELECT 2+2 FROM dual" in Oracle
if (preg_match('/^\s*SELECT/i', $query)
&& !preg_match('/\sFROM\s/i', $query)
) {
$query.= " FROM dual";
if (preg_match('/^\s*SELECT/i', $query)) {
if (!preg_match('/\sFROM\s/i', $query)) {
$query.= " FROM dual";
}
if ($limit > 0) {
// taken from http://svn.ez.no/svn/ezcomponents/packages/Database
$min = $offset + 1;
$max = $offset + $limit;
$query = "SELECT * FROM (SELECT a.*, ROWNUM rn FROM ($query) a WHERE ROWNUM <= $max) WHERE rn >= $min";
}
}
return $query;
}
Expand Down Expand Up @@ -594,8 +599,11 @@ function getServerVersion($native = false)
function &prepare($query, $types = null, $result_types = null, $lobs = array())
{
$is_manip = ($result_types === MDB2_PREPARE_MANIP);
$offset = $this->row_offset;
$limit = $this->row_limit;
$this->row_offset = $this->row_limit = 0;
$this->debug($query, 'prepare');
$query = $this->_modifyQuery($query);
$query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
$placeholder_type_guess = $placeholder_type = null;
$question = '?';
$colon = ':';
Expand Down Expand Up @@ -713,7 +721,7 @@ function &prepare($query, $types = null, $result_types = null, $lobs = array())
}

$class_name = 'MDB2_Statement_'.$this->phptype;
$obj =& new $class_name($this, $statement, $positions, $query, $types, $result_types, $is_manip, $this->row_limit, $this->row_offset);
$obj =& new $class_name($this, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
return $obj;
}

Expand Down Expand Up @@ -769,34 +777,6 @@ function currId($seq_name)

class MDB2_Result_oci8 extends MDB2_Result_Common
{
// {{{ _skipLimitOffset()

/**
* Skip the first row of a result set.
*
* @param resource $result
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access protected
*/
function _skipLimitOffset()
{
if ($this->limit) {
if ($this->rownum > $this->limit) {
return false;
}
}
if ($this->offset) {
while ($this->offset_count < $this->offset) {
++$this->offset_count;
if (!@OCIFetchInto($this->result, $row, OCI_RETURN_NULLS)) {
$this->offset_count = $this->offset;
return false;
}
}
}
return true;
}

// }}}
// {{{ fetchRow()

Expand All @@ -810,10 +790,6 @@ function _skipLimitOffset()
*/
function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
{
if (!$this->_skipLimitOffset()) {
$null = null;
return $null;
}
if (!is_null($rownum)) {
$seek = $this->seek($rownum);
if (PEAR::isError($seek)) {
Expand Down Expand Up @@ -968,13 +944,8 @@ function _fillBuffer($rownum = null)
}
}

if (!$this->_skipLimitOffset()) {
return false;
}

$row = true;
while ((is_null($rownum) || $this->buffer_rownum < $rownum)
&& (!$this->limit || $this->buffer_rownum < $this->limit)
&& ($row = @OCIFetchInto($this->result, $buffer, OCI_RETURN_NULLS))
) {
++$this->buffer_rownum;
Expand All @@ -985,9 +956,6 @@ function _fillBuffer($rownum = null)
++$this->buffer_rownum;
$this->buffer[$this->buffer_rownum] = false;
return false;
} elseif ($this->limit && $this->buffer_rownum >= $this->limit) {
++$this->buffer_rownum;
$this->buffer[$this->buffer_rownum] = false;
}
return true;
}
Expand Down Expand Up @@ -1257,7 +1225,7 @@ function &_execute($result_class = true, $result_wrap_class = false)
}

$result =& $this->db->_wrapResult($this->statement, $this->result_types,
$result_class, $result_wrap_class, $this->row_limit, $this->row_offset);
$result_class, $result_wrap_class);
return $result;
}

Expand Down

0 comments on commit 7a78c14

Please sign in to comment.