Рефакторинг

This commit is contained in:
origami11 2017-02-17 15:08:12 +03:00
parent 1b5852cc43
commit 981a1d0f0f
11 changed files with 626 additions and 270 deletions

View file

@ -0,0 +1,97 @@
<?php
require_once 'tools/string.php';
class Database_PDOStatement extends PDOStatement implements IteratorAggregate
{
protected $cursorPos = 0;
public $cache = array();
public $fields;
function getIterator() {
return new Database_StatementIterator($this);
}
protected function __construct() {
}
function rewind() {
$this->cursorPos = 0;
}
public function seek($rownum) {
if ($rownum < 0) {
return false;
}
// PostgreSQL rows start w/ 0, but this works, because we are
// looking to move the position _before_ the next desired position
$this->cursorPos = $rownum;
return true;
}
function valid() {
return true;
}
public function first() {
if($this->cursorPos !== 0) { $this->seek(0); }
return $this->next();
}
function next() {
if ($this->getRecordCount() > $this->cursorPos) {
if (!isset($this->cache[$this->cursorPos])) {
$this->cache[$this->cursorPos] = $this->fetch(PDO::FETCH_ASSOC);
}
$this->fields = $this->cache[$this->cursorPos];
$this->cursorPos++;
return true;
} else {
$this->fields = null;
return false;
}
}
function key() {
return $this->cursorPos;
}
function current() {
return $this->cache[$this->cursorPos];
}
function getRow() {
return $this->fields;
}
function getInt($name) {
return intval($this->fields[$name]);
}
function getBlob($name) {
return $this->fields[$name];
}
function getString($name) {
return $this->fields[$name];
}
function getBoolean($name) {
return (bool)$this->fields[$name];
}
function get($name) {
return $this->fields[$name];
}
function getArray($name) {
return strToArray($this->fields[$name]);
}
function getRecordCount() {
return count($this->cache);
}
}