diff --git a/ecrire/base/abstract_sql.php b/ecrire/base/abstract_sql.php index 6f75179552e3b3e77ffa1253050e7ad478172fac..c64d415655b14c5be2a7d1124631ad48026284f0 100644 --- a/ecrire/base/abstract_sql.php +++ b/ecrire/base/abstract_sql.php @@ -202,7 +202,7 @@ function sql_showbase($spip=NULL, $serveur='') } // http://doc.spip.org/@sql_showtable -function sql_showtable($table, $serveur='', $table_spip = false) +function sql_showtable($table, $table_spip = false, $serveur='') { if ($table_spip){ $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; @@ -323,8 +323,9 @@ function sql_in($val, $valeurs, $not='', $serveur='') { return $f($val, $valeurs, $not, $serveur); } + // http://doc.spip.org/@sql_test_int -function sql_test_int($type) +function sql_test_int($type, $serveur='') { return (preg_match('/^bigint/i',$type) OR preg_match('/^int/i',$type) @@ -332,7 +333,7 @@ function sql_test_int($type) } // http://doc.spip.org/@sql_test_date -function sql_test_date($type) +function sql_test_date($type, $serveur='') { return (preg_match('/^datetime/i',$type) OR preg_match('/^timestamp/i',$type)); diff --git a/ecrire/base/trouver_table.php b/ecrire/base/trouver_table.php index 19d374634d1183312b0f89538b3bdf47a2cf1e7f..d41ddc5240dc436721c78e0c6be0b6ce3b2dc18f 100644 --- a/ecrire/base/trouver_table.php +++ b/ecrire/base/trouver_table.php @@ -27,7 +27,7 @@ if (!defined("_ECRIRE_INC_VERSION")) return; // http://doc.spip.org/@base_trouver_table_dist function base_trouver_table_dist($nom, $serveur='') { - global $tables_principales, $tables_auxiliaires, $table_des_tables, $connexions; + global $tables_principales, $tables_auxiliaires, $table_des_tables; if (!spip_connect($serveur) OR !preg_match('/^[a-zA-Z0-9._-]+/',$nom)) @@ -36,18 +36,15 @@ function base_trouver_table_dist($nom, $serveur='') if (preg_match('/\.(.*)$/', $nom, $s)) $nom_sql = $s[1]; else $nom_sql = $nom; - $s = $serveur ? $serveur : 0; - - if ($connexions[$s]['spip_connect_version']) { + $desc = ''; + $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; + // base sous SPIP: gerer les abreviations des noms de table + if ($connexion['spip_connect_version']) { include_spip('public/interfaces'); - // base sous SPIP, le nom SQL peut etre autre if (isset($table_des_tables[$nom])) { - // indirection (table principale avec nom!=type) $t = $table_des_tables[$nom]; $nom_sql = 'spip_' . $t; - if (isset($connexions[$s]['tables'][$nom_sql])) - return $connexions[$s]['tables'][$nom_sql]; - else { + if (!isset($connexion['tables'][$nom_sql])) { include_spip('base/serial'); $desc = $tables_principales[$nom_sql]; $nom = $t; @@ -56,27 +53,26 @@ function base_trouver_table_dist($nom, $serveur='') include_spip('base/auxiliaires'); if (isset($tables_auxiliaires['spip_' .$nom])) { $nom_sql = 'spip_' . $nom; - if (isset($connexions[$s]['tables'][$nom_sql])) - return $connexions[$s]['tables'][$nom_sql]; - else { - $desc = $tables_auxiliaires[$nom_sql]; + if (!isset($connexion['tables'][$nom_sql])) { + $desc = $tables_auxiliaires[$nom_sql]; } } # table locale a cote de SPIP, comme non SPIP: } } - if (!isset($connexions[$s]['tables'][$nom_sql])) { - - $desc = sql_showtable($nom_sql, $serveur, ($nom_sql != $nom)); - if (!$desc OR !$desc['field']) { - spip_log("table inconnue $serveur $nom"); - return null; + if (!isset($connexion['tables'][$nom_sql])) { + if (!$desc) { + $t = ($nom_sql != $nom); + $desc = sql_showtable($nom_sql, $t, $serveur); + if (!$desc OR !$desc['field']) { + spip_log("table inconnue $serveur $nom"); + return null; + } } + $desc['table']= $nom_sql; + $desc['id_table']= $nom; + $desc['connexion']= $serveur; + $connexion['tables'][$nom_sql] = $desc; } - $desc['table']= $nom_sql; - $desc['id_table']= $nom; - $desc['connexion']= $serveur; - $connexions[$s]['tables'][$nom_sql] = $desc; - - return $connexions[$s]['tables'][$nom_sql]; + return $connexion['tables'][$nom_sql]; } ?>