diff --git a/ecrire/base/abstract_sql.php b/ecrire/base/abstract_sql.php index 12401714d2dd24e6ae30c9e7584958135db8ade1..6b4f22ffe8731afe74a69b57097e83739c09040c 100644 --- a/ecrire/base/abstract_sql.php +++ b/ecrire/base/abstract_sql.php @@ -54,7 +54,7 @@ function spip_abstract_select ( } } return $f($select, $from, $where, - $groupby, array_filter($orderby), $limit, + $groupby, $orderby, $limit, $sousrequete, $cpt, $table, $id, $serveur); } diff --git a/ecrire/base/db_mysql.php b/ecrire/base/db_mysql.php index e900073fffae167cc146a161685a3eb7f705b680..f32a82758dec5fee1ccc3cdd1b9dba0ffc46b921 100644 --- a/ecrire/base/db_mysql.php +++ b/ecrire/base/db_mysql.php @@ -78,9 +78,6 @@ function spip_mysql_select($select, $from, $where, $sousrequete, $having, $table, $id, $serveur) { - foreach($where as $k => $v) - { if (!$v) unset($where[$k]);} - $q = ($from ? ("\nFROM " . join(",\n\t", $from)) : '') . ($where ? ("\nWHERE " . join("\n\tAND ", $where)) : '') . ($groupby ? "\nGROUP BY $groupby" : '') diff --git a/ecrire/public/calcul-outils.php b/ecrire/public/calcul-outils.php index e6b944186cd85430ccb06fdd7c6b1bc7b0c5097a..175bd9aea1898da1da0f20c092e36194cbd663d3 100644 --- a/ecrire/public/calcul-outils.php +++ b/ecrire/public/calcul-outils.php @@ -543,4 +543,21 @@ function lang_parametres_forum($s) { return $s; } +// La fonction presente dans les squelettes compiles + +function spip_optim_select ($select = array(), $from = array(), + $where = array(), $join=array(), + $groupby = '', $orderby = array(), $limit = '', + $sousrequete = '', $cpt = '', + $table = '', $id = '', $serveur='') { + + foreach($where as $k => $v) { if (!$v) unset($where[$k]);} + $where = array_merge($where, $join); + + return spip_abstract_select($select, $from, $where, + $groupby, array_filter($orderby), $limit, + $sousrequete, $cpt, + $table, $id, $serveur); + +} ?> diff --git a/ecrire/public/compilo.php b/ecrire/public/compilo.php index 1e853f0427f62388ecacc006462283dd22d962a8..990c78f0cd4beb834800304e97cea31c464ff809 100644 --- a/ecrire/public/compilo.php +++ b/ecrire/public/compilo.php @@ -257,7 +257,7 @@ function calculer_requete_sql(&$boucle) return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') . $boucle->hash . "\n\n // REQUETE - \$result = spip_abstract_select(\n\t\tarray(\"" . + \$result = spip_optim_select(\n\t\tarray(\"" . # En absence de champ c'est un decompte : # prendre une constante pour avoir qqch (!$boucle->select ? 1 : @@ -265,12 +265,16 @@ function calculer_requete_sql(&$boucle) '"), # SELECT ' . calculer_from($boucle) . ', # FROM - ' . calculer_where($boucle) . - ', # WHERE + array(' . + ($boucle->where ? ('"'. join('", "', $boucle->where) . '"') : '') . + '), # WHERE + array(' . + ($boucle->join ? ('"'. join('", "', $boucle->join) . '"') : '') . + '), # WHERE pour jointure ' . (!$boucle->group ? "''" : ('"' . join(", ", $boucle->group)) . '"') . - ", # GROUP - array(" . + ', # GROUP + array(' . join(', ', $order) . "), # ORDER " . (strpos($boucle->limit, 'intval') === false ? @@ -291,15 +295,6 @@ function calculer_from(&$boucle) return 'array(' . substr($res,3) . '")'; } -function calculer_where(&$boucle) -{ - $w = array_merge($boucle->where, $boucle->join); - return 'array(' . - (!$w ? '' : ( '"' . join('", - "', $w) . '"')) . - ")"; -} - // // fonction traitant les criteres {1,n} (analyses dans inc-criteres) //