mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-08 09:05:16 +01:00
possibly more efficient record counting query, and fix limit case on queries that return less than limit
This commit is contained in:
parent
a6247a6191
commit
c02c4f563e
@ -491,31 +491,45 @@
|
||||
$query = ereg_replace('"','',$query);
|
||||
|
||||
$sql = "SELECT * FROM $this->std_table WHERE (";
|
||||
$sqlcount = "SELECT COUNT(id) FROM $this->std_table WHERE (";
|
||||
reset($this->stock_contact_fields);
|
||||
while(list($f,$x) = each($this->stock_contact_fields))
|
||||
{
|
||||
$sql .= " UPPER($f) LIKE UPPER('%$query%') OR ";
|
||||
$sqlcount .= $sql;
|
||||
}
|
||||
$sql = substr($sql,0,-3) . ') ' . $fand . $filtermethod . $ordermethod;
|
||||
$sqlcount = $sql;
|
||||
unset($f); unset($x);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = "SELECT id,lid,tid,owner,access,cat_id $t_fields FROM $this->std_table " . $fwhere
|
||||
. $filtermethod . ' ' . $ordermethod;
|
||||
$sqlcount = "SELECT COUNT(id) FROM $this->std_table " . $fwhere
|
||||
. $filtermethod . ' ' . $ordermethod;
|
||||
}
|
||||
if($DEBUG) { echo '<br>' . $sql; }
|
||||
|
||||
// $db2 = $this->db;
|
||||
copyobj($this->db,$db2);
|
||||
|
||||
$this->db->query($sql,__LINE__,__FILE__);
|
||||
/* Perhaps it is more efficient to count records for this query, which is all we need here */
|
||||
$this->db->query($sqlcount,__LINE__,__FILE__);
|
||||
unset($sqlcount);
|
||||
$this->total_records = $this->db->num_rows();
|
||||
|
||||
if($start && $limit)
|
||||
{
|
||||
if($this->total_records <= $limit)
|
||||
{
|
||||
$this->db->query($sql,__LINE__,__FILE__);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->limit_query($sql,$start,__LINE__,__FILE__,$limit);
|
||||
}
|
||||
}
|
||||
elseif(!$limit)
|
||||
{
|
||||
$this->db->query($sql,__LINE__,__FILE__);
|
||||
@ -536,7 +550,7 @@
|
||||
$return_fields[$i]['cat_id'] = $this->db->f('cat_id');
|
||||
$return_fields[$i]['last_mod'] = $this->db->f('last_mod');
|
||||
|
||||
if (gettype($stock_fieldnames) == 'array')
|
||||
if(@is_array($stock_fieldnames))
|
||||
{
|
||||
while(list($f_name) = each($stock_fieldnames))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user