From 0a106f0179b9effed61cc1f3ed3bfe112ef51d42 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 1 Sep 2023 18:44:54 +0700 Subject: [PATCH 1/8] Column type classes --- src/BinaryColumnSchema.php | 53 ++++++++++++++++++++++++++++++++++++++ src/ColumnSchema.php | 8 ++++++ src/Schema.php | 53 +++++++++++++++++++++++++------------- tests/ColumnSchemaTest.php | 48 ++++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+), 18 deletions(-) create mode 100644 src/BinaryColumnSchema.php diff --git a/src/BinaryColumnSchema.php b/src/BinaryColumnSchema.php new file mode 100644 index 00000000..db0aced5 --- /dev/null +++ b/src/BinaryColumnSchema.php @@ -0,0 +1,53 @@ +type(SchemaInterface::TYPE_BINARY); + $this->phpType(SchemaInterface::PHP_TYPE_RESOURCE); + } + + public function dbTypecast(mixed $value): mixed + { + if ($this->getDbType() === 'BLOB') { + if ($value instanceof ParamInterface && is_string($value->getValue())) { + /** @psalm-var string */ + $value = $value->getValue(); + } + + if (is_string($value)) { + $placeholder = uniqid('exp_' . preg_replace('/[^a-z0-9]/i', '', $this->getName())); + return new Expression('TO_BLOB(UTL_RAW.CAST_TO_RAW(:' . $placeholder . '))', [$placeholder => $value]); + } + } + + return match (true) { + is_string($value) => new Param($value, PDO::PARAM_LOB), + $value === null, is_resource($value), $value instanceof ExpressionInterface => $value, + /** ensure type cast always has . as decimal separator in all locales */ + is_float($value) => DbStringHelper::normalizeFloat($value), + $value === false => '0', + default => (string) $value, + }; + } +} diff --git a/src/ColumnSchema.php b/src/ColumnSchema.php index 6768c494..9b0d76ac 100644 --- a/src/ColumnSchema.php +++ b/src/ColumnSchema.php @@ -14,6 +14,10 @@ use function uniqid; /** + * @deprecated Use the following class for specific type: + * `StringColumnSchema`, `IntegerColumnSchema`, `BigIntColumnSchema`, `DoubleColumnSchema`, `BooleanColumnSchema`, + * `BinaryColumnSchema` + * * Represents the metadata of a column in a database table for Oracle Server. * * It provides information about the column's name, type, size, precision, and other details. @@ -36,6 +40,9 @@ * $column->autoIncrement(true); * $column->primaryKey(true); * ``` + * + * @psalm-suppress DeprecatedInterface + * @psalm-suppress DeprecatedClass */ final class ColumnSchema extends AbstractColumnSchema { @@ -52,6 +59,7 @@ public function dbTypecast(mixed $value): mixed } } + /** @psalm-suppress DeprecatedClass */ return parent::dbTypecast($value); } } diff --git a/src/Schema.php b/src/Schema.php index c3482be0..16d39f96 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -18,7 +18,7 @@ use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Helper\DbArrayHelper; use Yiisoft\Db\Schema\Builder\ColumnInterface; -use Yiisoft\Db\Schema\ColumnSchemaInterface; +use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use Yiisoft\Db\Schema\TableSchemaInterface; use function array_merge; @@ -369,14 +369,14 @@ protected function findColumns(TableSchemaInterface $table): bool return false; } - /** @psalm-var string[][] $columns */ - foreach ($columns as $column) { - /** @psalm-var ColumnInfoArray $column */ - $column = $this->normalizeRowKeyCase($column, false); + /** @psalm-var ColumnInfoArray $info */ + foreach ($columns as $info) { + /** @psalm-var ColumnInfoArray $info */ + $info = $this->normalizeRowKeyCase($info, false); - $c = $this->createColumnSchema($column); + $column = $this->loadColumnSchema($info); - $table->column($c->getName(), $c); + $table->column($column->getName(), $column); } return true; @@ -411,13 +411,20 @@ protected function getTableSequenceName(string $tableName): bool|float|int|strin } /** - * Creates ColumnSchema instance. + * Loads the column information into a {@see ColumnSchemaInterface} object. * - * @psalm-param ColumnInfoArray $info + * @param array $info The column information. + * + * @return ColumnSchemaInterface The column schema object. + * + * @psalm-param ColumnInfoArray $info The column information. */ - protected function createColumnSchema(array $info): ColumnSchemaInterface + private function loadColumnSchema(array $info): ColumnSchemaInterface { - $column = new ColumnSchema($info['column_name']); + $dbType = $info['data_type']; + $type = $this->extractColumnType($dbType, $info); + /** @psalm-var ColumnInfoArray $info */ + $column = $this->createColumnSchema($type, $info['column_name']); $column->allowNull($info['nullable'] === 'Y'); $column->comment($info['column_comment']); $column->primaryKey((bool) $info['is_pk']); @@ -425,14 +432,22 @@ protected function createColumnSchema(array $info): ColumnSchemaInterface $column->size((int) $info['data_length']); $column->precision($info['data_precision'] !== null ? (int) $info['data_precision'] : null); $column->scale($info['data_scale'] !== null ? (int) $info['data_scale'] : null); - $column->dbType($info['data_type']); - $column->type($this->extractColumnType($column)); - $column->phpType($this->getColumnPhpType($column)); + $column->dbType($dbType); + $column->phpType($this->getColumnPhpType($type)); $column->defaultValue($this->normalizeDefaultValue($info['data_default'], $column)); return $column; } + protected function createPhpTypeColumnSchema(string $phpType, string $name): ColumnSchemaInterface + { + if ($phpType === self::PHP_TYPE_RESOURCE) { + return new BinaryColumnSchema($name); + } + + return parent::createPhpTypeColumnSchema($phpType, $name); + } + /** * Converts column's default value according to {@see ColumnSchema::phpType} after retrieval from the database. * @@ -608,17 +623,19 @@ public function findUniqueIndexes(TableSchemaInterface $table): array /** * Extracts the data type for the given column. * - * @param ColumnSchemaInterface $column The column schema object. + * @param string $dbType The database data type + * @param array $info Column information. + * @psalm-param ColumnInfoArray $info * * @return string The abstract column type. */ - private function extractColumnType(ColumnSchemaInterface $column): string + private function extractColumnType(string $dbType, array $info): string { - $dbType = explode('(', (string) $column->getDbType(), 2)[0]; + $dbType = explode('(', $dbType, 2)[0]; return match ($dbType) { 'FLOAT', 'DOUBLE' => self::TYPE_DOUBLE, - 'NUMBER' => $column->getScale() === null || $column->getScale() > 0 + 'NUMBER' => $info['data_scale'] === null || $info['data_scale'] > 0 ? self::TYPE_DECIMAL : self::TYPE_INTEGER, 'BLOB' => self::TYPE_BINARY, diff --git a/tests/ColumnSchemaTest.php b/tests/ColumnSchemaTest.php index 800794b4..e5e2b85b 100644 --- a/tests/ColumnSchemaTest.php +++ b/tests/ColumnSchemaTest.php @@ -4,11 +4,19 @@ namespace Yiisoft\Db\Oracle\Tests; +use PDO; use PHPUnit\Framework\TestCase; +use Yiisoft\Db\Command\Param; use Yiisoft\Db\Expression\Expression; +use Yiisoft\Db\Oracle\BinaryColumnSchema; use Yiisoft\Db\Oracle\Tests\Support\TestTrait; use Yiisoft\Db\Query\Query; +use Yiisoft\Db\Schema\Column\DoubleColumnSchema; +use Yiisoft\Db\Schema\Column\IntegerColumnSchema; +use Yiisoft\Db\Schema\Column\StringColumnSchema; +use Yiisoft\Db\Schema\SchemaInterface; +use function fopen; use function str_repeat; /** @@ -62,4 +70,44 @@ public function testPhpTypeCast(): void $db->close(); } + + public function testColumnSchemaInstance() + { + $db = $this->getConnection(true); + $schema = $db->getSchema(); + $tableSchema = $schema->getTableSchema('type'); + + $this->assertInstanceOf(IntegerColumnSchema::class, $tableSchema->getColumn('int_col')); + $this->assertInstanceOf(StringColumnSchema::class, $tableSchema->getColumn('char_col')); + $this->assertInstanceOf(DoubleColumnSchema::class, $tableSchema->getColumn('float_col')); + $this->assertInstanceOf(BinaryColumnSchema::class, $tableSchema->getColumn('blob_col')); + } + + public function testBinaryColumnSchema() + { + $binaryCol = new BinaryColumnSchema('binary_col'); + + $this->assertSame('binary_col', $binaryCol->getName()); + $this->assertSame(SchemaInterface::TYPE_BINARY, $binaryCol->getType()); + $this->assertSame(SchemaInterface::PHP_TYPE_RESOURCE, $binaryCol->getPhpType()); + + $this->assertNull($binaryCol->dbTypecast(null)); + $this->assertSame('1', $binaryCol->dbTypecast(1)); + $this->assertSame('1', $binaryCol->dbTypecast(true)); + $this->assertSame('0', $binaryCol->dbTypecast(false)); + $this->assertSame($resource = fopen('php://memory', 'rb'), $binaryCol->dbTypecast($resource)); + $this->assertEquals(new Param("\x10\x11\x12", PDO::PARAM_LOB), $binaryCol->dbTypecast("\x10\x11\x12")); + $this->assertSame($expression = new Expression('expression'), $binaryCol->dbTypecast($expression)); + + $this->assertNull($binaryCol->phpTypecast(null)); + $this->assertSame("\x10\x11\x12", $binaryCol->phpTypecast("\x10\x11\x12")); + $this->assertSame($resource = fopen('php://memory', 'rb'), $binaryCol->phpTypecast($resource)); + + $binaryCol->dbType('BLOB'); + $this->assertInstanceOf(Expression::class, $binaryCol->dbTypecast("\x10\x11\x12")); + $this->assertInstanceOf( + Expression::class, + $binaryCol->dbTypecast(new Param("\x10\x11\x12", PDO::PARAM_LOB)), + ); + } } From 79ab45cdc81cf2cde39369575aaa1d47cc5af2b2 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 1 Sep 2023 18:50:14 +0700 Subject: [PATCH 2/8] Refactor with inheritance --- src/BinaryColumnSchema.php | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/src/BinaryColumnSchema.php b/src/BinaryColumnSchema.php index db0aced5..27544182 100644 --- a/src/BinaryColumnSchema.php +++ b/src/BinaryColumnSchema.php @@ -4,29 +4,14 @@ namespace Yiisoft\Db\Oracle; -use PDO; -use Yiisoft\Db\Command\Param; use Yiisoft\Db\Command\ParamInterface; use Yiisoft\Db\Expression\Expression; -use Yiisoft\Db\Expression\ExpressionInterface; -use Yiisoft\Db\Helper\DbStringHelper; -use Yiisoft\Db\Schema\Column\AbstractColumnSchema; -use Yiisoft\Db\Schema\SchemaInterface; +use Yiisoft\Db\Schema\Column\BinaryColumnSchema as BaseBinaryColumnSchema; -use function is_float; -use function is_resource; use function is_string; -final class BinaryColumnSchema extends AbstractColumnSchema +final class BinaryColumnSchema extends BaseBinaryColumnSchema { - public function __construct(string $name) - { - parent::__construct($name); - - $this->type(SchemaInterface::TYPE_BINARY); - $this->phpType(SchemaInterface::PHP_TYPE_RESOURCE); - } - public function dbTypecast(mixed $value): mixed { if ($this->getDbType() === 'BLOB') { @@ -41,13 +26,6 @@ public function dbTypecast(mixed $value): mixed } } - return match (true) { - is_string($value) => new Param($value, PDO::PARAM_LOB), - $value === null, is_resource($value), $value instanceof ExpressionInterface => $value, - /** ensure type cast always has . as decimal separator in all locales */ - is_float($value) => DbStringHelper::normalizeFloat($value), - $value === false => '0', - default => (string) $value, - }; + return parent::dbTypecast($value); } } From 4508ce60864f5bd6195a16c0c3f75133e8213755 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 1 Sep 2023 18:57:57 +0700 Subject: [PATCH 3/8] Refactor tests --- tests/ColumnSchemaTest.php | 35 +++++++++++-------------- tests/Provider/ColumnSchemaProvider.php | 26 ++++++++++++++++++ 2 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 tests/Provider/ColumnSchemaProvider.php diff --git a/tests/ColumnSchemaTest.php b/tests/ColumnSchemaTest.php index e5e2b85b..9da1b9c9 100644 --- a/tests/ColumnSchemaTest.php +++ b/tests/ColumnSchemaTest.php @@ -5,7 +5,6 @@ namespace Yiisoft\Db\Oracle\Tests; use PDO; -use PHPUnit\Framework\TestCase; use Yiisoft\Db\Command\Param; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Oracle\BinaryColumnSchema; @@ -14,15 +13,14 @@ use Yiisoft\Db\Schema\Column\DoubleColumnSchema; use Yiisoft\Db\Schema\Column\IntegerColumnSchema; use Yiisoft\Db\Schema\Column\StringColumnSchema; -use Yiisoft\Db\Schema\SchemaInterface; +use Yiisoft\Db\Tests\Common\CommonColumnSchemaTest; -use function fopen; use function str_repeat; /** * @group oracle */ -final class ColumnSchemaTest extends TestCase +final class ColumnSchemaTest extends CommonColumnSchemaTest { use TestTrait; @@ -83,27 +81,24 @@ public function testColumnSchemaInstance() $this->assertInstanceOf(BinaryColumnSchema::class, $tableSchema->getColumn('blob_col')); } + /** @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\ColumnSchemaProvider::predefinedTypes */ + public function testPredefinedType(string $className, string $type, string $phpType) + { + parent::testPredefinedType($className, $type, $phpType); + } + + /** @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\ColumnSchemaProvider::dbTypecastColumns */ + public function testDbTypecastColumns(string $className, array $values) + { + parent::testDbTypecastColumns($className, $values); + } + public function testBinaryColumnSchema() { $binaryCol = new BinaryColumnSchema('binary_col'); + $binaryCol->dbType('BLOB'); $this->assertSame('binary_col', $binaryCol->getName()); - $this->assertSame(SchemaInterface::TYPE_BINARY, $binaryCol->getType()); - $this->assertSame(SchemaInterface::PHP_TYPE_RESOURCE, $binaryCol->getPhpType()); - - $this->assertNull($binaryCol->dbTypecast(null)); - $this->assertSame('1', $binaryCol->dbTypecast(1)); - $this->assertSame('1', $binaryCol->dbTypecast(true)); - $this->assertSame('0', $binaryCol->dbTypecast(false)); - $this->assertSame($resource = fopen('php://memory', 'rb'), $binaryCol->dbTypecast($resource)); - $this->assertEquals(new Param("\x10\x11\x12", PDO::PARAM_LOB), $binaryCol->dbTypecast("\x10\x11\x12")); - $this->assertSame($expression = new Expression('expression'), $binaryCol->dbTypecast($expression)); - - $this->assertNull($binaryCol->phpTypecast(null)); - $this->assertSame("\x10\x11\x12", $binaryCol->phpTypecast("\x10\x11\x12")); - $this->assertSame($resource = fopen('php://memory', 'rb'), $binaryCol->phpTypecast($resource)); - - $binaryCol->dbType('BLOB'); $this->assertInstanceOf(Expression::class, $binaryCol->dbTypecast("\x10\x11\x12")); $this->assertInstanceOf( Expression::class, diff --git a/tests/Provider/ColumnSchemaProvider.php b/tests/Provider/ColumnSchemaProvider.php new file mode 100644 index 00000000..32c4b439 --- /dev/null +++ b/tests/Provider/ColumnSchemaProvider.php @@ -0,0 +1,26 @@ + Date: Sun, 3 Sep 2023 19:01:49 +0700 Subject: [PATCH 4/8] Fix after merge --- src/Schema.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Schema.php b/src/Schema.php index 188c64ae..3050520d 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -668,7 +668,9 @@ private function extractColumnType(string $dbType, array $info): string $dbType = strtolower($dbType); if ($dbType === 'number') { - return match ($info['data_scale']) { + $scale = $info['data_scale'] !== null ? (int) $info['data_scale'] : null; + + return match ($scale) { null => self::TYPE_DOUBLE, 0 => self::TYPE_INTEGER, default => self::TYPE_DECIMAL, From 9dc9f002594bc99ea03282891089d89da352adf8 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 5 Sep 2023 14:19:58 +0700 Subject: [PATCH 5/8] Add line to CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 350db644..bd797efe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## 1.1.1 under development - Enh #230: Improve column type #230 (@Tigrov) +- Enh #236: Implement `ColumnSchemaInterface` classes according to the data type of database table columns + for type casting performance. Related with yiisoft/db#752 (@Tigrov) ## 1.1.0 July 24, 2023 From 2ccd6ff85345e075686286e1cba08cf1ddb31bda Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 5 May 2024 08:31:31 +0700 Subject: [PATCH 6/8] Improve --- CHANGELOG.md | 4 +- src/{ => Column}/BinaryColumnSchema.php | 7 ++- src/ColumnSchema.php | 66 ------------------------- src/Schema.php | 16 +++--- tests/ColumnSchemaTest.php | 2 +- tests/Provider/ColumnSchemaProvider.php | 2 +- 6 files changed, 16 insertions(+), 81 deletions(-) rename src/{ => Column}/BinaryColumnSchema.php (75%) delete mode 100644 src/ColumnSchema.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 9916dd7b..fb291e75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Enh #260: Support `Traversable` values for `DMLQueryBuilder::batchInsert()` method with empty columns (@Tigrov) - Enh #255: Implement `SqlParser` and `ExpressionBuilder` driver classes (@Tigrov) +- Enh #236: Implement `ColumnSchemaInterface` classes according to the data type of database table columns + for type casting performance. Related with yiisoft/db#752 (@Tigrov) ## 1.3.0 March 21, 2024 @@ -17,8 +19,6 @@ ## 1.2.0 November 12, 2023 - Enh #230: Improve column type #230 (@Tigrov) -- Enh #236: Implement `ColumnSchemaInterface` classes according to the data type of database table columns - for type casting performance. Related with yiisoft/db#752 (@Tigrov) - Enh #243: Move methods from `Command` to `AbstractPdoCommand` class (@Tigrov) - Bug #233: Refactor `DMLQueryBuilder`, related with yiisoft/db#746 (@Tigrov) - Bug #240: Remove `RECURSIVE` expression from CTE queries (@Tigrov) diff --git a/src/BinaryColumnSchema.php b/src/Column/BinaryColumnSchema.php similarity index 75% rename from src/BinaryColumnSchema.php rename to src/Column/BinaryColumnSchema.php index 27544182..3ca984cf 100644 --- a/src/BinaryColumnSchema.php +++ b/src/Column/BinaryColumnSchema.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Yiisoft\Db\Oracle; +namespace Yiisoft\Db\Oracle\Column; use Yiisoft\Db\Command\ParamInterface; use Yiisoft\Db\Expression\Expression; @@ -16,13 +16,12 @@ public function dbTypecast(mixed $value): mixed { if ($this->getDbType() === 'BLOB') { if ($value instanceof ParamInterface && is_string($value->getValue())) { - /** @psalm-var string */ + /** @var string */ $value = $value->getValue(); } if (is_string($value)) { - $placeholder = uniqid('exp_' . preg_replace('/[^a-z0-9]/i', '', $this->getName())); - return new Expression('TO_BLOB(UTL_RAW.CAST_TO_RAW(:' . $placeholder . '))', [$placeholder => $value]); + return new Expression('TO_BLOB(UTL_RAW.CAST_TO_RAW(:value))', ['value' => $value]); } } diff --git a/src/ColumnSchema.php b/src/ColumnSchema.php deleted file mode 100644 index a3a39f7a..00000000 --- a/src/ColumnSchema.php +++ /dev/null @@ -1,66 +0,0 @@ -name('id'); - * $column->allowNull(false); - * $column->dbType('number'); - * $column->phpType('integer'); - * $column->type('integer'); - * $column->defaultValue(0); - * $column->autoIncrement(true); - * $column->primaryKey(true); - * ``` - * - * @psalm-suppress DeprecatedInterface - * @psalm-suppress DeprecatedClass - */ -final class ColumnSchema extends AbstractColumnSchema -{ - public function dbTypecast(mixed $value): mixed - { - if ($this->getType() === SchemaInterface::TYPE_BINARY && $this->getDbType() === 'BLOB') { - if ($value instanceof ParamInterface && is_string($value->getValue())) { - $value = (string) $value->getValue(); - } - - if (is_string($value)) { - /** @var non-empty-string $placeholder */ - $placeholder = uniqid('exp_' . preg_replace('/[^a-z0-9]/i', '', $this->getName())); - return new Expression('TO_BLOB(UTL_RAW.CAST_TO_RAW(:' . $placeholder . '))', [$placeholder => $value]); - } - } - - /** @psalm-suppress DeprecatedClass */ - return parent::dbTypecast($value); - } -} diff --git a/src/Schema.php b/src/Schema.php index a533c9a5..48136156 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -17,6 +17,7 @@ use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Helper\DbArrayHelper; +use Yiisoft\Db\Oracle\Column\BinaryColumnSchema; use Yiisoft\Db\Schema\Builder\ColumnInterface; use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use Yiisoft\Db\Schema\TableSchemaInterface; @@ -405,14 +406,14 @@ protected function findColumns(TableSchemaInterface $table): bool return false; } - /** @psalm-var ColumnInfoArray $info */ + /** @psalm-var string[][] $info */ foreach ($columns as $info) { /** @psalm-var ColumnInfoArray $info */ $info = array_change_key_case($info); $column = $this->loadColumnSchema($info); - $table->column($column->getName(), $column); + $table->column($info['column_name'], $column); } return true; @@ -460,8 +461,9 @@ private function loadColumnSchema(array $info): ColumnSchemaInterface { $dbType = $info['data_type']; $type = $this->extractColumnType($dbType, $info); - /** @psalm-var ColumnInfoArray $info */ - $column = $this->createColumnSchema($type, $info['column_name']); + + $column = $this->createColumnSchema($type); + $column->name($info['column_name']); $column->allowNull($info['nullable'] === 'Y'); $column->comment($info['column_comment']); $column->primaryKey((bool) $info['is_pk']); @@ -475,13 +477,13 @@ private function loadColumnSchema(array $info): ColumnSchemaInterface return $column; } - protected function createPhpTypeColumnSchema(string $phpType, string $name): ColumnSchemaInterface + protected function createColumnSchemaFromPhpType(string $phpType, string $type): ColumnSchemaInterface { if ($phpType === self::PHP_TYPE_RESOURCE) { - return new BinaryColumnSchema($name); + return new BinaryColumnSchema($type, $phpType); } - return parent::createPhpTypeColumnSchema($phpType, $name); + return parent::createColumnSchemaFromPhpType($phpType, $type); } /** diff --git a/tests/ColumnSchemaTest.php b/tests/ColumnSchemaTest.php index beb9a5b8..40a387cc 100644 --- a/tests/ColumnSchemaTest.php +++ b/tests/ColumnSchemaTest.php @@ -7,7 +7,7 @@ use PDO; use Yiisoft\Db\Command\Param; use Yiisoft\Db\Expression\Expression; -use Yiisoft\Db\Oracle\BinaryColumnSchema; +use Yiisoft\Db\Oracle\Column\BinaryColumnSchema; use Yiisoft\Db\Oracle\Tests\Support\TestTrait; use Yiisoft\Db\Query\Query; use Yiisoft\Db\Schema\Column\DoubleColumnSchema; diff --git a/tests/Provider/ColumnSchemaProvider.php b/tests/Provider/ColumnSchemaProvider.php index 32c4b439..02545ec2 100644 --- a/tests/Provider/ColumnSchemaProvider.php +++ b/tests/Provider/ColumnSchemaProvider.php @@ -4,7 +4,7 @@ namespace Yiisoft\Db\Oracle\Tests\Provider; -use Yiisoft\Db\Oracle\BinaryColumnSchema; +use Yiisoft\Db\Oracle\Column\BinaryColumnSchema; class ColumnSchemaProvider extends \Yiisoft\Db\Tests\Provider\ColumnSchemaProvider { From 216ece501a484bd1b60893cf7eaa938ca3d8ee3b Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 5 May 2024 09:10:45 +0700 Subject: [PATCH 7/8] Fix phpunit --- tests/ColumnSchemaTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/ColumnSchemaTest.php b/tests/ColumnSchemaTest.php index 40a387cc..6977bd6b 100644 --- a/tests/ColumnSchemaTest.php +++ b/tests/ColumnSchemaTest.php @@ -95,10 +95,9 @@ public function testDbTypecastColumns(string $className, array $values) public function testBinaryColumnSchema() { - $binaryCol = new BinaryColumnSchema('binary_col'); + $binaryCol = new BinaryColumnSchema(); $binaryCol->dbType('BLOB'); - $this->assertSame('binary_col', $binaryCol->getName()); $this->assertInstanceOf(Expression::class, $binaryCol->dbTypecast("\x10\x11\x12")); $this->assertInstanceOf( Expression::class, From ccef4fd323bc08a013df1190f6465a44f62f4906 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 5 May 2024 09:16:50 +0700 Subject: [PATCH 8/8] Fix psalm --- src/DMLQueryBuilder.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/DMLQueryBuilder.php b/src/DMLQueryBuilder.php index c1b57e10..bcb5873a 100644 --- a/src/DMLQueryBuilder.php +++ b/src/DMLQueryBuilder.php @@ -13,6 +13,7 @@ use Yiisoft\Db\Query\QueryInterface; use Yiisoft\Db\QueryBuilder\AbstractDMLQueryBuilder; +use function array_key_first; use function array_map; use function implode; use function count; @@ -164,7 +165,8 @@ protected function prepareInsertValues(string $table, array|QueryInterface $colu if (!empty($tableSchema->getPrimaryKey())) { $columns = $tableSchema->getPrimaryKey(); } else { - $columns = [current($tableSchema->getColumns())->getName()]; + /** @var list $columns */ + $columns = [array_key_first($tableSchema->getColumns())]; } foreach ($columns as $name) {