Skip to content
Open
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
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Yii Framework 2 Change Log
- Bug #20764: Fix `@return` annotation for `Model::rules()` (mspirkov)
- 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)
- Enh #20765: Return affected row count from `QueryBuilder::executeResetSequence()` (WarLikeLaux)


2.0.54 January 09, 2026
Expand Down
1 change: 1 addition & 0 deletions framework/db/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
3 changes: 2 additions & 1 deletion framework/db/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion framework/db/oci/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
11 changes: 11 additions & 0 deletions tests/framework/db/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading