Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Truncate sqlite table name with prefix #50251

Merged
merged 1 commit into from
Feb 26, 2024
Merged
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
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
Loading