-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Bug: [QueryBuilder] if set limit to 0, it will return all data. Perhaps it should return 0 data. #8278
Comments
Thank you for reporting. This is very interesting.
As I read it, I expect |
What is the practical purpose of doing a query where you don't want any results? I'm not sure that I can think of a reason to do that. Think of it as "there's 0 limit on the number of results I'd like returned." |
This behavior has not changed since the beginning of 4.0. CodeIgniter4/system/Database/BuilderTrait.php Lines 2400 to 2404 in 4d2746f
|
In CI3, the following code generates $jobs = $this->db->limit(0, 0)
->get('job')
->result_array(); // LIMIT
if ($this->qb_limit !== FALSE OR $this->qb_offset)
{
return $this->_limit($sql."\n");
} |
I don't know if this is a bug or not. Since no one has reported it before, there are probably few use cases where 0 is specified. |
I am writing this query in MariaDB: "SELECT * FROM payment limit 0 offset 0" , and it shows no result. So on Ci3, and Ci4 I am expecting $builder->limit(0,0) or $builder->limit($set, $offset) do the same. Maybe, it is not a bug, some query do different depending on database we use. https://dev.mysql.com/doc/refman/8.0/en/limit-optimization.html "LIMIT 0 quickly returns an empty set. This can be useful for checking the validity of a query. It can also be employed to obtain the types of the result columns within applications that use a MySQL API that makes result set metadata available." |
Do you have a use case for limit 0 with Query Builder?
|
If that so, maybe do not change and stick to it. Because on my side it can be fix by adding 1 line of code.
|
if ($quantity === 0) {
return [];
}
$query = $this->db->table('order')->limit($quantity)->offset($offset)->get()->getResultArray(); |
I sent PR #8280 to fix this. |
You can fix this behavior in v4.5.0. See #8280 |
PHP Version
8.2
CodeIgniter4 Version
4
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
Linux
Which server did you use?
fpm-fcgi
Database
MariaDB 10.2.44
What happened?
$builder->limit(0, 0)
, set the limit => 0 and the query will shows all the table rows. It should return no rows because limit is 0.Steps to Reproduce
Expected Output
it should return no rows if it set limit to 0.
Anything else?
No response
The text was updated successfully, but these errors were encountered: