* @package Mammut\DB\Adapter\Oracle */ class Result extends \Mammut\DB\Result { /** * * @var resource */ private $result; private $rownum = 0; public function __construct($result) { $this->result = $result; } public function getFields() { throw new ImplementationException('not implemented'); } public function getFieldTypes() { throw new ImplementationException('not implemented'); } public function position() { return $this->rownum; } public function seek() { throw new ImplementationException('not implemented'); } /** * Converts values returned by oracle to PHP types * @param array $arr the value array * @param ressource $result the select ressource */ public static function fixValues(&$arr, $result) { foreach($arr as $k=>&$v) { $type = oci_field_type($result, $k); if ($type == 'NUMBER') { if (strpos($v,'.') === false) settype($v,'int'); else settype($v,'float'); } } } public function fetchRow() { $this->rownum++; $result = oci_fetch_row($this->result); $this->fixValues($result, $this->result); if(!empty($result)) $this->rownum++; return $result; } public function fetchArray() { $this->rownum++; $result = oci_fetch_assoc($this->result); $this->fixValues($result, $this->result); if(!empty($result)) $this->rownum++; return $result; } public function fetchObject($class = false, $param = array()) { if($class) { $ref = new \ReflectionClass($class); $obj = $ref->newInstanceArgs($param); unset($ref); } else $obj = new \stdClass(); $data = oci_fetch_assoc($this->result); if(empty($data)) return NULL; $this->fixValues($data, $this->result); foreach($data as $k=>$v) $obj->$k = $v; $this->rownum++; return $obj; } public function getRowCount() { return oci_num_rows($this->result); } public function getRowNumber() { return $this->rownum; } public function getColumns() { throw new ImplementationException('not implemented'); } public function getColumnInfo($column) { throw new ImplementationException('not implemented'); } public function close() { oci_free_statement($this->result); } }