87 lines
2.3 KiB
PHP
87 lines
2.3 KiB
PHP
<?php defined('SYSPATH') OR die('No direct script access.');
|
|
/**
|
|
* DB2 database result. See [Results](/database/results) for usage and examples.
|
|
*
|
|
* @package Kohana/Database
|
|
* @category Query/Result
|
|
* @author Deon George
|
|
* @copyright (c) 2015 Deon George
|
|
* @license http://dev.leenooks.net/license
|
|
*/
|
|
class Kohana_Database_DB2_Result extends Database_Result {
|
|
|
|
protected $_internal_row = 0;
|
|
|
|
// if we cache queries, we need to preserve our data, otherwise it is lost
|
|
protected $_internal_data = array();
|
|
|
|
public function __construct($result, $sql, $as_object = FALSE, array $params = NULL)
|
|
{
|
|
parent::__construct($result, $sql, $as_object, $params);
|
|
|
|
// Find the number of rows in the result
|
|
$this->_total_rows = db2_num_rows($result);
|
|
}
|
|
|
|
public function __destruct()
|
|
{
|
|
if (is_resource($this->_result))
|
|
{
|
|
db2_free_result($this->_result);
|
|
}
|
|
}
|
|
|
|
public function seek($offset)
|
|
{
|
|
if ($this->offsetExists($offset) AND db2_next_result($this->_result))
|
|
{
|
|
// Set the current row to the offset
|
|
$this->_current_row = $this->_internal_row = $offset;
|
|
|
|
return TRUE;
|
|
}
|
|
else
|
|
{
|
|
return isset($this->_internal_data[$offset+1]);
|
|
}
|
|
}
|
|
|
|
public function current()
|
|
{
|
|
if ($this->_current_row !== $this->_internal_row AND ! $this->seek($this->_current_row))
|
|
return NULL;
|
|
|
|
// Increment internal row for optimization assuming rows are fetched in order
|
|
$this->_internal_row++;
|
|
|
|
if ($this->_as_object === TRUE)
|
|
{
|
|
throw new Kohana_Exception('This configuration is not tested for caching');
|
|
// Return an stdClass
|
|
return db2_fetch_object($this->_result);
|
|
}
|
|
elseif (is_string($this->_as_object))
|
|
{
|
|
throw new Kohana_Exception('This configuration is not tested for caching');
|
|
$o = new $this->_as_object;
|
|
|
|
// Return an object of given class name
|
|
// @todo This doesnt have $this->_loaded = $this->_valid = TRUE;
|
|
return $o->values(db2_fetch_assoc($this->_result));
|
|
}
|
|
else
|
|
{
|
|
// Return an array of the row
|
|
return isset($this->_internal_data[$this->_internal_row])
|
|
? $this->_internal_data[$this->_internal_row]
|
|
: ($this->_internal_data[$this->_internal_row] = db2_fetch_assoc($this->_result));
|
|
}
|
|
}
|
|
|
|
public function rewind() {
|
|
$this->_internal_row = 0;
|
|
|
|
return parent::rewind();
|
|
}
|
|
} // End Database_DB2_Result
|