Fix: modification de la fonction DDLListTables car mysqli_list_tables n'existe plus sous mysqli

Fix: ajout vérification de l'existence des tables dans l'upgrade
This commit is contained in:
Regis Houssin 2007-06-14 19:42:16 +00:00
parent 3a641078ce
commit 953a530790
3 changed files with 53 additions and 35 deletions

View File

@ -149,29 +149,33 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade")
'llx_telephonie_societe_ligne', 'llx_telephonie_societe_ligne',
'llx_telephonie_tarif_client'); 'llx_telephonie_tarif_client');
foreach ($listtables as $val) foreach ($listtables as $val)
{ {
$sql = "SHOW CREATE TABLE ".$val; $searchTable = '';
$resql = $db->query($sql); $searchTable = $db->DDLListTables($conf->db->name,$val);
if (! $resql) dolibarr_print_error($db); if ($searchTable == $val)
{ {
$values=$db->fetch_array($resql); $sql = "SHOW CREATE TABLE ".$val;
$i=0; $resql = $db->query($sql);
$createsql=$values[1]; if (! $resql) dolibarr_print_error($db);
while (eregi('CONSTRAINT `(0_[0-9a-zA-Z]+|[_0-9a-zA-Z]+_ibfk_[0-9]+)`',$createsql,$reg) && $i < 100) {
{ $values=$db->fetch_array($resql);
$sqldrop="ALTER TABLE ".$val." DROP FOREIGN KEY ".$reg[1]; $i=0;
$resqldrop = $db->query($sqldrop); $createsql=$values[1];
if ($resqldrop) while (eregi('CONSTRAINT `(0_[0-9a-zA-Z]+|[_0-9a-zA-Z]+_ibfk_[0-9]+)`',$createsql,$reg) && $i < 100)
{ {
print '<tr><td colspan="2">'.$sqldrop.";</td></tr>\n"; $sqldrop="ALTER TABLE ".$val." DROP FOREIGN KEY ".$reg[1];
} $resqldrop = $db->query($sqldrop);
$createsql=eregi_replace('CONSTRAINT `'.$reg[1].'`','XXX',$createsql); if ($resqldrop)
$i++; {
} print '<tr><td colspan="2">'.$sqldrop.";</td></tr>\n";
$db->free($resql); }
} $createsql=eregi_replace('CONSTRAINT `'.$reg[1].'`','XXX',$createsql);
$i++;
} }
$db->free($resql);
}
}
}
} }
} }

View File

@ -672,15 +672,22 @@ class DoliDb
} }
/** /**
\brief Liste des tables dans une database. \brief Liste des tables dans une database.
\param database Nom de la database \param database Nom de la database
\return resource \param table Nom de la table à rechercher
*/ \return resource
function DDLListTables($database) */
{ function DDLListTables($database, $table='')
$this->results = mysql_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;
}
/** /**
\brief Crée une table \brief Crée une table

View File

@ -678,12 +678,19 @@ class DoliDb
/** /**
\brief Liste des tables dans une database. \brief Liste des tables dans une database.
\param database Nom de la database \param database Nom de la database
\param table Nom de la table à rechercher
\return resource \return resource
*/ */
function DDLListTables($database) function DDLListTables($database, $table='')
{ {
$this->results = mysqli_list_tables($database, $this->db); $like = '';
return $this->results; 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;
} }
/** /**