Skip to content

Commit

Permalink
Fix multi-column WHERE not prefixed with DBPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Usman authored and musmanikram committed Feb 9, 2020
1 parent 1514be2 commit aef1e64
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3045,6 +3045,11 @@ protected function compileWhereHaving(string $qb_key): string

if (! empty($matches[4]))
{
if (strpos($matches[4], '.') !== false)
{
$matches[4] = $this->db->protectIdentifiers(trim($matches[4]));
}

$matches[4] = ' ' . $matches[4];
}

Expand Down
15 changes: 15 additions & 0 deletions tests/system/Database/Builder/PrefixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,19 @@ public function testPrefixesSetOnTableNames()

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

public function testPrefixesSetOnTableNamesWithWhereClause()
{
$builder = $this->db->table('users');

$where = 'users.created_at < users.updated_at';

$expectedSQL = 'SELECT * FROM "ci_users" WHERE "ci_users"."created_at" < "ci_users"."updated_at"';
$expectedBinds = [];

$builder->where($where);

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

}

0 comments on commit aef1e64

Please sign in to comment.