2018-12-14 00:47:51 +00:00
|
|
|
<?php
|
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\Arsse\Db\PostgreSQL;
|
|
|
|
|
|
|
|
class Result extends \JKingWeb\Arsse\Db\AbstractResult {
|
|
|
|
protected $db;
|
|
|
|
protected $r;
|
|
|
|
protected $cur;
|
2020-11-03 22:52:20 +00:00
|
|
|
protected $blobs = [];
|
2018-12-14 00:47:51 +00:00
|
|
|
|
|
|
|
// actual public methods
|
|
|
|
|
|
|
|
public function changes(): int {
|
|
|
|
return pg_affected_rows($this->r);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function lastId(): int {
|
|
|
|
if ($r = @pg_query($this->db, "SELECT lastval()")) {
|
|
|
|
return (int) pg_fetch_result($r, 0, 0);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// constructor/destructor
|
|
|
|
|
|
|
|
public function __construct($db, $result) {
|
|
|
|
$this->db = $db;
|
|
|
|
$this->r = $result;
|
2020-11-03 22:52:20 +00:00
|
|
|
for ($a = 0, $stop = pg_num_fields($result); $a < $stop; $a++) {
|
|
|
|
if (pg_field_type($result, $a) === "bytea") {
|
|
|
|
$this->blobs[$a] = pg_field_name($result, $a);
|
|
|
|
}
|
|
|
|
}
|
2018-12-14 00:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function __destruct() {
|
|
|
|
pg_free_result($this->r);
|
|
|
|
unset($this->r, $this->db);
|
|
|
|
}
|
|
|
|
|
|
|
|
// PHP iterator methods
|
|
|
|
|
|
|
|
public function valid() {
|
|
|
|
$this->cur = pg_fetch_row($this->r, null, \PGSQL_ASSOC);
|
2020-11-03 22:52:20 +00:00
|
|
|
if ($this->cur !== false) {
|
|
|
|
foreach($this->blobs as $f) {
|
2020-11-09 21:49:42 +00:00
|
|
|
if ($this->cur[$f]) {
|
|
|
|
$this->cur[$f] = hex2bin(substr($this->cur[$f], 2));
|
|
|
|
}
|
2020-11-03 22:52:20 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2018-12-14 00:47:51 +00:00
|
|
|
}
|
|
|
|
}
|