core
core copied to clipboard
Add CALC_FOUND_ROWS to query builder
I've already added this functionality by adding the following method to Database_Query_Builder_Select class
public function calc_found_rows($value = true)
{
$this->_calc_found_rows = (bool) $value;
return $this;
}
It's pretty simple and usefull when you have to paginate for RESTFul applications.
What exactly is this supposed to do? There is absolutely nothing that uses this property, so why should this be part of the DB layer? Can you provide an explaination and a use-case?
It's a query modifier like 'DISTINCT', It would be usefull to know how many rows would be returned without the where condition/s.
E.g:
$query = DB::select('c.name' , 'c.surname', 'c.age') ->calc_found_rows() ->from(array('customer' , 'c') ->where('c.age', '>', 21);
And then you could call $query->found_rows() which would be a new method too
I'm using it to fill datatables (http://datatables.net/)
I know what CALC_FOUND_ROWS does, but this code snippit just sets a class property, which isn't used anywhere. So this is a but of a nop operation.
Second point is that it's MySQL specific, so it shouldn't belong in a generic driver, unless you intend to implement the actual functionality in the DB drivers, but that is then missing...
Yes you're right, i forgot to mention the use of the property, sorry about that, inside the compile method you do
if ($this->_calc_found_rows === TRUE) { $query.= 'SQL_CALC_FOUND_ROWS '; }
Fuel supports Mysql, Mysqli and PDO, i guess that all of them will work with this method
Unless you're not using MySQL with PDO that is... I don't like to have anything platform specific in the PDO driver.
Yes i agree with you, but i'm not suggesting to put this method in the PDO driver, i guess that it could be added to Database_Query_Builder_Select class wich is generic and already have specific MySQL sintax methods like 'LIMIT' wich won't work with MSSQL or Oracle
One of the reasons we're getting rid of this DB layer.
@FrenkyNet is adding this kind of modifiers already supported in FuelPHP/Database ?