Skip to content
Extraits de code Groupes Projets
Valider 38c663c1 rédigé par esj's avatar esj
Parcourir les fichiers

#209: comme l'avait prévu [9859], autre cas de nombres à ne pas entourer...

#209: comme l'avait prévu [9859], autre cas de nombres à ne pas entourer d'apostrophies, les clés de jointure. Il a fallu réfléchir longtemps, mais le changement est minimal, preuve que le compilateur a les bons utilitaires c'est rassurant.

Aussi dans ce dépot, quelques corrections  dans l'inteface PG:
	° [9861] était vraiment à l'arraché, il ne fallait pas oublier de supprimer les AS ingjctés dans le GROUPBY;
	* traitement du HAVING par la fonction pour PG pas pour MySQL;
	* inclusion inopérante du débusqueur.
parent f42f88a8
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -90,7 +90,7 @@ function spip_pg_select($select, $from, $where,
(!is_array($from) ? $from : spip_pg_select_as($from))))
. (!$where ? '' : ("\nWHERE " . (!is_array($where) ? $where : (join("\n\tAND ", array_map('calculer_pg_where', $where))))))
. spip_pg_groupby($groupby, $from, $select)
. (!$having ? '' : "\nHAVING " . (!is_array($having) ? $having : (join("\n\tAND ", array_map('calculer_where', $having)))))
. (!$having ? '' : "\nHAVING " . (!is_array($having) ? $having : (join("\n\tAND ", array_map('calculer_pg_where', $having)))))
. ($orderby ? ("\nORDER BY " . spip_pg_nocast($orderby)) :'')
. (!$limit ? '' : (" LIMIT $count" . (!$offset ? '' : " OFFSET $offset")));
$q = " SELECT ". $q;
......@@ -100,6 +100,7 @@ function spip_pg_select($select, $from, $where,
// actuellement dans erreur_requete_boucle
if ($GLOBALS['var_mode'] == 'debug') {
include_spip('public/debug');
boucle_debug_resultat($id, '', $q);
}
......@@ -121,7 +122,8 @@ function spip_pg_groupby($groupby, $from, $select)
$join = is_array($from) ? (count($from) > 1) : strpos($from, ",");
if ($join) $join = !is_array($select) ? $select : join(", ", $select);
if ($join) $groupby = $groupby ? "$groupby, $join" : $join;
return ($groupby ? "\nGROUP BY $groupby" : '');
$groupby = preg_replace('/\s+AS\s+\w+/','', $groupby);
return (!$groupby ? '' : ("\nGROUP BY " . spip_pg_nocast($groupby)));
}
// 0+x avec un champ x commencant par des chiffres est converti par MySQL
......
......@@ -341,7 +341,7 @@ function calculer_dump_array($a)
function calculer_dump_join($a)
{
$res = "";
foreach($a as $k => $v) $res .= ", $k => array('$v[0]', '$v[1]')";
foreach($a as $k => $v) $res .= ", $k => array($v[0], $v[1])";
return 'array(' . substr($res,2) . ')';
}
......
......@@ -859,7 +859,10 @@ function trouver_champ($champ, $where)
}
}
// deduction automatique des jointures
// deduction automatique d'une chaine de jointures
// Pour chaque cle de jointure il faut regarder si le type est numerique
// car PG ne veut pas d'apostrophe
// http://doc.spip.org/@calculer_jointure
function calculer_jointure(&$boucle, $depart, $arrivee, $col='', $cond=false)
{
......@@ -873,8 +876,10 @@ function calculer_jointure(&$boucle, $depart, $arrivee, $col='', $cond=false)
$cpt = &$num[$boucle->descr['nom']][$boucle->id_boucle];
foreach($res as $r) {
list($d, $a, $j) = $r;
if (!$id_table) $id_table = $d;
$type = $a[1]['field'][$j];
$n = ++$cpt;
$boucle->join[$n]= array(($id_table ? $id_table : $d), $j);
$boucle->join[$n]= array("'$id_table'", test_sql_int($type) ? $j : "'$j'");
$boucle->from[$id_table = "L$n"] = $a[0];
}
......@@ -1119,17 +1124,20 @@ function calculer_critere_infixe_ops($idb, &$boucles, $crit)
if ($op == '=' OR in_array($op, $table_criteres_infixes)) {
list($nom, $desc) = trouver_def_table($boucles[$idb]->id_table, $boucles[$idb]);
$type = $desc['field'][$col];
if (strpos($val[0], '_q(') === 0
AND (strpos($type, 'bigint') === 0
OR strpos($type, 'int') === 0
OR strpos($type, 'tinyint') === 0))
$val[0] = 'intval' . substr($val[0],2);
if (strpos($val[0], '_q(') === 0 AND test_sql_int($type))
$val[0] = 'intval' . substr($val[0],2);
}
return array($fct, $col, $op, $val, $args_sql);
}
function test_sql_int($type)
{
return (strpos($type, 'bigint') === 0
OR strpos($type, 'int') === 0
OR strpos($type, 'tinyint') === 0);
}
// compatibilite ancienne version
// http://doc.spip.org/@calculer_vieux_in
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter