From e302b12f650a96be8f39b23443d10e547b137364 Mon Sep 17 00:00:00 2001
From: "Committo,Ergo:sum" <esj@rezo.net>
Date: Sun, 5 Mar 2006 21:27:35 +0000
Subject: [PATCH] =?UTF-8?q?Jointures=20sur=20tables=20externes=20demand?=
 =?UTF-8?q?=C3=A9es=20par=20#113?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ecrire/public/criteres.php | 45 +++++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 18 deletions(-)

diff --git a/ecrire/public/criteres.php b/ecrire/public/criteres.php
index 7dd6b0cdec..6547bdd292 100644
--- a/ecrire/public/criteres.php
+++ b/ecrire/public/criteres.php
@@ -660,28 +660,37 @@ function trouver_cles_table($keys)
 
 function trouver_def_table($nom, &$boucle)
 {
-  global $tables_principales, $tables_auxiliaires, $table_des_tables, $tables_des_serveurs_sql;
+	global $tables_principales, $tables_auxiliaires, $table_des_tables, $tables_des_serveurs_sql;
 
-  if ($desc = $tables_principales['spip_' . $nom])
-    return array('spip_' . $nom, $desc);
+	spip_log("tdt $nom");
+	$nom_table = $nom;
+	$s = $boucle->sql_serveur;
+	if (!$s) {
+		 $s = 'localhost';
+    // indirection (pour les rares cas ou le nom de la table!=type)
+		 if (in_array($nom, $table_des_tables))
+		   $nom_table = (($GLOBALS['table_prefix'] ? $GLOBALS['table_prefix'] : 'spip') . '_' . $nom);
 
-  if ($boucle->sql_serveur && 
-      $desc = $tables_des_serveurs_sql[$boucle->sql_serveur][$nom])
-    return array($nom, $desc);
-  include_spip('base/auxiliaires');
-  if ($desc = $tables_auxiliaires['spip_' . $nom])
-    return array('spip_' . $nom, $desc);
+	}
+
+	$desc = $tables_des_serveurs_sql[$s][$nom_table];
+	if ($desc)
+		return array($nom_table, $desc);
 
-  $desc = $table_des_tables[$nom] ?  (($GLOBALS['table_prefix'] ? $GLOBALS['table_prefix'] : 'spip') . '_' . $nom) : $nom;
-  if ($desc = spip_abstract_showtable($desc, $boucle->sql_serveur))
-    if (isset($desc['field'])) {
+	include_spip('base/auxiliaires');
+	$nom_table = (($GLOBALS['table_prefix'] ? $GLOBALS['table_prefix'] : 'spip') . '_' . $nom);
+	if ($desc = $tables_auxiliaires[$nom_table])
+		return array($nom_table, $desc);
+
+	if ($desc = spip_abstract_showtable($nom, $boucle->sql_serveur))
+	  if (isset($desc['field'])) {
       // faudrait aussi prevoir le cas du serveur externe
-      $tables_principales[$nom] = $desc;
-      return array($nom, $desc);
-    }
-  erreur_squelette(_T('zbug_table_inconnue', array('table' => $nom)),
-		   $boucle->id_boucle);
-}
+	    $tables_principales[$nom] = $desc;
+	    return array($nom, $desc);
+	  }
+	erreur_squelette(_T('zbug_table_inconnue', array('table' => $nom)),
+			 $boucle->id_boucle);
+	}
 
 function trouver_champ_exterieur($cle, $joints, &$boucle)
 {
-- 
GitLab