You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: [QueryBuilder] join() with BETWEEN causes TypeError preg_quote(): Argument #1 ($str) must be of type string, false given #8791
Which operating systems have you tested for this bug?
Windows, Linux
Which server did you use?
apache
Database
MariaDB 11.2.3
What happened?
After upgrading to 4.5.0 and then 4.5.1, I am now getting TypeError preg_quote(): Argument #1 ($str) must be of type string, false given at SYSTEMPATH/Database/BaseBuilder.php at line 680 with some of my SQL queries. These queries all use the BETWEEN Operator to compare dates.
These queries worked perfectly fine going all the way back to CI 4.0.x up through 4.4.8.
Below is a screenshot of the error:
Steps to Reproduce
Execute an SQL query created using the Query Builder Class utilizing the BETWEEN operator.
I probably did not phrase the bug report correctly. I have two SQL queries that have worked perfectly from CI version 4.0.x all the way through 4.4.8. Both of these queries are constructed using the Query Builder Class. Here are the lines from each Query Builder that appear to be throwing the type error:
->join('leases', 'units.unit_id = leases.unit_id AND CURDATE() BETWEEN lease_start_date AND lease_exp_date', 'left')
->join('leases', 'units.unit_id = leases.unit_id AND workorder_start BETWEEN lease_start_date AND lease_exp_date', 'left')
The only common thread seems to be the use of the BETWEEN SQL operator. I'm not sure that has anything to do with it.
It does seem to be an issue in Query Builder because it no longer puts together the query without throwing an error.
It could simply be a strict typing issue like some of the other 4.5.0 bugs, but I will do some further troubleshooting.
changed the title [-]Bug: TypeError preg_quote(): Argument #1 ($str) must be of type string, false given[/-][+]Bug: [QueryBuilder] join() with BETWEEN causes TypeError preg_quote(): Argument #1 ($str) must be of type string, false given[/+]on Apr 15, 2024
I replaced the BETWEEN operators in my JOIN clauses with a combination of >= and <= operators to workaround this limitation with Query Builder.
This project also has many WHERE clauses constructed by Query Builder utilizing the BETWEEN operator that are still working as expected in 4.5.1. Does where() officially support BETWEEN or is is this also working by accident?
If $escape is set to false, the value as is becomes a part of the SQL statement, so you can freely create SQL statements, but QueryBuilder does not provide any protection/escaping.
Activity
kenjis commentedon Apr 15, 2024
How do we reproduce?
It seems Query Builder does not support BETWEEN.
https://codeigniter4.github.io/CodeIgniter4/database/query_builder.html
oakhurstmgmt commentedon Apr 15, 2024
I probably did not phrase the bug report correctly. I have two SQL queries that have worked perfectly from CI version 4.0.x all the way through 4.4.8. Both of these queries are constructed using the Query Builder Class. Here are the lines from each Query Builder that appear to be throwing the type error:
->join('leases', 'units.unit_id = leases.unit_id AND CURDATE() BETWEEN lease_start_date AND lease_exp_date', 'left')->join('leases', 'units.unit_id = leases.unit_id AND workorder_start BETWEEN lease_start_date AND lease_exp_date', 'left')The only common thread seems to be the use of the BETWEEN SQL operator. I'm not sure that has anything to do with it.
It does seem to be an issue in Query Builder because it no longer puts together the query without throwing an error.
It could simply be a strict typing issue like some of the other 4.5.0 bugs, but I will do some further troubleshooting.
kenjis commentedon Apr 15, 2024
Thank you for the feedback.
There is no sample code with
BETWEENinjoin().https://codeigniter4.github.io/CodeIgniter4/database/query_builder.html#join
and there is no test case:
https://github.com/codeigniter4/CodeIgniter4/blob/develop/tests/system/Database/Builder/JoinTest.php
We need further investigation.
[-]Bug: TypeError preg_quote(): Argument #1 ($str) must be of type string, false given[/-][+]Bug: [QueryBuilder] join() with BETWEEN causes TypeError preg_quote(): Argument #1 ($str) must be of type string, false given[/+]kenjis commentedon Apr 16, 2024
It seems
join()does not supportBETWEEN, but it worked by accident in previous versions.When there is a conditon
'units.unit_id = leases.unit_id AND CURDATE() BETWEEN lease_start_date AND lease_exp_date', it is parsed in$conditionsasbut it is of course wrong.
Fixing this behavior is difficult, so I sent ad hoc fix PR #8792
oakhurstmgmt commentedon Apr 16, 2024
Ahh, I understand now.
I replaced the
BETWEENoperators in myJOINclauses with a combination of>=and<=operators to workaround this limitation with Query Builder.This project also has many
WHEREclauses constructed by Query Builder utilizing theBETWEENoperator that are still working as expected in 4.5.1. Doeswhere()officially supportBETWEENor is is this also working by accident?kenjis commentedon Apr 16, 2024
There is one test case.
CodeIgniter4/tests/system/Database/Builder/WhereTest.php
Lines 198 to 210 in d425bdf
But note that uses
falsein the third parameter$escape:CodeIgniter4/tests/system/Database/Builder/WhereTest.php
Line 203 in d425bdf
If
$escapeis set to false, the value as is becomes a part of the SQL statement, so you can freely create SQL statements, but QueryBuilder does not provide any protection/escaping.kenjis commentedon Apr 28, 2024
@oakhurstmgmt If you agree to merge #8792, approve the PR.