diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index cb55aacdfae..29dd672854d 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -28,6 +28,7 @@ Yii Framework 2 Change Log - Bug #20697: `loadTableIndexes()` includes LOB indexes with `NULL` column names, causing `strpos()` deprecation on PHP `8.1+` (terabytesoftw) - Chg #20757: Remove dead code for PHP < 7.4 in `Security` (WarLikeLaux) - Bug #17254: Fix `MessageController` crash on dynamic input in `Yii::t()` call (CeBe) +- Enh #20765: Return affected row count from `QueryBuilder::executeResetSequence()` (WarLikeLaux) 2.0.54 January 09, 2026 diff --git a/framework/db/Command.php b/framework/db/Command.php index 513a409cb0f..fbd1652d628 100644 --- a/framework/db/Command.php +++ b/framework/db/Command.php @@ -983,6 +983,7 @@ public function resetSequence($table, $value = null) * @param string $table the name of the table whose primary key sequence is reset * @param mixed $value the value for the primary key of the next new row inserted. If this is not set, * the next new row's primary key will have the maximum existing value +1. + * @return int number of rows affected by the execution. * @throws NotSupportedException if this is not supported by the underlying DBMS * @since 2.0.16 */ diff --git a/framework/db/QueryBuilder.php b/framework/db/QueryBuilder.php index e0b87441ae7..9d58bffbaaf 100644 --- a/framework/db/QueryBuilder.php +++ b/framework/db/QueryBuilder.php @@ -1058,12 +1058,13 @@ public function resetSequence($tableName, $value = null) * @param string $table the name of the table whose primary key sequence is reset * @param array|string|null $value the value for the primary key of the next new row inserted. If this is not set, * the next new row's primary key will have the maximum existing value +1. + * @return int number of rows affected by the execution. * @throws NotSupportedException if this is not supported by the underlying DBMS * @since 2.0.16 */ public function executeResetSequence($table, $value = null) { - $this->db->createCommand()->resetSequence($table, $value)->execute(); + return $this->db->createCommand()->resetSequence($table, $value)->execute(); } /** diff --git a/framework/db/oci/QueryBuilder.php b/framework/db/oci/QueryBuilder.php index b1d4d4d155a..cb851ee5eb1 100644 --- a/framework/db/oci/QueryBuilder.php +++ b/framework/db/oci/QueryBuilder.php @@ -164,7 +164,8 @@ public function executeResetSequence($table, $value = null) //Oracle needs at least two queries to reset sequence (see adding transactions and/or use alter method to avoid grants' issue?) $this->db->createCommand('DROP SEQUENCE "' . $tableSchema->sequenceName . '"')->execute(); - $this->db->createCommand('CREATE SEQUENCE "' . $tableSchema->sequenceName . '" START WITH ' . $value + + return $this->db->createCommand('CREATE SEQUENCE "' . $tableSchema->sequenceName . '" START WITH ' . $value . ' INCREMENT BY 1 NOMAXVALUE NOCACHE')->execute(); } diff --git a/tests/framework/db/CommandTest.php b/tests/framework/db/CommandTest.php index 38b5ac5d5b8..c1d02352905 100644 --- a/tests/framework/db/CommandTest.php +++ b/tests/framework/db/CommandTest.php @@ -1658,6 +1658,17 @@ public function testBindValuesSupportsDeprecatedPDOCastingFormat(): void $this->assertTrue(true); } + public function testExecuteResetSequence(): void + { + $db = $this->getConnection(); + + $result = $db->createCommand()->executeResetSequence('item'); + $this->assertIsInt($result); + + $result = $db->createCommand()->executeResetSequence('item', 4); + $this->assertIsInt($result); + } + public function testBindValuesSupportsEnums(): void { if (version_compare(PHP_VERSION, '8.1.0') >= 0) {