Browse Source
Most of the SQLite3 Result class' methods are fully generic, so it should be helpful for future result setsmicrosub
J. King
7 years ago
2 changed files with 57 additions and 38 deletions
@ -0,0 +1,55 @@ |
|||||
|
<?php |
||||
|
declare(strict_types=1); |
||||
|
namespace JKingWeb\Arsse\Db; |
||||
|
|
||||
|
abstract class AbstractResult implements Result { |
||||
|
protected $pos = 0; |
||||
|
protected $cur = null; |
||||
|
|
||||
|
// actual public methods |
||||
|
|
||||
|
public function getValue() { |
||||
|
$this->next(); |
||||
|
if ($this->valid()) { |
||||
|
$keys = array_keys($this->cur); |
||||
|
return $this->cur[array_shift($keys)]; |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
public function getRow() { |
||||
|
$this->next(); |
||||
|
return ($this->valid() ? $this->cur : null); |
||||
|
} |
||||
|
|
||||
|
public function getAll(): array { |
||||
|
return iterator_to_array($this, false); |
||||
|
} |
||||
|
|
||||
|
abstract public function changes(); |
||||
|
|
||||
|
abstract public function lastId(); |
||||
|
|
||||
|
// PHP iterator methods |
||||
|
|
||||
|
abstract public function valid(); |
||||
|
|
||||
|
public function next() { |
||||
|
$this->cur = null; |
||||
|
$this->pos += 1; |
||||
|
} |
||||
|
|
||||
|
public function current() { |
||||
|
return $this->cur; |
||||
|
} |
||||
|
|
||||
|
public function key() { |
||||
|
return $this->pos; |
||||
|
} |
||||
|
|
||||
|
public function rewind() { |
||||
|
if ($this->pos) { |
||||
|
throw new Exception("resultReused"); |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue