Skip to content

Commit

Permalink
Merge pull request #2802 from michalsn/feature/qb_from_reset
Browse files Browse the repository at this point in the history
Add resetting QBFrom part
  • Loading branch information
lonnieezell authored Apr 6, 2020
2 parents 241a54e + 654b915 commit 1092399
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3328,6 +3328,12 @@ protected function resetSelect()
{
$this->db->setAliasedTables([]);
}

// Reset QBFrom part
if (! empty($this->QBFrom))
{
$this->from(array_shift($this->QBFrom), true);
}
}

//--------------------------------------------------------------------
Expand Down
29 changes: 29 additions & 0 deletions tests/system/Database/Builder/FromTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,33 @@ public function testFromWithMultipleTablesAsString()
}

//--------------------------------------------------------------------

public function testFromReset()
{
$builder = new BaseBuilder('user', $this->db);

$builder->from(['jobs', 'roles']);

$expectedSQL = 'SELECT * FROM "user", "jobs", "roles"';

$this->assertEquals($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));

$expectedSQL = 'SELECT * FROM "user"';

$this->assertEquals($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));

$expectedSQL = 'SELECT *';

$builder->from(null, true);

$this->assertEquals($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));

$expectedSQL = 'SELECT * FROM "jobs"';

$builder->from('jobs');

$this->assertEquals($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));
}

//--------------------------------------------------------------------
}

0 comments on commit 1092399

Please sign in to comment.