-
Notifications
You must be signed in to change notification settings - Fork 2k
Bug: orderBy method fails afrer and before calling getCompiledSelect #9696
Copy link
Copy link
Closed
Labels
bugVerified issues on the current code behavior or pull requests that will fix themVerified issues on the current code behavior or pull requests that will fix them
Description
PHP Version
8.3
CodeIgniter4 Version
4.6.0, 4.6.3
CodeIgniter4 Installation Method
Composer (as dependency to an existing project)
Which operating systems have you tested for this bug?
Linux
Which server did you use?
cli
Database
both of postgresql and mysql
What happened?
For debugging purpose, I check my SQL with getCompiledSelect(false) of query builder.
Calling orderBy() , getCompiledSelect() , orderBy() failes with TypeError.
Steps to Reproduce
Running code below anywhere (in a basic controller action or spark command)
$con = \Config\Database::connect();
$qb = $con->newQuery();
$qb->select("*")->from("t1");
echo "Calling orderBy() 1 -----\n";
$qb->orderBy("col1","desc");
echo "Calling orderBy() 2 -----\n";
$qb->orderBy("col2","desc");
$sql = $qb->getCompiledSelect(false);
echo "Result of getCompiledSelect() 1: {$sql} \n";
echo "Calling orderBy() 3 -----\n";
$qb->orderBy("col3","desc");
$sql = $qb->getCompiledSelect(false);
echo "Result of getCompiledSelect() 2: {$sql} \n";then it fails with error:
[TypeError]
array_merge(): Argument #1 must be of type array, string given
at SYSTEMPATH/Database/BaseBuilder.php:1506
Backtrace:
1 SYSTEMPATH/Database/BaseBuilder.php:1506
array_merge('
ORDER BY `col1` DESC, `col2` DESC', [...])
When I remove getCompiledSelect() 1 or orderBy() 1 and orderBy() 2 or orderBy() 3,
It runs as expected and no error occurs.
Expected Output
Calling orderBy() 1 -----
Calling orderBy() 2 -----
Result of getCompiledSelect() 1: SELECT * FROM `t1` ORDER BY `col1` DESC, `col2` DESC
Calling orderBy() 3 -----
Result of getCompiledSelect() 2: SELECT * FROM `t1` ORDER BY `col1` DESC, `col2` DESC, `col3` DESC
Anything else?
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugVerified issues on the current code behavior or pull requests that will fix themVerified issues on the current code behavior or pull requests that will fix them