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

fix: [QueryBuilder] RawSql causes error when using like() and countAllResults() #7277

Merged
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
4 changes: 4 additions & 0 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3082,6 +3082,10 @@ protected function compileWhereHaving(string $qbKey): string
continue;
}

if ($qbkey instanceof RawSql) {
continue;
}

if ($qbkey['condition'] instanceof RawSql) {
$qbkey = $qbkey['condition'];

Expand Down
43 changes: 43 additions & 0 deletions tests/system/Database/Live/LikeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace CodeIgniter\Database\Live;

use CodeIgniter\Database\RawSql;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\DatabaseTestTrait;
use Tests\Support\Database\Seeds\CITestSeeder;
Expand Down Expand Up @@ -121,4 +122,46 @@ public function testLikeSpacesOrTabs()
$this->assertCount(1, $spaces);
$this->assertCount(1, $tabs);
}

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/7268
*/
public function testLikeRawSqlAndCountAllResultsAndGet()
{
$builder = $this->db->table('job');

if ($this->db->DBDriver === 'OCI8') {
$key = new RawSql('"name"');
} else {
$key = new RawSql('name');
}

$builder->like($key, 'Developer');
$count = $builder->countAllResults(false);
$results = $builder->get()->getResult();

$this->assertSame(1, $count);
$this->assertSame('Developer', $results[0]->name);
}

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/7268
*/
public function testLikeRawSqlAndGetAndCountAllResults()
{
$builder = $this->db->table('job');

if ($this->db->DBDriver === 'OCI8') {
$key = new RawSql('"name"');
} else {
$key = new RawSql('name');
}

$builder->like($key, 'Developer');
$results = $builder->get(null, 0, false)->getResult();
$count = $builder->countAllResults();

$this->assertSame(1, $count);
$this->assertSame('Developer', $results[0]->name);
}
}