mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-31 21:12:41 +00:00
Fix handling of bytea-typed nulls
This commit is contained in:
parent
1b1789988a
commit
576d7e16a8
4 changed files with 17 additions and 1 deletions
|
@ -49,7 +49,9 @@ class Result extends \JKingWeb\Arsse\Db\AbstractResult {
|
||||||
$this->cur = pg_fetch_row($this->r, null, \PGSQL_ASSOC);
|
$this->cur = pg_fetch_row($this->r, null, \PGSQL_ASSOC);
|
||||||
if ($this->cur !== false) {
|
if ($this->cur !== false) {
|
||||||
foreach($this->blobs as $f) {
|
foreach($this->blobs as $f) {
|
||||||
$this->cur[$f] = hex2bin(substr($this->cur[$f], 2));
|
if ($this->cur[$f]) {
|
||||||
|
$this->cur[$f] = hex2bin(substr($this->cur[$f], 2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ use JKingWeb\Arsse\Db\Result;
|
||||||
abstract class BaseResult extends \JKingWeb\Arsse\Test\AbstractTest {
|
abstract class BaseResult extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
protected static $insertDefault = "INSERT INTO arsse_test default values";
|
protected static $insertDefault = "INSERT INTO arsse_test default values";
|
||||||
protected static $selectBlob = "SELECT x'DEADBEEF' as \"blob\"";
|
protected static $selectBlob = "SELECT x'DEADBEEF' as \"blob\"";
|
||||||
|
protected static $selectNullBlob = "SELECT null as \"blob\"";
|
||||||
protected static $interface;
|
protected static $interface;
|
||||||
protected $resultClass;
|
protected $resultClass;
|
||||||
|
|
||||||
|
@ -142,4 +143,15 @@ abstract class BaseResult extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
$test = new $this->resultClass(...$this->makeResult(static::$selectBlob));
|
$test = new $this->resultClass(...$this->makeResult(static::$selectBlob));
|
||||||
$this->assertEquals($exp, $test->getValue());
|
$this->assertEquals($exp, $test->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetNullBlobRow(): void {
|
||||||
|
$exp = ['blob' => null];
|
||||||
|
$test = new $this->resultClass(...$this->makeResult(static::$selectNullBlob));
|
||||||
|
$this->assertEquals($exp, $test->getRow());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetNullBlobValue(): void {
|
||||||
|
$test = new $this->resultClass(...$this->makeResult(static::$selectNullBlob));
|
||||||
|
$this->assertNull($test->getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ class TestResult extends \JKingWeb\Arsse\TestCase\Db\BaseResult {
|
||||||
protected static $createMeta = "CREATE TABLE arsse_meta(key text primary key not null, value text)";
|
protected static $createMeta = "CREATE TABLE arsse_meta(key text primary key not null, value text)";
|
||||||
protected static $createTest = "CREATE TABLE arsse_test(id bigserial primary key)";
|
protected static $createTest = "CREATE TABLE arsse_test(id bigserial primary key)";
|
||||||
protected static $selectBlob = "SELECT '\\xDEADBEEF'::bytea as blob";
|
protected static $selectBlob = "SELECT '\\xDEADBEEF'::bytea as blob";
|
||||||
|
protected static $selectNullBlob = "SELECT null::bytea as blob";
|
||||||
|
|
||||||
protected function makeResult(string $q): array {
|
protected function makeResult(string $q): array {
|
||||||
$set = pg_query(static::$interface, $q);
|
$set = pg_query(static::$interface, $q);
|
||||||
|
|
|
@ -16,6 +16,7 @@ class TestResult extends \JKingWeb\Arsse\TestCase\Db\BaseResult {
|
||||||
protected static $createMeta = "CREATE TABLE arsse_meta(key text primary key not null, value text)";
|
protected static $createMeta = "CREATE TABLE arsse_meta(key text primary key not null, value text)";
|
||||||
protected static $createTest = "CREATE TABLE arsse_test(id bigserial primary key)";
|
protected static $createTest = "CREATE TABLE arsse_test(id bigserial primary key)";
|
||||||
protected static $selectBlob = "SELECT '\\xDEADBEEF'::bytea as blob";
|
protected static $selectBlob = "SELECT '\\xDEADBEEF'::bytea as blob";
|
||||||
|
protected static $selectNullBlob = "SELECT null::bytea as blob";
|
||||||
|
|
||||||
protected function makeResult(string $q): array {
|
protected function makeResult(string $q): array {
|
||||||
$set = static::$interface->query($q);
|
$set = static::$interface->query($q);
|
||||||
|
|
Loading…
Reference in a new issue