Skip to content

Commit 1962e8c

Browse files
committed
fix: select() may cause TypeError
TypeError: trim(): Argument #1 ($string) must be of type string, CodeIgniter\Database\RawSql given
1 parent 43ce135 commit 1962e8c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

system/Database/BaseBuilder.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ public function ignore(bool $ignore = true)
390390
/**
391391
* Generates the SELECT portion of the query
392392
*
393-
* @param array|RawSql|string $select
393+
* @param list<RawSql|string>|RawSql|string $select
394394
*
395395
* @return $this
396396
*/
@@ -402,16 +402,21 @@ public function select($select = '*', ?bool $escape = null)
402402
}
403403

404404
if ($select instanceof RawSql) {
405-
$this->QBSelect[] = $select;
406-
407-
return $this;
405+
$select = [$select];
408406
}
409407

410408
if (is_string($select)) {
411-
$select = $escape === false ? [$select] : explode(',', $select);
409+
$select = ($escape === false) ? [$select] : explode(',', $select);
412410
}
413411

414412
foreach ($select as $val) {
413+
if ($val instanceof RawSql) {
414+
$this->QBSelect[] = $val;
415+
$this->QBNoEscape[] = false;
416+
417+
continue;
418+
}
419+
415420
$val = trim($val);
416421

417422
if ($val !== '') {

0 commit comments

Comments
 (0)