Skip to content

Commit

Permalink
Truncate sqlite table with prefix (#50251)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitloong authored Feb 26, 2024
1 parent b8b71e0 commit fa1be10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ protected function compileDeleteWithJoinsOrLimit(Builder $query)
public function compileTruncate(Builder $query)
{
return [
'delete from sqlite_sequence where name = ?' => [$query->from],
'delete from sqlite_sequence where name = ?' => [$this->getTablePrefix().$query->from],
'delete from '.$this->wrapTable($query->from) => [],
];
}
Expand Down
17 changes: 17 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3592,6 +3592,23 @@ public function testTruncateMethod()
], $sqlite->compileTruncate($builder));
}

public function testTruncateMethodWithPrefix()
{
$builder = $this->getBuilder();
$builder->getGrammar()->setTablePrefix('prefix_');
$builder->getConnection()->shouldReceive('statement')->once()->with('truncate table "prefix_users"', []);
$builder->from('users')->truncate();

$sqlite = new SQLiteGrammar;
$sqlite->setTablePrefix('prefix_');
$builder = $this->getBuilder();
$builder->from('users');
$this->assertEquals([
'delete from sqlite_sequence where name = ?' => ['prefix_users'],
'delete from "prefix_users"' => [],
], $sqlite->compileTruncate($builder));
}

public function testPreserveAddsClosureToArray()
{
$builder = $this->getBuilder();
Expand Down

0 comments on commit fa1be10

Please sign in to comment.