From d594a8b368ff47a00b80c746f7fd8e4730238d3c Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Mon, 6 May 2024 15:09:16 +0700 Subject: [PATCH 01/14] Refactor `insertBatch()`, add `getRawTableName()` to `QuoterInterface` (#834) --- CHANGELOG.md | 1 + UPGRADE.md | 4 ++++ src/Command/AbstractCommand.php | 9 +-------- src/Schema/Quoter.php | 10 ---------- src/Schema/QuoterInterface.php | 12 ++++++++++++ tests/Db/Helper/DbArrayHelperTest.php | 8 ++++---- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bffa6bf4..4a058bb0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Bug #828: Fix `float` type when use `AbstractCommand::getRawSql()` method (@Tigrov) - Enh #829: Rename `batchInsert()` to `insertBatch()` in `DMLQueryBuilderInterface` and `CommandInterface` and change parameters from `$table, $columns, $rows` to `$table, $rows, $columns = []` (@Tigrov) +- Enh #834: Refactor `AbstractCommand::insertBatch()`, add `Quoter::getRawTableName()` to `QuoterInterface` (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index 6da8f2b95..00ed580ab 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -54,3 +54,7 @@ $values = [ /** @var ConnectionInterface $db */ $db->createCommand()->insertBatch('user', $values)->execute(); ``` + +### New methods in `QuoterInterface` + +* `QuoterInterface::getRawTableName()` - returns the raw table name without quotes. diff --git a/src/Command/AbstractCommand.php b/src/Command/AbstractCommand.php index 0114d801d..c9f1e505f 100644 --- a/src/Command/AbstractCommand.php +++ b/src/Command/AbstractCommand.php @@ -212,14 +212,7 @@ public function batchInsert(string $table, array $columns, iterable $rows): stat public function insertBatch(string $table, iterable $rows, array $columns = []): static { - $table = $this->getQueryBuilder()->quoter()->quoteSql($table); - - /** @psalm-var string[] $columns */ - foreach ($columns as &$column) { - $column = $this->getQueryBuilder()->quoter()->quoteSql($column); - } - - unset($column); + $table = $this->getQueryBuilder()->quoter()->getRawTableName($table); $params = []; $sql = $this->getQueryBuilder()->insertBatch($table, $rows, $columns, $params); diff --git a/src/Schema/Quoter.php b/src/Schema/Quoter.php index 8314c1499..18f78aa2e 100644 --- a/src/Schema/Quoter.php +++ b/src/Schema/Quoter.php @@ -83,16 +83,6 @@ public function cleanUpTableNames(array $tableNames): array return $cleanedUpTableNames; } - /** - * Returns the actual name of a given table name. - * - * This method will strip off curly brackets from the given table name and replace the percentage character '%' with - * {@see ConnectionInterface::tablePrefix}. - * - * @param string $name The table name to convert. - * - * @return string The real name of the given table name. - */ public function getRawTableName(string $name): string { if (str_contains($name, '{{')) { diff --git a/src/Schema/QuoterInterface.php b/src/Schema/QuoterInterface.php index f51e446cc..9435c434c 100644 --- a/src/Schema/QuoterInterface.php +++ b/src/Schema/QuoterInterface.php @@ -26,6 +26,18 @@ interface QuoterInterface */ public function cleanUpTableNames(array $tableNames): array; + /** + * Returns the actual name of a given table name. + * + * This method will strip off curly brackets from the given table name and replace the percentage character '%' with + * {@see ConnectionInterface::tablePrefix}. + * + * @param string $name The table name to convert. + * + * @return string The real name of the given table name. + */ + public function getRawTableName(string $name): string; + /** * Splits full table name into parts. * diff --git a/tests/Db/Helper/DbArrayHelperTest.php b/tests/Db/Helper/DbArrayHelperTest.php index 3a87586e4..0f7039fe1 100644 --- a/tests/Db/Helper/DbArrayHelperTest.php +++ b/tests/Db/Helper/DbArrayHelperTest.php @@ -33,20 +33,20 @@ public function testPopulate(array $rows): void * @dataProvider \Yiisoft\Db\Tests\Provider\PopulateProvider::populateWithIncorrectIndexBy * @dataProvider \Yiisoft\Db\Tests\Provider\PopulateProvider::populateWithIndexByClosure */ - public function testPopulateWithIndexBy(Closure|string|null $indexBy, array $rows, array $populated): void + public function testPopulateWithIndexBy(Closure|string|null $indexBy, array $rows, array $expected): void { - $this->assertSame($populated, DbArrayHelper::populate($rows, $indexBy)); + $this->assertSame($expected, DbArrayHelper::populate($rows, $indexBy)); } /** * @dataProvider \Yiisoft\Db\Tests\Provider\PopulateProvider::populateWithIndexBy */ - public function testPopulateWithIndexByWithObject(Closure|string|null $indexBy, array $rows, array $expectedPopulated): void + public function testPopulateWithIndexByWithObject(Closure|string|null $indexBy, array $rows, array $expected): void { $rows = json_decode(json_encode($rows)); $populated = json_decode(json_encode(DbArrayHelper::populate($rows, $indexBy)), true); - $this->assertSame($expectedPopulated, $populated); + $this->assertSame($expected, $populated); } /** From 7bb36b272dc6bdff8b63d044904e87fef943ea66 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Tue, 7 May 2024 08:53:33 +0700 Subject: [PATCH 02/14] Remove `AbstractDMLQueryBuilder::getTypecastValue()` method (#836) --- CHANGELOG.md | 1 + UPGRADE.md | 4 ++++ src/QueryBuilder/AbstractDMLQueryBuilder.php | 15 --------------- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a058bb0f..c86a07cb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Enh #829: Rename `batchInsert()` to `insertBatch()` in `DMLQueryBuilderInterface` and `CommandInterface` and change parameters from `$table, $columns, $rows` to `$table, $rows, $columns = []` (@Tigrov) - Enh #834: Refactor `AbstractCommand::insertBatch()`, add `Quoter::getRawTableName()` to `QuoterInterface` (@Tigrov) +- Chg #836: Remove `AbstractDMLQueryBuilder::getTypecastValue()` method (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index 00ed580ab..e3ab80293 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -58,3 +58,7 @@ $db->createCommand()->insertBatch('user', $values)->execute(); ### New methods in `QuoterInterface` * `QuoterInterface::getRawTableName()` - returns the raw table name without quotes. + +### Remove deprecated methods + +- `AbstractDMLQueryBuilder::getTypecastValue()` diff --git a/src/QueryBuilder/AbstractDMLQueryBuilder.php b/src/QueryBuilder/AbstractDMLQueryBuilder.php index c877b8650..1ae0ef083 100644 --- a/src/QueryBuilder/AbstractDMLQueryBuilder.php +++ b/src/QueryBuilder/AbstractDMLQueryBuilder.php @@ -16,7 +16,6 @@ use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Query\QueryInterface; -use Yiisoft\Db\Schema\ColumnSchemaInterface; use Yiisoft\Db\Schema\QuoterInterface; use Yiisoft\Db\Schema\SchemaInterface; @@ -511,20 +510,6 @@ static function (Constraint $constraint) use ($quoter, $columns, &$columnNames): return array_unique($columnNames); } - /** - * @return mixed The typecast value of the given column. - * - * @deprecated will be removed in version 2.0.0 - */ - protected function getTypecastValue(mixed $value, ColumnSchemaInterface $columnSchema = null): mixed - { - if ($columnSchema) { - return $columnSchema->dbTypecast($value); - } - - return $value; - } - /** * Normalizes the column names. * From c702494f3e474db8e3d0a169c022db5ef6488783 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Wed, 8 May 2024 09:41:52 +0700 Subject: [PATCH 03/14] Remove `$table` parameter from `normalizeColumnNames()` (#837) --- CHANGELOG.md | 2 ++ UPGRADE.md | 5 +++++ src/QueryBuilder/AbstractDMLQueryBuilder.php | 16 +++++++--------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c86a07cb9..fa16b2012 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and change parameters from `$table, $columns, $rows` to `$table, $rows, $columns = []` (@Tigrov) - Enh #834: Refactor `AbstractCommand::insertBatch()`, add `Quoter::getRawTableName()` to `QuoterInterface` (@Tigrov) - Chg #836: Remove `AbstractDMLQueryBuilder::getTypecastValue()` method (@Tigrov) +- Chg #767: Remove `$table` parameter from `normalizeColumnNames()` and `getNormalizeColumnNames()` methods + of `AbstractDMLQueryBuilder` class (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index e3ab80293..377edf6ed 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -62,3 +62,8 @@ $db->createCommand()->insertBatch('user', $values)->execute(); ### Remove deprecated methods - `AbstractDMLQueryBuilder::getTypecastValue()` + +### Remove deprecated parameters + +- `$table` parameter from `AbstractDMLQueryBuilder::normalizeColumnNames()` method +- `$table` parameter from `AbstractDMLQueryBuilder::getNormalizeColumnNames()` method diff --git a/src/QueryBuilder/AbstractDMLQueryBuilder.php b/src/QueryBuilder/AbstractDMLQueryBuilder.php index 1ae0ef083..0b283bb76 100644 --- a/src/QueryBuilder/AbstractDMLQueryBuilder.php +++ b/src/QueryBuilder/AbstractDMLQueryBuilder.php @@ -227,7 +227,7 @@ protected function prepareBatchInsertValues(string $table, iterable $rows, array */ protected function extractColumnNames(array|Iterator $rows, array $columns): array { - $columns = $this->getNormalizeColumnNames('', $columns); + $columns = $this->getNormalizeColumnNames($columns); if (!empty($columns)) { return $columns; @@ -332,7 +332,7 @@ protected function prepareInsertValues(string $table, array|QueryInterface $colu $names = []; $placeholders = []; - $columns = $this->normalizeColumnNames('', $columns); + $columns = $this->normalizeColumnNames($columns); $columnSchemas = $this->schema->getTableSchema($table)?->getColumns() ?? []; foreach ($columns as $name => $value) { @@ -366,7 +366,7 @@ protected function prepareInsertValues(string $table, array|QueryInterface $colu protected function prepareUpdateSets(string $table, array $columns, array $params = []): array { $sets = []; - $columns = $this->normalizeColumnNames('', $columns); + $columns = $this->normalizeColumnNames($columns); $columnSchemas = $this->schema->getTableSchema($table)?->getColumns() ?? []; foreach ($columns as $name => $value) { @@ -410,7 +410,7 @@ protected function prepareUpsertColumns( if ($insertColumns instanceof QueryInterface) { [$insertNames] = $this->prepareInsertSelectSubQuery($insertColumns); } else { - $insertNames = $this->getNormalizeColumnNames('', array_keys($insertColumns)); + $insertNames = $this->getNormalizeColumnNames(array_keys($insertColumns)); $insertNames = array_map( [$this->quoter, 'quoteColumnName'], @@ -513,18 +513,17 @@ static function (Constraint $constraint) use ($quoter, $columns, &$columnNames): /** * Normalizes the column names. * - * @param string $table Not used. Could be empty string. Will be removed in version 2.0.0. * @param array $columns The column data (name => value). * * @return array The normalized column names (name => value). * * @psalm-return array */ - protected function normalizeColumnNames(string $table, array $columns): array + protected function normalizeColumnNames(array $columns): array { /** @var string[] $columnNames */ $columnNames = array_keys($columns); - $normalizedNames = $this->getNormalizeColumnNames('', $columnNames); + $normalizedNames = $this->getNormalizeColumnNames($columnNames); return array_combine($normalizedNames, $columns); } @@ -532,12 +531,11 @@ protected function normalizeColumnNames(string $table, array $columns): array /** * Get normalized column names * - * @param string $table Not used. Could be empty string. Will be removed in version 2.0.0. * @param string[] $columns The column names. * * @return string[] Normalized column names. */ - protected function getNormalizeColumnNames(string $table, array $columns): array + protected function getNormalizeColumnNames(array $columns): array { foreach ($columns as &$name) { $name = $this->quoter->ensureColumnName($name); From f0f8d90050b68e4e712c09b9f54d724a04bf30c7 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Thu, 9 May 2024 14:21:11 +0700 Subject: [PATCH 04/14] Remove `SchemaInterface::TYPE_JSONB` constant (#838) --- CHANGELOG.md | 3 ++- UPGRADE.md | 6 +++++- src/Schema/SchemaInterface.php | 6 ------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa16b2012..81ce4717f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,8 +13,9 @@ and change parameters from `$table, $columns, $rows` to `$table, $rows, $columns = []` (@Tigrov) - Enh #834: Refactor `AbstractCommand::insertBatch()`, add `Quoter::getRawTableName()` to `QuoterInterface` (@Tigrov) - Chg #836: Remove `AbstractDMLQueryBuilder::getTypecastValue()` method (@Tigrov) -- Chg #767: Remove `$table` parameter from `normalizeColumnNames()` and `getNormalizeColumnNames()` methods +- Chg #837: Remove `$table` parameter from `normalizeColumnNames()` and `getNormalizeColumnNames()` methods of `AbstractDMLQueryBuilder` class (@Tigrov) +- Chg #838: Remove `SchemaInterface::TYPE_JSONB` constant (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index 377edf6ed..19f330517 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -57,7 +57,7 @@ $db->createCommand()->insertBatch('user', $values)->execute(); ### New methods in `QuoterInterface` -* `QuoterInterface::getRawTableName()` - returns the raw table name without quotes. +- `QuoterInterface::getRawTableName()` - returns the raw table name without quotes. ### Remove deprecated methods @@ -67,3 +67,7 @@ $db->createCommand()->insertBatch('user', $values)->execute(); - `$table` parameter from `AbstractDMLQueryBuilder::normalizeColumnNames()` method - `$table` parameter from `AbstractDMLQueryBuilder::getNormalizeColumnNames()` method + +### Remove deprecated constants + +- `SchemaInterface::TYPE_JSONB` diff --git a/src/Schema/SchemaInterface.php b/src/Schema/SchemaInterface.php index 744ebc555..73d0893e0 100644 --- a/src/Schema/SchemaInterface.php +++ b/src/Schema/SchemaInterface.php @@ -218,12 +218,6 @@ interface SchemaInterface extends ConstraintSchemaInterface * Define the abstract column type as `json`. */ public const TYPE_JSON = 'json'; - /** - * Define the abstract column type as `jsonb`. - * - * @deprecated will be removed in version 2.0.0. Use `SchemaInterface::TYPE_JSON` instead. - */ - public const TYPE_JSONB = 'jsonb'; /** * Define the php type as `integer` for cast to php value. From b4254afc4ad1907eceac676a98cbdad8c7e4e513 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Thu, 9 May 2024 14:53:10 +0700 Subject: [PATCH 05/14] Remove `TableSchemaInterface::compositeForeignKey()` method (#839) --- CHANGELOG.md | 1 + UPGRADE.md | 1 + src/Schema/AbstractTableSchema.php | 7 ------- src/Schema/TableSchemaInterface.php | 15 --------------- tests/AbstractTableSchemaTest.php | 11 ----------- 5 files changed, 2 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81ce4717f..dd7283b12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Chg #837: Remove `$table` parameter from `normalizeColumnNames()` and `getNormalizeColumnNames()` methods of `AbstractDMLQueryBuilder` class (@Tigrov) - Chg #838: Remove `SchemaInterface::TYPE_JSONB` constant (@Tigrov) +- Chg #839: Remove `TableSchemaInterface::compositeForeignKey()` method (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index 19f330517..6af704b1f 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -62,6 +62,7 @@ $db->createCommand()->insertBatch('user', $values)->execute(); ### Remove deprecated methods - `AbstractDMLQueryBuilder::getTypecastValue()` +- `TableSchemaInterface::compositeForeignKey()` ### Remove deprecated parameters diff --git a/src/Schema/AbstractTableSchema.php b/src/Schema/AbstractTableSchema.php index e5b6ada95..bc72ad989 100644 --- a/src/Schema/AbstractTableSchema.php +++ b/src/Schema/AbstractTableSchema.php @@ -4,8 +4,6 @@ namespace Yiisoft\Db\Schema; -use Yiisoft\Db\Exception\NotSupportedException; - use function array_keys; /** @@ -152,9 +150,4 @@ public function foreignKey(string|int $id, array $to): void { $this->foreignKeys[$id] = $to; } - - public function compositeForeignKey(int $id, string $from, string $to): void - { - throw new NotSupportedException(static::class . ' does not support composite FK.'); - } } diff --git a/src/Schema/TableSchemaInterface.php b/src/Schema/TableSchemaInterface.php index 47fe0c107..db1ddd1de 100644 --- a/src/Schema/TableSchemaInterface.php +++ b/src/Schema/TableSchemaInterface.php @@ -4,8 +4,6 @@ namespace Yiisoft\Db\Schema; -use Yiisoft\Db\Exception\NotSupportedException; - /** * Represents the metadata of a database table. * @@ -201,17 +199,4 @@ public function foreignKeys(array $value): void; * @param array $to The foreign key. */ public function foreignKey(string|int $id, array $to): void; - - /** - * Set composite foreign key. - * - * @param int $id The index of foreign key. - * @param string $from The column name in current table. - * @param string $to The column name in foreign table. - * - * @throws NotSupportedException - * - * @deprecated will be removed in version 2.0.0 - */ - public function compositeForeignKey(int $id, string $from, string $to): void; } diff --git a/tests/AbstractTableSchemaTest.php b/tests/AbstractTableSchemaTest.php index a22446710..5a4fd3ba2 100644 --- a/tests/AbstractTableSchemaTest.php +++ b/tests/AbstractTableSchemaTest.php @@ -5,7 +5,6 @@ namespace Yiisoft\Db\Tests; use PHPUnit\Framework\TestCase; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Tests\Support\Stub\ColumnSchema; use Yiisoft\Db\Tests\Support\Stub\TableSchema; use Yiisoft\Db\Tests\Support\TestTrait; @@ -14,16 +13,6 @@ abstract class AbstractTableSchemaTest extends TestCase { use TestTrait; - public function testCompositeFk(): void - { - $tableSchema = new TableSchema(); - - $this->expectException(NotSupportedException::class); - $this->expectExceptionMessage('Yiisoft\Db\Tests\Support\Stub\TableSchema does not support composite FK.'); - - $tableSchema->compositeForeignKey(1, 'from', 'to'); - } - public function testGetCatalogName(): void { $tableSchema = new TableSchema(); From 68823a6cecc8f2e9ec6b60cc41fdd783e9006374 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Thu, 9 May 2024 16:34:20 +0700 Subject: [PATCH 06/14] Remove parameter `$withColumn` from `QuoterInterface::getTableNameParts()`, Remove `Quoter::unquoteParts()` (#840) --- CHANGELOG.md | 2 ++ UPGRADE.md | 8 +++++--- src/Schema/Quoter.php | 23 +++-------------------- src/Schema/QuoterInterface.php | 3 +-- 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd7283b12..3092a1ed0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ of `AbstractDMLQueryBuilder` class (@Tigrov) - Chg #838: Remove `SchemaInterface::TYPE_JSONB` constant (@Tigrov) - Chg #839: Remove `TableSchemaInterface::compositeForeignKey()` method (@Tigrov) +- Chg #840: Remove parameter `$withColumn` from `QuoterInterface::getTableNameParts()` method (@Tigrov) +- Chg #840: Remove `Quoter::unquoteParts()` method (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index 6af704b1f..74a87e527 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -59,15 +59,17 @@ $db->createCommand()->insertBatch('user', $values)->execute(); - `QuoterInterface::getRawTableName()` - returns the raw table name without quotes. -### Remove deprecated methods +### Remove methods - `AbstractDMLQueryBuilder::getTypecastValue()` - `TableSchemaInterface::compositeForeignKey()` +- `Quoter::unquoteParts()` ### Remove deprecated parameters -- `$table` parameter from `AbstractDMLQueryBuilder::normalizeColumnNames()` method -- `$table` parameter from `AbstractDMLQueryBuilder::getNormalizeColumnNames()` method +- `$table` from `AbstractDMLQueryBuilder::normalizeColumnNames()` method +- `$table` from `AbstractDMLQueryBuilder::getNormalizeColumnNames()` method +- `$withColumn` from `QuoterInterface::getTableNameParts()` method ### Remove deprecated constants diff --git a/src/Schema/Quoter.php b/src/Schema/Quoter.php index 18f78aa2e..7ec65b4eb 100644 --- a/src/Schema/Quoter.php +++ b/src/Schema/Quoter.php @@ -8,6 +8,7 @@ use Yiisoft\Db\Expression\ExpressionInterface; use function addcslashes; +use function array_map; use function array_slice; use function count; use function explode; @@ -94,11 +95,11 @@ public function getRawTableName(string $name): string return $name; } - public function getTableNameParts(string $name, bool $withColumn = false): array + public function getTableNameParts(string $name): array { $parts = array_slice(explode('.', $name), -2, 2); - return $this->unquoteParts($parts, $withColumn); + return array_map([$this, 'unquoteSimpleTableName'], $parts); } public function ensureNameQuoted(string $name): string @@ -245,22 +246,4 @@ public function unquoteSimpleTableName(string $name): string ? $name : substr($name, 1, -1); } - - /** - * @psalm-param string[] $parts Parts of table name - * - * @psalm-return string[] - */ - protected function unquoteParts(array $parts, bool $withColumn): array - { - $lastKey = count($parts) - 1; - - foreach ($parts as $k => &$part) { - $part = ($withColumn && $lastKey === $k) ? - $this->unquoteSimpleColumnName($part) : - $this->unquoteSimpleTableName($part); - } - - return $parts; - } } diff --git a/src/Schema/QuoterInterface.php b/src/Schema/QuoterInterface.php index 9435c434c..7f2325928 100644 --- a/src/Schema/QuoterInterface.php +++ b/src/Schema/QuoterInterface.php @@ -42,11 +42,10 @@ public function getRawTableName(string $name): string; * Splits full table name into parts. * * @param string $name The full name of the table. - * @param bool $withColumn Deprecated. Will be removed in version 2.0.0. * * @return string[] The table name parts. */ - public function getTableNameParts(string $name, bool $withColumn = false): array; + public function getTableNameParts(string $name): array; /** * Ensures name is wrapped with `{{ and }}`. From 1ff947e638424592ab0180d25173f66cd8084077 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Thu, 9 May 2024 18:00:37 +0700 Subject: [PATCH 07/14] Remove `$rawSql` parameter from `internalExecute()` method of `AbstractCommand` and `AbstractPdoCommand` classes (#841) --- CHANGELOG.md | 2 ++ UPGRADE.md | 2 ++ src/Command/AbstractCommand.php | 6 ++---- src/Driver/Pdo/AbstractPdoCommand.php | 6 ++---- tests/Common/CommonCommandTest.php | 2 +- tests/Common/CommonPdoCommandTest.php | 2 +- tests/Support/Stub/Command.php | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3092a1ed0..4a4f7ba0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ - Chg #839: Remove `TableSchemaInterface::compositeForeignKey()` method (@Tigrov) - Chg #840: Remove parameter `$withColumn` from `QuoterInterface::getTableNameParts()` method (@Tigrov) - Chg #840: Remove `Quoter::unquoteParts()` method (@Tigrov) +- Chg #841: Remove `$rawSql` parameter from `AbstractCommand::internalExecute()` method + and `AbstractPdoCommand::internalExecute()` method (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index 74a87e527..571d45eb5 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -70,6 +70,8 @@ $db->createCommand()->insertBatch('user', $values)->execute(); - `$table` from `AbstractDMLQueryBuilder::normalizeColumnNames()` method - `$table` from `AbstractDMLQueryBuilder::getNormalizeColumnNames()` method - `$withColumn` from `QuoterInterface::getTableNameParts()` method +- `$rawSql` from `AbstractCommand::internalExecute()` method +- `$rawSql` from `AbstractPdoCommand::internalExecute()` method ### Remove deprecated constants diff --git a/src/Command/AbstractCommand.php b/src/Command/AbstractCommand.php index c9f1e505f..ca320ea4e 100644 --- a/src/Command/AbstractCommand.php +++ b/src/Command/AbstractCommand.php @@ -556,12 +556,10 @@ abstract protected function internalGetQueryResult(int $queryMode): mixed; /** * Executes a prepared statement. * - * @param string|null $rawSql Deprecated. Use `null` value. Will be removed in version 2.0.0. - * * @throws Exception * @throws Throwable */ - abstract protected function internalExecute(string|null $rawSql): void; + abstract protected function internalExecute(): void; /** * Check if the value has a given flag. @@ -589,7 +587,7 @@ protected function queryInternal(int $queryMode): mixed $isReadMode = $this->isReadMode($queryMode); $this->prepare($isReadMode); - $this->internalExecute(null); + $this->internalExecute(); /** @psalm-var mixed $result */ $result = $this->internalGetQueryResult($queryMode); diff --git a/src/Driver/Pdo/AbstractPdoCommand.php b/src/Driver/Pdo/AbstractPdoCommand.php index 54899e993..eab69ea87 100644 --- a/src/Driver/Pdo/AbstractPdoCommand.php +++ b/src/Driver/Pdo/AbstractPdoCommand.php @@ -185,12 +185,10 @@ protected function getQueryMode(int $queryMode): string * * It's a wrapper around {@see PDOStatement::execute()} to support transactions and retry handlers. * - * @param string|null $rawSql Deprecated. Use `null` value. Will be removed in version 2.0.0. - * * @throws Exception * @throws Throwable */ - protected function internalExecute(string|null $rawSql): void + protected function internalExecute(): void { $attempt = 0; @@ -202,7 +200,7 @@ protected function internalExecute(string|null $rawSql): void && $this->db->getTransaction() === null ) { $this->db->transaction( - fn () => $this->internalExecute($rawSql), + fn () => $this->internalExecute(), $this->isolationLevel ); } else { diff --git a/tests/Common/CommonCommandTest.php b/tests/Common/CommonCommandTest.php index d08556014..2c8d7d31b 100644 --- a/tests/Common/CommonCommandTest.php +++ b/tests/Common/CommonCommandTest.php @@ -1973,7 +1973,7 @@ protected function getQueryBuilder(): QueryBuilderInterface { } - protected function internalExecute(string|null $rawSql): void + protected function internalExecute(): void { } }; diff --git a/tests/Common/CommonPdoCommandTest.php b/tests/Common/CommonPdoCommandTest.php index 1b00e39b2..98f90aa74 100644 --- a/tests/Common/CommonPdoCommandTest.php +++ b/tests/Common/CommonPdoCommandTest.php @@ -218,7 +218,7 @@ protected function getQueryBuilder(): QueryBuilderInterface { } - protected function internalExecute(?string $rawSql): void + protected function internalExecute(): void { } }; diff --git a/tests/Support/Stub/Command.php b/tests/Support/Stub/Command.php index 3293265c3..027ecb097 100644 --- a/tests/Support/Stub/Command.php +++ b/tests/Support/Stub/Command.php @@ -25,7 +25,7 @@ protected function getQueryBuilder(): QueryBuilderInterface return $this->db->getQueryBuilder(); } - protected function internalExecute(string|null $rawSql): void + protected function internalExecute(): void { throw new NotSupportedException(__METHOD__ . ' is not supported by this DBMS.'); } From 2033479bd748eabcaa10b9b95d3933be94d60533 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Fri, 10 May 2024 10:05:02 +0700 Subject: [PATCH 08/14] Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` (#842) --- CHANGELOG.md | 5 +++-- UPGRADE.md | 4 ++++ src/Query/Query.php | 7 +++++-- src/Query/QueryPartsInterface.php | 9 +++++++-- tests/Provider/QueryBuilderProvider.php | 1 + 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a4f7ba0d..9548beb53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,9 +18,10 @@ - Chg #838: Remove `SchemaInterface::TYPE_JSONB` constant (@Tigrov) - Chg #839: Remove `TableSchemaInterface::compositeForeignKey()` method (@Tigrov) - Chg #840: Remove parameter `$withColumn` from `QuoterInterface::getTableNameParts()` method (@Tigrov) -- Chg #840: Remove `Quoter::unquoteParts()` method (@Tigrov) -- Chg #841: Remove `$rawSql` parameter from `AbstractCommand::internalExecute()` method +- Enh #840: Remove `Quoter::unquoteParts()` method (@Tigrov) +- Chg #841: Remove `$rawSql` parameter from `AbstractCommand::internalExecute()` method and `AbstractPdoCommand::internalExecute()` method (@Tigrov) +- Enh #842: Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index 571d45eb5..af5713827 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -76,3 +76,7 @@ $db->createCommand()->insertBatch('user', $values)->execute(); ### Remove deprecated constants - `SchemaInterface::TYPE_JSONB` + +### Other changes + +- Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method diff --git a/src/Query/Query.php b/src/Query/Query.php index 1a2857811..60d635159 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -669,8 +669,11 @@ public function where(array|string|ExpressionInterface|null $condition, array $p return $this; } - public function withQuery(QueryInterface|string $query, string $alias, bool $recursive = false): static - { + public function withQuery( + QueryInterface|string $query, + ExpressionInterface|string $alias, + bool $recursive = false + ): static { $this->withQueries[] = ['query' => $query, 'alias' => $alias, 'recursive' => $recursive]; return $this; } diff --git a/src/Query/QueryPartsInterface.php b/src/Query/QueryPartsInterface.php index fbef76cef..784e722c9 100644 --- a/src/Query/QueryPartsInterface.php +++ b/src/Query/QueryPartsInterface.php @@ -680,10 +680,15 @@ public function where(array|string|ExpressionInterface|null $condition, array $p * Prepends an SQL statement using `WITH` syntax. * * @param QueryInterface|string $query The SQL statement to append using `UNION`. - * @param string $alias The query alias in `WITH` construction. + * @param ExpressionInterface|string $alias The query alias in `WITH` construction. + * To specify the alias in plain SQL, you may pass an instance of {@see ExpressionInterface}. * @param bool $recursive Its `true` if using `WITH RECURSIVE` and `false` if using `WITH`. */ - public function withQuery(QueryInterface|string $query, string $alias, bool $recursive = false): static; + public function withQuery( + QueryInterface|string $query, + ExpressionInterface|string $alias, + bool $recursive = false + ): static; /** * Specifies the `WITH` query clause for the query. diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 564493def..9c350bd9a 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -1527,6 +1527,7 @@ public static function cteAliases(): array 'with one column' => ['a(b)', '[[a]]([[b]])'], 'with columns' => ['a(b,c,d)', '[[a]]([[b]], [[c]], [[d]])'], 'with extra space' => ['a(b,c,d) ', 'a(b,c,d) '], + 'expression' => [new Expression('a(b,c,d)'), 'a(b,c,d)'], ]; } From 25de1a6ac6c017dcbe5961ca1fafc38bbff44926 Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Fri, 10 May 2024 00:23:07 -0300 Subject: [PATCH 09/14] Fix docs (#833) * Fix docs * Update file * Update README.md * Update UPGRADE.md * fix * Update docs/internals.md --------- Co-authored-by: Sergei Predvoditelev Co-authored-by: Sergei Tigrov --- README.md | 16 +++++----- UPGRADE.md | 12 ++++--- docs/guide/en/README.md | 8 +---- docs/guide/pt-BR/README.md | 10 ++---- docs/internals.md | 64 +++++++++++++++++++++++++++++++++++++- docs/testing.md | 63 ------------------------------------- 6 files changed, 82 insertions(+), 91 deletions(-) delete mode 100644 docs/testing.md diff --git a/README.md b/README.md index 7d5590e53..7fbc25a12 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,15 @@

Yii Database

+[![Latest Stable Version](https://poser.pugx.org/yiisoft/db/v/stable.png)](https://packagist.org/packages/yiisoft/db) +[![Total Downloads](https://poser.pugx.org/yiisoft/db/downloads.png)](https://packagist.org/packages/yiisoft/db) +[![Build status](https://github.com/yiisoft/db/workflows/build/badge.svg)](https://github.com/yiisoft/db/actions?query=workflow%3Abuild) +[![codecov](https://codecov.io/gh/yiisoft/db/branch/master/graph/badge.svg?token=pRr4gci2qj)](https://codecov.io/gh/yiisoft/db) +[![static analysis](https://github.com/yiisoft/db/actions/workflows/static.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db/actions/workflows/static.yml) +[![type-coverage](https://shepherd.dev/github/yiisoft/db/coverage.svg)](https://shepherd.dev/github/yiisoft/db) + Yii Database is a framework-agnostic package to work with different types of databases, -such as [MariaDB], [MSSQL], [MySQL], [Oracle], [PostgreSQL], and [SQLite]. +such as [MariaDB], [MSSQL], [MySQL], [Oracle], [PostgreSQL] and [SQLite]. Using the package, you can perform common database tasks such as creating, reading, updating, and deleting records in a database table, as well as executing raw SQL queries. @@ -35,13 +42,6 @@ similar to the way you would use ORM (Object-Relational Mapping) frameworks like [PostgreSQL]: https://www.postgresql.org [SQLite]: https://www.sqlite.org -[![Latest Stable Version](https://poser.pugx.org/yiisoft/db/v/stable.png)](https://packagist.org/packages/yiisoft/db) -[![Total Downloads](https://poser.pugx.org/yiisoft/db/downloads.png)](https://packagist.org/packages/yiisoft/db) -[![Build status](https://github.com/yiisoft/db/workflows/build/badge.svg)](https://github.com/yiisoft/db/actions?query=workflow%3Abuild) -[![codecov](https://codecov.io/gh/yiisoft/db/branch/master/graph/badge.svg?token=pRr4gci2qj)](https://codecov.io/gh/yiisoft/db) -[![static analysis](https://github.com/yiisoft/db/actions/workflows/static.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db/actions/workflows/static.yml) -[![type-coverage](https://shepherd.dev/github/yiisoft/db/coverage.svg)](https://shepherd.dev/github/yiisoft/db) - ## Requirements - PHP 8.0 or higher. diff --git a/UPGRADE.md b/UPGRADE.md index af5713827..c094144fe 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,7 +1,11 @@ -# Upgrading Instructions for Yii Database - -The following upgrading instructions are cumulative. That is, if you want to upgrade from version A to version C and -there is version B between A and C, you need to following the instructions for both A and B. +# Yii Database Upgrading Instructions + +> **!!!IMPORTANT!!!** +> +> The following upgrading instructions are *cumulative*. That is, +> if you want to upgrade from version A to version C and there is +> version B between A and C, you need to following the instructions +> for both A and B. ## Upgrade from 1.x to 2.x diff --git a/docs/guide/en/README.md b/docs/guide/en/README.md index dfe593cc2..f531cd9cd 100644 --- a/docs/guide/en/README.md +++ b/docs/guide/en/README.md @@ -23,13 +23,9 @@ Yii DB supports the following databases out of the box: - [PostgreSQL](https://www.postgresql.org/) of versions **9.6 - 15**. - [SQLite](https://www.sqlite.org/) of version **3.3 and above**. -## Requirements - -- PHP 8.0 or higher. - ## Installation -To install Yii DB, you must select the driver you want to use and install it with [Composer](https://getcomposer.org/). +To install Yii DB, you must select the driver you want to use and install it with [Composer](https://getcomposer.org). For [MSSQL](https://github.com/yiisoft/db-mssql): @@ -61,8 +57,6 @@ For [SQLite](https://github.com/yiisoft/db-sqlite): composer require yiisoft/db-sqlite ``` -## Prerequisites - ## Configure schema cache First, you need to [configure database schema cache](schema/cache.md). diff --git a/docs/guide/pt-BR/README.md b/docs/guide/pt-BR/README.md index b5c3dc7e9..6b06bd86d 100644 --- a/docs/guide/pt-BR/README.md +++ b/docs/guide/pt-BR/README.md @@ -23,13 +23,9 @@ Yii DB suporta os seguintes bancos de dados prontos para uso: - [PostgreSQL](https://www.postgresql.org/) das versões **9.6 - 15**. - [SQLite](https://www.sqlite.org/) da versão **3.3 e superior**. -## Requerimentos +## Installation -- PHP 8.0 or higher. - -## Instalação - -Para instalar o Yii DB, você deve selecionar o driver que deseja usar e instalá-lo com o [Composer](https://getcomposer.org/). +Para instalar o Yii DB, você deve selecionar o driver que deseja usar e instalá-lo com o [Composer](https://getcomposer.org). Para [MSSQL](https://github.com/yiisoft/db-mssql): @@ -61,8 +57,6 @@ Para [SQLite](https://github.com/yiisoft/db-sqlite): composer require yiisoft/db-sqlite ``` -## Pré-requisitos - ## Configurar cache de esquema Primeiro, você precisa [configurar o cache do esquema do banco de dados](schema/cache.md). diff --git a/docs/internals.md b/docs/internals.md index 6598f764c..ba6f53a30 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -1,6 +1,68 @@ # Internals -- [Testing](./testing.md) +## Unit testing + +This package can be tested globally or individually for each DBMS. + +- [MSSQL](https://github.com/yiisoft/db-mssql) +- [MySQL/MariaDB](https://github.com/yiisoft/db-mysql) +- [Oracle](https://github.com/yiisoft/db-oracle) +- [PostgreSQL](https://github.com/yiisoft/db-pgsql) +- [SQLite](https://github.com/yiisoft/db-sqlite) + +### Github actions + +All our packages have github actions by default, so you can test your [contribution](https://github.com/yiisoft/db/blob/master/.github/CONTRIBUTING.md) in the cloud. + +> Note: We recommend pull requesting in draft mode until all tests pass. + +### Docker images + +For greater ease it is recommended to use Docker containers for each DBMS, for this you can use the [docker-compose.yml](https://docs.docker.com/compose/compose-file/) file that in the root directory of each package. + +- [MSSQL 2022](https://github.com/yiisoft/db-mssql/blob/master/docker-compose.yml) +- [MySQL 8](https://github.com/yiisoft/db-mysql/blob/master/docker-compose.yml) +- [MariaDB 10.11](https://github.com/yiisoft/db-mysql/blob/master/docker-compose-mariadb.yml) +- [Oracle 21](https://github.com/yiisoft/db-oracle/blob/master/docker-compose.yml) +- [PostgreSQL 15](https://github.com/yiisoft/db-pgsql/blob/master/docker-compose.yml) + +For running the Docker containers you can use the following command: + +```shell +docker compose up -d +``` + +### Global testing + +The package is tested with [PHPUnit](https://phpunit.de/). To run tests: + +1. Run all Docker containers for each DBMS. +2. Install the dependencies of the project with composer. +3. Run the tests. + +```shell +./vendor/bin/phpunit +``` + +### Individual testing + +The package is tested with [PHPUnit](https://phpunit.de/). To run tests: + +1. Run the Docker container for the dbms you want to test. +2. Install the dependencies of the project with composer. +3. Run the tests. + +```shell +./vendor/bin/phpunit --testsuite=Pgsql +``` + +Suites available: + +- Mssql +- Mysql +- Oracle +- Pgsql +- Sqlite ## Static analysis diff --git a/docs/testing.md b/docs/testing.md deleted file mode 100644 index fa26b9ab1..000000000 --- a/docs/testing.md +++ /dev/null @@ -1,63 +0,0 @@ -# Testing - -This package can be tested globally or individually for each DBMS. - -- [MSSQL](https://github.com/yiisoft/db-mssql) -- [MySQL/MariaDB](https://github.com/yiisoft/db-mysql) -- [Oracle](https://github.com/yiisoft/db-oracle) -- [PostgreSQL](https://github.com/yiisoft/db-pgsql) -- [SQLite](https://github.com/yiisoft/db-sqlite) - -## Github actions - -All our packages have github actions by default, so you can test your [contribution](https://github.com/yiisoft/db/blob/master/.github/CONTRIBUTING.md) in the cloud. - -> Note: We recommend pull requesting in draft mode until all tests pass. - -## Docker images - -For greater ease it is recommended to use Docker containers for each DBMS, for this you can use the [docker-compose.yml](https://docs.docker.com/compose/compose-file/) file that in the root directory of each package. - -- [MSSQL 2022](https://github.com/yiisoft/db-mssql/blob/master/docker-compose.yml) -- [MySQL 8](https://github.com/yiisoft/db-mysql/blob/master/docker-compose.yml) -- [MariaDB 10.11](https://github.com/yiisoft/db-mysql/blob/master/docker-compose-mariadb.yml) -- [Oracle 21](https://github.com/yiisoft/db-oracle/blob/master/docker-compose.yml) -- [PostgreSQL 15](https://github.com/yiisoft/db-pgsql/blob/master/docker-compose.yml) - -For running the Docker containers you can use the following command: - -```shell -docker compose up -d -``` - -### Global testing - -The following steps are required to run the tests. - -1. Run all Docker containers for each dbms. -2. Install the dependencies of the project with composer. -3. Run the tests. - -```shell -vendor/bin/phpunit -``` - -### Individual testing - -The following steps are required to run the tests. - -1. Run the Docker container for the dbms you want to test. -2. Install the dependencies of the project with composer. -3. Run the tests. - -```shell -vendor/bin/phpunit --testsuite=Pgsql -``` - -Suites available: - -- Mssql -- Mysql -- Oracle -- Pgsql -- Sqlite From 5baf5ab0f7a3969a06b4b28ed8b7cecc9c0156f7 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Fri, 10 May 2024 12:44:41 +0700 Subject: [PATCH 10/14] Remove `AbstractPdoCommand::logQuery()` method (#843) --- CHANGELOG.md | 1 + UPGRADE.md | 9 ++++----- src/Driver/Pdo/AbstractPdoCommand.php | 20 +++----------------- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9548beb53..91186d070 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - Chg #841: Remove `$rawSql` parameter from `AbstractCommand::internalExecute()` method and `AbstractPdoCommand::internalExecute()` method (@Tigrov) - Enh #842: Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method (@Tigrov) +- Enh #843: Remove `AbstractPdoCommand::logQuery()` method (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index c094144fe..ca227c8e7 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,11 +1,9 @@ # Yii Database Upgrading Instructions -> **!!!IMPORTANT!!!** +> **IMPORTANT** > -> The following upgrading instructions are *cumulative*. That is, -> if you want to upgrade from version A to version C and there is -> version B between A and C, you need to following the instructions -> for both A and B. +> The following upgrading instructions are *cumulative*. That is, if you want to upgrade from version A to version C +> and there is version B between A and C, you need to following the instructions for both A and B. ## Upgrade from 1.x to 2.x @@ -68,6 +66,7 @@ $db->createCommand()->insertBatch('user', $values)->execute(); - `AbstractDMLQueryBuilder::getTypecastValue()` - `TableSchemaInterface::compositeForeignKey()` - `Quoter::unquoteParts()` +- `AbstractPdoCommand::logQuery()` ### Remove deprecated parameters diff --git a/src/Driver/Pdo/AbstractPdoCommand.php b/src/Driver/Pdo/AbstractPdoCommand.php index eab69ea87..7a31bba2c 100644 --- a/src/Driver/Pdo/AbstractPdoCommand.php +++ b/src/Driver/Pdo/AbstractPdoCommand.php @@ -252,31 +252,17 @@ protected function internalGetQueryResult(int $queryMode): mixed return $result; } - /** - * Logs the current database query if query logging is on and returns the profiling token if profiling is on. - */ - protected function logQuery(string $rawSql, string $category): void - { - $this->logger?->log(LogLevel::INFO, $rawSql, [$category, 'type' => LogType::QUERY]); - } - protected function queryInternal(int $queryMode): mixed { $logCategory = self::class . '::' . $this->getQueryMode($queryMode); - if ($this->logger !== null) { - $rawSql = $this->getRawSql(); - $this->logQuery($rawSql, $logCategory); - } + $this->logger?->log(LogLevel::INFO, $rawSql = $this->getRawSql(), [$logCategory, 'type' => LogType::QUERY]); $queryContext = new CommandContext(__METHOD__, $logCategory, $this->getSql(), $this->getParams()); - /** - * @psalm-var string $rawSql - * @psalm-suppress RedundantConditionGivenDocblockType - * @psalm-suppress DocblockTypeContradiction - */ + /** @psalm-var string|null $rawSql */ $this->profiler?->begin($rawSql ??= $this->getRawSql(), $queryContext); + /** @psalm-var string $rawSql */ try { /** @psalm-var mixed $result */ $result = parent::queryInternal($queryMode); From ca37aa175f61f3d6010f60096a9d1e9148947630 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Fri, 10 May 2024 15:11:29 +0700 Subject: [PATCH 11/14] Remove `AbstractSchema::normalizeRowKeyCase()` method (#845) --- CHANGELOG.md | 1 + UPGRADE.md | 1 + src/Schema/AbstractSchema.php | 22 ---------------------- tests/Db/Schema/SchemaTest.php | 19 ------------------- 4 files changed, 2 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91186d070..e6a38681e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and `AbstractPdoCommand::internalExecute()` method (@Tigrov) - Enh #842: Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method (@Tigrov) - Enh #843: Remove `AbstractPdoCommand::logQuery()` method (@Tigrov) +- Chg #845: Remove `AbstractSchema::normalizeRowKeyCase()` method (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index ca227c8e7..b25882c84 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -65,6 +65,7 @@ $db->createCommand()->insertBatch('user', $values)->execute(); - `AbstractDMLQueryBuilder::getTypecastValue()` - `TableSchemaInterface::compositeForeignKey()` +- `AbstractSchema::normalizeRowKeyCase()` - `Quoter::unquoteParts()` - `AbstractPdoCommand::logQuery()` diff --git a/src/Schema/AbstractSchema.php b/src/Schema/AbstractSchema.php index 7e13c88f0..54915a9bf 100644 --- a/src/Schema/AbstractSchema.php +++ b/src/Schema/AbstractSchema.php @@ -13,8 +13,6 @@ use Yiisoft\Db\Constraint\IndexConstraint; use Yiisoft\Db\Exception\NotSupportedException; -use function array_change_key_case; -use function array_map; use function gettype; use function is_array; use function preg_match; @@ -529,26 +527,6 @@ protected function getTableTypeMetadata( }; } - /** - * Change row's array key case to lower. - * - * @param array $row Thew row's array or an array of row arrays. - * @param bool $multiple Whether many rows or a single row passed. - * - * @return array The normalized row or rows. - * - * @deprecated Use `array_change_key_case($row)` or `array_map('array_change_key_case', $row)`. - * Will be removed in version 2.0.0. - */ - protected function normalizeRowKeyCase(array $row, bool $multiple): array - { - if ($multiple) { - return array_map(static fn (array $row) => array_change_key_case($row), $row); - } - - return array_change_key_case($row); - } - /** * Resolves the table name and schema name (if any). * diff --git a/tests/Db/Schema/SchemaTest.php b/tests/Db/Schema/SchemaTest.php index 7db253b30..cfd480b8f 100644 --- a/tests/Db/Schema/SchemaTest.php +++ b/tests/Db/Schema/SchemaTest.php @@ -336,25 +336,6 @@ public function testGetViewNames(): void $this->assertSame([], $schema->getViewNames()); } - /** - * @throws ReflectionException - */ - public function testNormaliceRowKeyCase(): void - { - $db = $this->getConnection(); - - $schema = $db->getSchema(); - - $this->assertSame( - ['fk_test' => 1], - Assert::InvokeMethod($schema, 'normalizeRowKeyCase', [['Fk_test' => 1], false]), - ); - $this->assertSame( - ['FK_test' => ['uk_test' => 1]], - Assert::InvokeMethod($schema, 'normalizeRowKeyCase', [['FK_test' => ['UK_test' => 1]], true]), - ); - } - public function testRefreshTableSchema(): void { $db = $this->getConnection(true); From 645b6907e5fdeb002a9b4a188ead63cc72035198 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Fri, 10 May 2024 15:57:22 +0700 Subject: [PATCH 12/14] Remove `SchemaInterface::isReadQuery()` method (#846) --- CHANGELOG.md | 1 + UPGRADE.md | 2 ++ src/Schema/AbstractSchema.php | 9 --------- src/Schema/SchemaInterface.php | 11 ----------- 4 files changed, 3 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6a38681e..d122482a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Enh #842: Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method (@Tigrov) - Enh #843: Remove `AbstractPdoCommand::logQuery()` method (@Tigrov) - Chg #845: Remove `AbstractSchema::normalizeRowKeyCase()` method (@Tigrov) +- Chg #846: Remove `SchemaInterface::isReadQuery()` method (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index b25882c84..a342f7ef4 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -65,6 +65,8 @@ $db->createCommand()->insertBatch('user', $values)->execute(); - `AbstractDMLQueryBuilder::getTypecastValue()` - `TableSchemaInterface::compositeForeignKey()` +- `SchemaInterface::isReadQuery()` +- `AbstractSchema::isReadQuery()` - `AbstractSchema::normalizeRowKeyCase()` - `Quoter::unquoteParts()` - `AbstractPdoCommand::logQuery()` diff --git a/src/Schema/AbstractSchema.php b/src/Schema/AbstractSchema.php index 54915a9bf..368cb8d71 100644 --- a/src/Schema/AbstractSchema.php +++ b/src/Schema/AbstractSchema.php @@ -15,7 +15,6 @@ use function gettype; use function is_array; -use function preg_match; use function preg_replace; use function str_contains; use function str_replace; @@ -314,14 +313,6 @@ public function getTableUniques(string $name, bool $refresh = false): array return is_array($tableUniques) ? $tableUniques : []; } - /** @deprecated Use {@see DbStringHelper::isReadQuery()}. Will be removed in version 2.0.0. */ - public function isReadQuery(string $sql): bool - { - $pattern = '/^\s*(SELECT|SHOW|DESCRIBE)\b/i'; - - return preg_match($pattern, $sql) > 0; - } - /** * @throws InvalidArgumentException */ diff --git a/src/Schema/SchemaInterface.php b/src/Schema/SchemaInterface.php index 73d0893e0..1a5b675c3 100644 --- a/src/Schema/SchemaInterface.php +++ b/src/Schema/SchemaInterface.php @@ -357,17 +357,6 @@ public function getTableSchema(string $name, bool $refresh = false): TableSchema */ public function getTableSchemas(string $schema = '', bool $refresh = false): array; - /** - * Returns a value indicating whether an SQL statement is for read purpose. - * - * @param string $sql The SQL statement. - * - * @return bool Whether an SQL statement is for read purpose. - * - * @deprecated Use {@see DbStringHelper::isReadQuery()}. Will be removed in version 2.0.0. - */ - public function isReadQuery(string $sql): bool; - /** * Refreshes the schema. * From 29902268dc9450130c84240e14138523161c7127 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Fri, 10 May 2024 17:50:53 +0700 Subject: [PATCH 13/14] Remove `SchemaInterface::getRawTableName()` method (#847) --- CHANGELOG.md | 3 ++- UPGRADE.md | 2 ++ src/Schema/AbstractSchema.php | 28 ++++------------------------ src/Schema/SchemaInterface.php | 14 -------------- 4 files changed, 8 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d122482a9..567a7d2e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,8 @@ - Enh #842: Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method (@Tigrov) - Enh #843: Remove `AbstractPdoCommand::logQuery()` method (@Tigrov) - Chg #845: Remove `AbstractSchema::normalizeRowKeyCase()` method (@Tigrov) -- Chg #846: Remove `SchemaInterface::isReadQuery()` method (@Tigrov) +- Chg #846: Remove `SchemaInterface::isReadQuery()` and `AbstractSchema::isReadQuery()` methods (@Tigrov) +- Chg #847: Remove `SchemaInterface::getRawTableName()` and `AbstractSchema::getRawTableName()` methods (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index a342f7ef4..099a5694c 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -67,6 +67,8 @@ $db->createCommand()->insertBatch('user', $values)->execute(); - `TableSchemaInterface::compositeForeignKey()` - `SchemaInterface::isReadQuery()` - `AbstractSchema::isReadQuery()` +- `SchemaInterface::getRawTableName()` +- `AbstractSchema::getRawTableName()` - `AbstractSchema::normalizeRowKeyCase()` - `Quoter::unquoteParts()` - `AbstractPdoCommand::logQuery()` diff --git a/src/Schema/AbstractSchema.php b/src/Schema/AbstractSchema.php index 368cb8d71..3a7e9697c 100644 --- a/src/Schema/AbstractSchema.php +++ b/src/Schema/AbstractSchema.php @@ -15,9 +15,6 @@ use function gettype; use function is_array; -use function preg_replace; -use function str_contains; -use function str_replace; /** * Provides a set of methods for working with database schemas such as creating, modifying, and inspecting tables, @@ -141,18 +138,6 @@ public function getDataType(mixed $data): int }; } - /** @deprecated Use {@see Quoter::getRawTableName()}. Will be removed in version 2.0.0. */ - public function getRawTableName(string $name): string - { - if (str_contains($name, '{{')) { - $name = preg_replace('/{{(.*?)}}/', '\1', $name); - - return str_replace('%', $this->db->getTablePrefix(), $name); - } - - return $name; - } - /** * @throws InvalidArgumentException * @throws NotSupportedException @@ -331,8 +316,7 @@ public function refresh(): void */ public function refreshTableSchema(string $name): void { - /** @psalm-suppress DeprecatedMethod */ - $rawName = $this->getRawTableName($name); + $rawName = $this->db->getQuoter()->getRawTableName($name); unset($this->tableMetadata[$rawName]); @@ -462,8 +446,7 @@ protected function getSchemaMetadata(string $schema, string $type, bool $refresh */ protected function getTableMetadata(string $name, string $type, bool $refresh = false): mixed { - /** @psalm-suppress DeprecatedMethod */ - $rawName = $this->getRawTableName($name); + $rawName = $this->db->getQuoter()->getRawTableName($name); if (!isset($this->tableMetadata[$rawName])) { $this->loadTableMetadataFromCache($rawName); @@ -543,11 +526,8 @@ protected function resolveTableName(string $name): TableSchemaInterface */ protected function setTableMetadata(string $name, string $type, mixed $data): void { - /** - * @psalm-suppress MixedArrayAssignment - * @psalm-suppress DeprecatedMethod - */ - $this->tableMetadata[$this->getRawTableName($name)][$type] = $data; + /** @psalm-suppress MixedArrayAssignment */ + $this->tableMetadata[$this->db->getQuoter()->getRawTableName($name)][$type] = $data; } /** diff --git a/src/Schema/SchemaInterface.php b/src/Schema/SchemaInterface.php index 1a5b675c3..d03341fb4 100644 --- a/src/Schema/SchemaInterface.php +++ b/src/Schema/SchemaInterface.php @@ -269,20 +269,6 @@ public function getDefaultSchema(): string|null; */ public function getDataType(mixed $data): int; - /** - * Returns the actual name of a given table name. - * - * This method will strip off curly brackets from the given table name and replace the percentage character '%' with - * {@see ConnectionInterface::tablePrefix}. - * - * @param string $name The table name to convert. - * - * @return string The real name of the given table name. - * - * @deprecated Use {@see Quoter::getRawTableName()}. Will be removed in version 2.0.0. - */ - public function getRawTableName(string $name): string; - /** * Returns all schema names in the database, except system schemas. * From 0acb116a6a5dbcf04f4619e08a8959cd0a356768 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Sat, 11 May 2024 08:44:39 +0700 Subject: [PATCH 14/14] Improve psalm (#844) --- .github/workflows/static.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 6b3b0fb92..91ee880dd 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -3,18 +3,23 @@ on: paths: - 'src/**' - 'config/**' + - '.github/workflows/static.yml' - 'psalm*.xml' + - 'composer.json' push: paths: - 'src/**' - 'config/**' + - '.github/workflows/static.yml' - 'psalm*.xml' + - 'composer.json' name: static analysis jobs: psalm: + if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.fork }} uses: yiisoft/actions/.github/workflows/psalm.yml@master with: os: >- @@ -22,6 +27,7 @@ jobs: php: >- ['8.1', '8.2'] psalm83: + if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.fork }} uses: yiisoft/actions/.github/workflows/psalm.yml@master with: psalm-config: psalm83.xml