Skip to content

Commit fa1be10

Browse files
authored
Truncate sqlite table with prefix (#50251)
1 parent b8b71e0 commit fa1be10

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ protected function compileDeleteWithJoinsOrLimit(Builder $query)
387387
public function compileTruncate(Builder $query)
388388
{
389389
return [
390-
'delete from sqlite_sequence where name = ?' => [$query->from],
390+
'delete from sqlite_sequence where name = ?' => [$this->getTablePrefix().$query->from],
391391
'delete from '.$this->wrapTable($query->from) => [],
392392
];
393393
}

tests/Database/DatabaseQueryBuilderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3592,6 +3592,23 @@ public function testTruncateMethod()
35923592
], $sqlite->compileTruncate($builder));
35933593
}
35943594

3595+
public function testTruncateMethodWithPrefix()
3596+
{
3597+
$builder = $this->getBuilder();
3598+
$builder->getGrammar()->setTablePrefix('prefix_');
3599+
$builder->getConnection()->shouldReceive('statement')->once()->with('truncate table "prefix_users"', []);
3600+
$builder->from('users')->truncate();
3601+
3602+
$sqlite = new SQLiteGrammar;
3603+
$sqlite->setTablePrefix('prefix_');
3604+
$builder = $this->getBuilder();
3605+
$builder->from('users');
3606+
$this->assertEquals([
3607+
'delete from sqlite_sequence where name = ?' => ['prefix_users'],
3608+
'delete from "prefix_users"' => [],
3609+
], $sqlite->compileTruncate($builder));
3610+
}
3611+
35953612
public function testPreserveAddsClosureToArray()
35963613
{
35973614
$builder = $this->getBuilder();

0 commit comments

Comments
 (0)