From 953a53079072cc856d9c935422b50344e74c6d3c Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 14 Jun 2007 19:42:16 +0000 Subject: [PATCH] =?UTF-8?q?Fix:=20modification=20de=20la=20fonction=20DDLL?= =?UTF-8?q?istTables=20car=20mysqli=5Flist=5Ftables=20n'existe=20plus=20so?= =?UTF-8?q?us=20mysqli=20Fix:=20ajout=20v=E9rification=20de=20l'existence?= =?UTF-8?q?=20des=20tables=20dans=20l'upgrade?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/install/upgrade.php | 50 ++++++++++++++++------------- htdocs/lib/databases/mysql.lib.php | 25 +++++++++------ htdocs/lib/databases/mysqli.lib.php | 13 ++++++-- 3 files changed, 53 insertions(+), 35 deletions(-) diff --git a/htdocs/install/upgrade.php b/htdocs/install/upgrade.php index ae3aae6c142..663b74902a4 100644 --- a/htdocs/install/upgrade.php +++ b/htdocs/install/upgrade.php @@ -149,29 +149,33 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade") 'llx_telephonie_societe_ligne', 'llx_telephonie_tarif_client'); foreach ($listtables as $val) - { - $sql = "SHOW CREATE TABLE ".$val; - $resql = $db->query($sql); - if (! $resql) dolibarr_print_error($db); - { - $values=$db->fetch_array($resql); - $i=0; - $createsql=$values[1]; - while (eregi('CONSTRAINT `(0_[0-9a-zA-Z]+|[_0-9a-zA-Z]+_ibfk_[0-9]+)`',$createsql,$reg) && $i < 100) - { - $sqldrop="ALTER TABLE ".$val." DROP FOREIGN KEY ".$reg[1]; - $resqldrop = $db->query($sqldrop); - if ($resqldrop) - { - print ''.$sqldrop.";\n"; - } - $createsql=eregi_replace('CONSTRAINT `'.$reg[1].'`','XXX',$createsql); - $i++; - } - $db->free($resql); - } - - } + { + $searchTable = ''; + $searchTable = $db->DDLListTables($conf->db->name,$val); + if ($searchTable == $val) + { + $sql = "SHOW CREATE TABLE ".$val; + $resql = $db->query($sql); + if (! $resql) dolibarr_print_error($db); + { + $values=$db->fetch_array($resql); + $i=0; + $createsql=$values[1]; + while (eregi('CONSTRAINT `(0_[0-9a-zA-Z]+|[_0-9a-zA-Z]+_ibfk_[0-9]+)`',$createsql,$reg) && $i < 100) + { + $sqldrop="ALTER TABLE ".$val." DROP FOREIGN KEY ".$reg[1]; + $resqldrop = $db->query($sqldrop); + if ($resqldrop) + { + print ''.$sqldrop.";\n"; + } + $createsql=eregi_replace('CONSTRAINT `'.$reg[1].'`','XXX',$createsql); + $i++; + } + $db->free($resql); + } + } + } } } diff --git a/htdocs/lib/databases/mysql.lib.php b/htdocs/lib/databases/mysql.lib.php index 0bb300db0d9..474ed80bc60 100644 --- a/htdocs/lib/databases/mysql.lib.php +++ b/htdocs/lib/databases/mysql.lib.php @@ -672,15 +672,22 @@ class DoliDb } /** - \brief Liste des tables dans une database. - \param database Nom de la database - \return resource - */ - function DDLListTables($database) - { - $this->results = mysql_list_tables($database, $this->db); - return $this->results; - } + \brief Liste des tables dans une database. + \param database Nom de la database + \param table Nom de la table à rechercher + \return resource + */ + function DDLListTables($database, $table='') + { + $like = ''; + if ($table) $like = "LIKE '".$table."'" + $result = mysqli_query($this->db, "SHOW TABLES FROM ".$database." ".$like." "); + while($row = mysqli_fetch_array($result)) + { + $this->results = $row[0]; + } + return $this->results; + } /** \brief Crée une table diff --git a/htdocs/lib/databases/mysqli.lib.php b/htdocs/lib/databases/mysqli.lib.php index cbd583ead56..0659352bddb 100644 --- a/htdocs/lib/databases/mysqli.lib.php +++ b/htdocs/lib/databases/mysqli.lib.php @@ -678,12 +678,19 @@ class DoliDb /** \brief Liste des tables dans une database. \param database Nom de la database + \param table Nom de la table à rechercher \return resource */ - function DDLListTables($database) + function DDLListTables($database, $table='') { - $this->results = mysqli_list_tables($database, $this->db); - return $this->results; + $like = ''; + if ($table) $like = "LIKE '".$table."'"; + $result = mysqli_query($this->db, "SHOW TABLES FROM ".$database." ".$like." "); + while($row = mysqli_fetch_array($result)) + { + $this->results = $row[0]; + } + return $this->results; } /**