Browse Source

Fix handling of bytea-typed nulls

rpm
J. King 3 years ago
parent
commit
576d7e16a8
  1. 4
      lib/Db/PostgreSQL/Result.php
  2. 12
      tests/cases/Db/BaseResult.php
  3. 1
      tests/cases/Db/PostgreSQL/TestResult.php
  4. 1
      tests/cases/Db/PostgreSQLPDO/TestResult.php

4
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;
}

12
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());
}
}

1
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);

1
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);

Loading…
Cancel
Save