Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions src/Column/BinaryColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
3 changes: 1 addition & 2 deletions tests/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

use function iterator_to_array;
use function str_repeat;
use function stream_get_contents;

/**
* @group pgsql
Expand Down Expand Up @@ -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']);
Expand Down
1 change: 1 addition & 0 deletions tests/Provider/QueryBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']";

Expand Down