Skip to content

Commit

Permalink
Merge pull request #4181 from kenjis/fix-getCompiledDelete
Browse files Browse the repository at this point in the history
fix: BaseBuilder::getCompiledDelete() runs real query
  • Loading branch information
samsonasik authored Jan 29, 2021
2 parents 67b0934 + 00b2c3f commit e8a7926
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
5 changes: 2 additions & 3 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2803,9 +2803,8 @@ protected function _truncate(string $table): string
*/
public function getCompiledDelete(bool $reset = true): string
{
$table = $this->QBFrom[0];

$sql = $this->delete($table, null, $reset);
$sql = $this->testMode()->delete('', null, $reset);
$this->testMode(false);

return $this->compileFinalQuery($sql);
}
Expand Down
26 changes: 26 additions & 0 deletions tests/system/Database/Builder/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,30 @@ public function testDelete()
$this->assertEquals($expectedBinds, $builder->getBinds());
}

public function testGetCompiledDelete()
{
$builder = $this->db->table('jobs');

$builder->where('id', 1);
$sql = $builder->getCompiledDelete();

$expectedSQL = <<<'EOL'
DELETE FROM "jobs"
WHERE "id" = 1
EOL;
$this->assertEquals($expectedSQL, $sql);
}

public function testGetCompiledDeleteWithLimit()
{
$builder = $this->db->table('jobs');

$sql = $builder->where('id', 1)->limit(10)->getCompiledDelete();

$expectedSQL = <<<'EOL'
DELETE FROM "jobs"
WHERE "id" = 1 LIMIT 10
EOL;
$this->assertEquals($expectedSQL, $sql);
}
}

0 comments on commit e8a7926

Please sign in to comment.