diff --git a/lib/Db/PostgreSQL/Result.php b/lib/Db/PostgreSQL/Result.php index 67a7352..2b4d1b6 100644 --- a/lib/Db/PostgreSQL/Result.php +++ b/lib/Db/PostgreSQL/Result.php @@ -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; } diff --git a/tests/cases/Db/BaseResult.php b/tests/cases/Db/BaseResult.php index a43956d..e848f51 100644 --- a/tests/cases/Db/BaseResult.php +++ b/tests/cases/Db/BaseResult.php @@ -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()); + } } diff --git a/tests/cases/Db/PostgreSQL/TestResult.php b/tests/cases/Db/PostgreSQL/TestResult.php index 658228e..9a4413d 100644 --- a/tests/cases/Db/PostgreSQL/TestResult.php +++ b/tests/cases/Db/PostgreSQL/TestResult.php @@ -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); diff --git a/tests/cases/Db/PostgreSQLPDO/TestResult.php b/tests/cases/Db/PostgreSQLPDO/TestResult.php index caddba7..b3d0cb3 100644 --- a/tests/cases/Db/PostgreSQLPDO/TestResult.php +++ b/tests/cases/Db/PostgreSQLPDO/TestResult.php @@ -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);