N°3907 - Polishing: Run query

This commit is contained in:
acognet
2021-08-02 18:56:07 +02:00
parent e28f704f3e
commit 3130e95f4f
5 changed files with 47 additions and 13 deletions

View File

@@ -389,14 +389,16 @@ class SQLObjectQuery extends SQLQuery
if (count($this->__aSelectedIdFields) > 0)
{
$aCountFields = array();
foreach ($this->__aSelectedIdFields as $sFieldExpr)
{
$aCountFields[] = "COALESCE($sFieldExpr, 0)"; // Null values are excluded from the count
$i = 0;
foreach ($this->__aSelectedIdFields as $sFieldExpr) {
$aCountFields[] = "COALESCE($sFieldExpr, 0) AS idCount$i"; // Null values are excluded from the count
$aCountI[] = 'idCount'.$i++;
}
$sCountFields = implode(', ', $aCountFields);
$sCountI = implode('+ ', $aCountI);
// Count can be limited for performance reason, in this case the total amount is not important,
// we only need to know if the number of entries is greater than a certain amount.
$sSQL = "SELECT COUNT(*) AS COUNT FROM (SELECT$sLineSep DISTINCT $sCountFields $sLineSep FROM $sFrom$sLineSep WHERE $sWhere $sLimit) AS _alderaan_";
$sSQL = "SELECT COUNT(*) AS COUNT FROM (SELECT$sLineSep DISTINCT $sCountFields $sLineSep FROM $sFrom$sLineSep WHERE $sWhere $sLimit) AS _alderaan_ WHERE $sCountI>0";
}
else
{