Skip to content

Commit

Permalink
fix: select() may cause TypeError
Browse files Browse the repository at this point in the history
TypeError: trim(): Argument #1 ($string) must be of type string, CodeIgniter\Database\RawSql given
  • Loading branch information
kenjis committed Jun 27, 2024
1 parent 43ce135 commit 1962e8c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public function ignore(bool $ignore = true)
/**
* Generates the SELECT portion of the query
*
* @param array|RawSql|string $select
* @param list<RawSql|string>|RawSql|string $select
*
* @return $this
*/
Expand All @@ -402,16 +402,21 @@ public function select($select = '*', ?bool $escape = null)
}

if ($select instanceof RawSql) {
$this->QBSelect[] = $select;

return $this;
$select = [$select];
}

if (is_string($select)) {
$select = $escape === false ? [$select] : explode(',', $select);
$select = ($escape === false) ? [$select] : explode(',', $select);
}

foreach ($select as $val) {
if ($val instanceof RawSql) {
$this->QBSelect[] = $val;
$this->QBNoEscape[] = false;

continue;
}

$val = trim($val);

if ($val !== '') {
Expand Down

0 comments on commit 1962e8c

Please sign in to comment.