1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 13:12:41 +00:00

Fix handling of bytea-typed nulls

This commit is contained in:
J. King 2020-11-09 16:49:42 -05:00
parent 1b1789988a
commit 576d7e16a8
4 changed files with 17 additions and 1 deletions

View file

@ -49,7 +49,9 @@ class Result extends \JKingWeb\Arsse\Db\AbstractResult {
$this->cur = pg_fetch_row($this->r, null, \PGSQL_ASSOC);
if ($this->cur !== false) {
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;
}

View file

@ -11,6 +11,7 @@ use JKingWeb\Arsse\Db\Result;
abstract class BaseResult extends \JKingWeb\Arsse\Test\AbstractTest {
protected static $insertDefault = "INSERT INTO arsse_test default values";
protected static $selectBlob = "SELECT x'DEADBEEF' as \"blob\"";
protected static $selectNullBlob = "SELECT null as \"blob\"";
protected static $interface;
protected $resultClass;
@ -142,4 +143,15 @@ abstract class BaseResult extends \JKingWeb\Arsse\Test\AbstractTest {
$test = new $this->resultClass(...$this->makeResult(static::$selectBlob));
$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());
}
}

View file

@ -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 $createTest = "CREATE TABLE arsse_test(id bigserial primary key)";
protected static $selectBlob = "SELECT '\\xDEADBEEF'::bytea as blob";
protected static $selectNullBlob = "SELECT null::bytea as blob";
protected function makeResult(string $q): array {
$set = pg_query(static::$interface, $q);

View file

@ -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 $createTest = "CREATE TABLE arsse_test(id bigserial primary key)";
protected static $selectBlob = "SELECT '\\xDEADBEEF'::bytea as blob";
protected static $selectNullBlob = "SELECT null::bytea as blob";
protected function makeResult(string $q): array {
$set = static::$interface->query($q);