From 41ebd98a926f35904b5ee4dd92eeaf9971fa37aa Mon Sep 17 00:00:00 2001
From: "Committo,Ergo:sum" <esj@rezo.net>
Date: Fri, 31 Aug 2007 07:59:27 +0000
Subject: [PATCH] =?UTF-8?q?#209:=20erreurs=20dans=20le=20simulateur=20PG?=
 =?UTF-8?q?=20du=20showtable=20MySQL,=20en=20particuleir=20parce=20que=20P?=
 =?UTF-8?q?G=20diff=C3=A9rencie=20les=20casses.=20Du=20coup=20on=20remplac?=
 =?UTF-8?q?e=20=3D=20par=20ILIKE.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ecrire/base/abstract_sql.php |  2 +-
 ecrire/base/db_pg.php        | 10 +++++-----
 ecrire/public/criteres.php   |  4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/ecrire/base/abstract_sql.php b/ecrire/base/abstract_sql.php
index 536d70c7ef..e469aff2a5 100644
--- a/ecrire/base/abstract_sql.php
+++ b/ecrire/base/abstract_sql.php
@@ -245,7 +245,7 @@ function calcul_mysql_in($val, $valeurs, $not='') {
 
 // http://doc.spip.org/@description_table
 function description_table($nom){
-	global $tables_principales, $tables_auxiliaires, $table_des_tables, $tables_des_serveurs_sql;
+	global $tables_principales, $tables_auxiliaires;
 	static $tables_externes = array();
 
 	if (isset($tables_externes[$nom]))
diff --git a/ecrire/base/db_pg.php b/ecrire/base/db_pg.php
index ddeae40e5a..023e1830ca 100644
--- a/ecrire/base/db_pg.php
+++ b/ecrire/base/db_pg.php
@@ -553,12 +553,12 @@ function spip_pg_errno() {
 }
 
 // http://doc.spip.org/@spip_pg_showtable
-function spip_pg_showtable($nom_table)
+function spip_pg_showtable($nom_table, $serveur='')
 {
 	$connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0];
 	$link = $connexion['link'];
 
-	$res = pg_query($link, "SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name=" . _q($nom_table));
+	$res = pg_query($link, "SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE " . _q($nom_table));
 
 	if (!$res) return false;
 
@@ -567,13 +567,13 @@ function spip_pg_showtable($nom_table)
 		$fields[$field[0]] = $field[2] . (!$field[1] ? '' : (" DEFAULT " . $field[1]));
 	}
 
-	$res = pg_query($link, "SELECT indexdef FROM pg_indexes WHERE tablename=" . _q($nom_table));
+	$res = pg_query($link, "SELECT indexdef FROM pg_indexes WHERE tablename ILIKE " . _q($nom_table));
 	$keys = array();
 	while($index = pg_fetch_array($res, NULL, PGSQL_NUM)) {
 		if (preg_match('/CREATE\s+(UNIQUE\s+)?INDEX.*\((.*)\)$/',
 			       $index[0],$r)) {
 			$index = split(',', $r[2]);
-			$keys[($r[1] ? "PRIMARY KEY " : "KEY ") . $index[0]] = 
+			$keys[($r[1] ? "PRIMARY KEY" : ("KEY " . $index[0]))] = 
 			  $r[2];
 		}
 	}
@@ -667,7 +667,7 @@ function spip_pg_create($nom, $champs, $cles, $autoinc=false, $temporary=false,
 	if (!$r)
 		spip_log("table $nom deja la");
 	else {
-		foreach($keys as $index) {@pg_query($link, $index);}
+		foreach($keys as $index) {pg_query($link, $index);}
 	} 
 	return $r;
 }
diff --git a/ecrire/public/criteres.php b/ecrire/public/criteres.php
index 0c78925b3d..c56b9abb56 100644
--- a/ecrire/public/criteres.php
+++ b/ecrire/public/criteres.php
@@ -1049,8 +1049,8 @@ function trouver_table($type, $boucle)
 
 	if (!isset($tables_des_serveurs_sql[$s][$nom_table])) {
 		$desc = sql_showtable($nom_table, $serveur, ($nom_table != $type));
-		if (!$desc) {
-			erreur_squelette(_T('zbug_table_inconnue', array('table' => $type)),
+		if (!$desc OR !$desc['field']) {
+		  erreur_squelette(_T('zbug_table_inconnue', array('table' => $s ? "$serveur:$type" : $type)),
 					 $boucle->id_boucle);
 			return null;
 		}
-- 
GitLab