Skip to content

Commit 76e0fe1

Browse files
Fix method resetSequence(). (#130)
* Fix method resetSequence().
1 parent 56d7c32 commit 76e0fe1

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/DMLQueryBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ public function __construct(
3535

3636
/**
3737
* @throws Exception|Throwable
38-
*
39-
* @psalm-suppress RiskyCast
4038
*/
41-
public function resetSequence(string $tableName, mixed $value = null): string
39+
public function resetSequence(string $tableName, int|string $value = null): string
4240
{
4341
$table = $this->schema->getTableSchema($tableName);
4442

@@ -47,11 +45,13 @@ public function resetSequence(string $tableName, mixed $value = null): string
4745
}
4846

4947
$sequenceName = $table->getSequenceName();
48+
5049
if ($sequenceName === null) {
5150
throw new InvalidArgumentException("There is not sequence associated with table '$tableName'.'");
5251
}
5352

5453
$tableName = $this->quoter->quoteTableName($tableName);
54+
5555
if ($value !== null) {
5656
$value = "'" . ((int) $value - 1) . "'";
5757
} else {

tests/QueryBuilderTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ public function testResetSequence(): void
278278
$this->assertEquals(1, $result);
279279

280280
// change up
281+
$expected = "UPDATE sqlite_sequence SET seq='0' WHERE name='testCreateTable'";
282+
$sql = $qb->resetSequence('testCreateTable', '1');
283+
$this->assertEquals($expected, $sql);
284+
281285
$expected = "UPDATE sqlite_sequence SET seq='3' WHERE name='testCreateTable'";
282286
$sql = $qb->resetSequence('testCreateTable', 4);
283287
$this->assertEquals($expected, $sql);

0 commit comments

Comments
 (0)