diff --git a/CHANGELOG.md b/CHANGELOG.md index af9086ebc..b8490e25c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - Chg #416: Use `\InvalidArgumentException` instead of `Yiisoft\Db\Exception\InvalidArgumentException` (@DikoIbragimov) - Enh #336, #405: Implement and use `SqlParser` class (@Tigrov) -- New #315: Implement `ColumnSchemaInterface` classes according to the data type of database table columns +- New #315, #432: Implement `ColumnInterface` classes according to the data type of database table columns for type casting performance. Related with yiisoft/db#752 (@Tigrov) - Chg #348: Replace call of `SchemaInterface::getRawTableName()` to `QuoterInterface::getRawTableName()` (@Tigrov) - Enh #349: Add method chaining for column classes (@Tigrov) diff --git a/src/Column/BinaryColumn.php b/src/Column/BinaryColumn.php index f546f933a..046817343 100644 --- a/src/Column/BinaryColumn.php +++ b/src/Column/BinaryColumn.php @@ -5,6 +5,7 @@ namespace Yiisoft\Db\Pgsql\Column; use Yiisoft\Db\Schema\Column\BinaryColumn as BaseBinaryColumn; +use Yiisoft\Db\Schema\Data\StringableStream; use function hex2bin; use function is_string; @@ -13,12 +14,13 @@ final class BinaryColumn extends BaseBinaryColumn { - public function phpTypecast(mixed $value): mixed + public function phpTypecast(mixed $value): StringableStream|string|null { if (is_string($value) && str_starts_with($value, '\x')) { + /** @var string */ return hex2bin(substr($value, 2)); } - return $value; + return parent::phpTypecast($value); } } diff --git a/tests/ColumnTest.php b/tests/ColumnTest.php index f97d43a00..d625bab6e 100644 --- a/tests/ColumnTest.php +++ b/tests/ColumnTest.php @@ -32,7 +32,6 @@ use function iterator_to_array; use function str_repeat; -use function stream_get_contents; /** * @group pgsql @@ -75,7 +74,7 @@ protected function assertTypecastedValues(array $result, bool $allTypecasted = f $this->assertSame(1, $result['int_col']); $this->assertSame(str_repeat('x', 100), $result['char_col']); $this->assertSame(1.234, $result['float_col']); - $this->assertSame("\x10\x11\x12", stream_get_contents($result['blob_col'])); + $this->assertSame("\x10\x11\x12", (string) $result['blob_col']); $this->assertEquals(new DateTimeImmutable('2023-07-11 14:50:23', new DateTimeZone('UTC')), $result['timestamp_col']); $this->assertEquals(new DateTimeImmutable('2023-07-11 14:50:23'), $result['timestamp_default']); $this->assertFalse($result['bool_col']); diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 87276b065..d58280bb3 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -507,6 +507,7 @@ public static function prepareValue(): array $values['binary'][0] = "'\\x737472696e67'::bytea"; $values['paramBinary'][0] = "'\\x737472696e67'::bytea"; $values['paramResource'][0] = "'\\x737472696e67'::bytea"; + $values['ResourceStream'][0] = "'\\x737472696e67'::bytea"; $values['array'][0] = "ARRAY['a','b','c']"; $values['Iterator'][0] = "ARRAY['a','b','c']";