diff --git a/ecrire/public/composer.php b/ecrire/public/composer.php index 6360369390c45287f49d85c0ec855d5123389728..90fab5b2d73e865d25be55e4e0ba4de07d8e39c6 100644 --- a/ecrire/public/composer.php +++ b/ecrire/public/composer.php @@ -499,6 +499,7 @@ function calculer_select ($select = array(), $from = array(), // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln // si elle est seulement utile a Ln+1 elle meme inutile + $sfrom = ''; for($k = count($join); $k > 0; $k--) { list($t,$c) = $join[$k]; $cle = "L$k"; @@ -506,10 +507,11 @@ function calculer_select ($select = array(), $from = array(), OR calculer_jointnul($cle, $select) OR calculer_jointnul($cle, $join) OR calculer_jointnul($cle, $where)) - $where[]= "$t.$c=$cle.$c"; - else { unset($from[$cle]); unset($join[$k]);} + $sfrom = " INNER JOIN " . $from[$cle] . " AS $cle ON $t.$c=$cle.$c" . $sfrom; + else { unset($join[$k]);} + unset($from[$cle]); } - + if ($sfrom) $from[-1] = $sfrom; $GLOBALS['debug']['aucasou'] = array ($table, $id, $serveur); $r = sql_select($select, $from, $where, diff --git a/ecrire/public/criteres.php b/ecrire/public/criteres.php index a0157ba5416cf3557428ed547db9e7d836362ff4..ee3e8059d693e327da905a9ae7b92bbeb4a226ce 100644 --- a/ecrire/public/criteres.php +++ b/ecrire/public/criteres.php @@ -853,13 +853,11 @@ function calculer_jointure(&$boucle, $depart, $arrivee, $col='', $cond=false) function fabrique_jointures(&$boucle, $res, $cond=false, $desc, $nom='', $col='') { - spip_log("fj " . join(',',$res) . ' ' . join(';', $desc)); static $num=array(); $id_table = ""; $cpt = &$num[$boucle->descr['nom']][$boucle->id_boucle]; foreach($res as $r) { list($d, $a, $j) = $r; - spip_log("id $id_table d $d a $a[0] j $j"); if (!$id_table) $id_table = $d; $n = ++$cpt; $boucle->join[$n]= array("'$id_table'","'$j'"); @@ -876,17 +874,14 @@ function fabrique_jointures(&$boucle, $res, $cond=false, $desc, $nom='', $col='' if ($pk = ((count($boucle->from) == 2) && !$cond)) { if ($pk = $a[1]['key']['PRIMARY KEY']) { $id_primary = $desc['key']['PRIMARY KEY']; - spip_log("prim $id_primary $col '$pk'"); $pk = (preg_match("/^$id_primary, *$col$/", $pk) OR preg_match("/^$col, *$id_primary$/", $pk)); } } // la clause Group by est en conflit avec ORDER BY, a completer - spip_log("pj '$pk' '$cond' " . join(',',$boucle->from) . " $desc"); if (!$pk) foreach(liste_champs_jointures($nom,$desc) as $id_prim){ $id_field = $nom . '.' . $id_prim; - spip_log("id_field"); if (!in_array($id_field, $boucle->group)) { $boucle->group[] = $id_field; // postgres exige que le champ pour GROUP soit dans le SELECT diff --git a/ecrire/req/mysql.php b/ecrire/req/mysql.php index 412a2401d81ac138381eec3e38b0c7307d0b1bc8..cb54f2e2bb765a6b09ebbd8bcd3a284623e92b5b 100644 --- a/ecrire/req/mysql.php +++ b/ecrire/req/mysql.php @@ -217,12 +217,16 @@ function calculer_where($v) // http://doc.spip.org/@spip_select_as function spip_select_as($args) { - $argsas = ""; + if (isset($args[-1])) { + $join = ' ' . $args[-1]; + unset($args[-1]); + } else $join =''; + $res = ''; foreach($args as $k => $v) { - if (strpos($v, 'JOIN') === false) $argsas .= ', '; - $argsas .= $v . (is_numeric($k) ? '' : " AS `$k`"); + $res .= ', ' . $v . (is_numeric($k) ? '' : " AS `$k`") . $join; + $join = ''; } - return substr($argsas,2); + return substr($res,2); } //