Qual: Les codes erreurs des requetes est remplac par l'quivalent gnrique, ce qui permet compatibilit des gestions d'erreurs entre mysql et pgsql.
This commit is contained in:
parent
18834d28c6
commit
6eeda3819b
@ -181,7 +181,7 @@ if ($_POST["actionadd"]) {
|
||||
$result = $db->query($sql);
|
||||
if (!$result)
|
||||
{
|
||||
if ($db->errno() == $db->ERROR_DUPLICATE) {
|
||||
if ($db->errno() == DB_ERROR_RECORD_ALREADY_EXISTS) {
|
||||
$msg="Une entrée pour cette clé existe déjà<br>";
|
||||
}
|
||||
else {
|
||||
|
||||
@ -135,7 +135,7 @@ class FactureFourn
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->db->errno() == $this->db->ERROR_DUPLICATE) {
|
||||
if ($this->db->errno() == DB_ERROR_RECORD_ALREADY_EXISTS) {
|
||||
print "Erreur : Une facture possédant cet id existe déjà";
|
||||
}
|
||||
else {
|
||||
|
||||
@ -23,17 +23,18 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/lib/mysql.lib.php
|
||||
\brief Fichier de la classe permettant de gérer une base mysql
|
||||
\author Fabien Seisen
|
||||
\author Rodolphe Quiedeville.
|
||||
\author Laurent Destailleur.
|
||||
\version $Revision$
|
||||
\file htdocs/lib/mysql.lib.php
|
||||
\brief Fichier de la classe permettant de gérer une base mysql
|
||||
\author Fabien Seisen
|
||||
\author Rodolphe Quiedeville.
|
||||
\author Laurent Destailleur.
|
||||
\version $Revision$
|
||||
*/
|
||||
|
||||
|
||||
/** \class DoliDb
|
||||
\brief Classe permettant de gérér la database de dolibarr
|
||||
/**
|
||||
\class DoliDb
|
||||
\brief Classe permettant de gérér la database de dolibarr
|
||||
*/
|
||||
|
||||
class DoliDb
|
||||
@ -47,10 +48,24 @@ class DoliDb
|
||||
|
||||
var $ok;
|
||||
|
||||
// Constantes pour code erreurs
|
||||
var $ERROR_DUPLICATE=1062;
|
||||
var $ERROR_TABLEEXISTS=1050;
|
||||
|
||||
// Constantes pour conversion code erreur MySql en code erreur générique
|
||||
var $errorcode_map = array(
|
||||
1004 => DB_ERROR_CANNOT_CREATE,
|
||||
1005 => DB_ERROR_CANNOT_CREATE,
|
||||
1006 => DB_ERROR_CANNOT_CREATE,
|
||||
1007 => DB_ERROR_ALREADY_EXISTS,
|
||||
1008 => DB_ERROR_CANNOT_DROP,
|
||||
1046 => DB_ERROR_NODBSELECTED,
|
||||
1050 => DB_ERROR_TABLE_ALREADY_EXISTS,
|
||||
1051 => DB_ERROR_NOSUCHTABLE,
|
||||
1054 => DB_ERROR_NOSUCHFIELD,
|
||||
1062 => DB_ERROR_RECORD_ALREADY_EXISTS,
|
||||
1064 => DB_ERROR_SYNTAX,
|
||||
1100 => DB_ERROR_NOT_LOCKED,
|
||||
1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
|
||||
1146 => DB_ERROR_NOSUCHTABLE,
|
||||
1048 => DB_ERROR_CONSTRAINT,
|
||||
);
|
||||
|
||||
/**
|
||||
\brief Ouverture d'une connection vers le serveur et éventuellement une database.
|
||||
@ -447,8 +462,21 @@ class DoliDb
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Renvoie le texte de l'erreur mysql de l'operation precedente.
|
||||
\return error_text
|
||||
\brief Renvoie le code erreur generique de l'operation precedente.
|
||||
\return error_num (Exemples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...)
|
||||
*/
|
||||
|
||||
function errno()
|
||||
{
|
||||
if (isset($this->errorcode_map[mysql_errno($this->db)])) {
|
||||
return $this->errorcode_map[mysql_errno($this->db)];
|
||||
}
|
||||
return DB_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Renvoie le texte de l'erreur mysql de l'operation precedente.
|
||||
\return error_text
|
||||
*/
|
||||
|
||||
function error()
|
||||
@ -456,20 +484,6 @@ class DoliDb
|
||||
return mysql_error($this->db);
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Renvoie la valeur numerique de l'erreur de l'operation precedente.
|
||||
pour etre exploiter par l'appelant et détecter les erreurs du genre:
|
||||
echec car doublons, table deja existante...
|
||||
\return error_num
|
||||
*/
|
||||
|
||||
function errno()
|
||||
{
|
||||
// $ERROR_DUPLICATE=1062;
|
||||
// $ERROR_TABLEEXISTS=1050;
|
||||
return mysql_errno($this->db);
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Obtient l'id genéré par le dernier INSERT.
|
||||
\return id
|
||||
|
||||
@ -465,7 +465,7 @@ class DoliDb
|
||||
$error_regexps = array(
|
||||
'/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/' => DB_ERROR_NOSUCHTABLE,
|
||||
'/table [\"\'].*[\"\'] does not exist/' => DB_ERROR_NOSUCHTABLE,
|
||||
'/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/' => DB_ERROR_ALREADY_EXISTS,
|
||||
'/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/' => DB_ERROR_RECORD_ALREADY_EXISTS,
|
||||
'/divide by zero$/' => DB_ERROR_DIVZERO,
|
||||
'/pg_atoi: error in .*: can\'t parse /' => DB_ERROR_INVALID_NUMBER,
|
||||
'/ttribute [\"\'].*[\"\'] not found$|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => DB_ERROR_NOSUCHFIELD,
|
||||
|
||||
@ -188,7 +188,7 @@ class Product
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->db->errno() == $this->db->ERROR_DUPLICATE) {
|
||||
if ($this->db->errno() == DB_ERROR_RECORD_ALREADY_EXISTS) {
|
||||
$this->mesg_error=$langs->trans("Error")." : ".$langs->trans("ErrorProductAlreadyExists",$this->ref);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -139,7 +139,7 @@ class Societe {
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->db->errno() == $this->db->ERROR_DUPLICATE)
|
||||
if ($this->db->errno() == DB_ERROR_RECORD_ALREADY_EXISTS)
|
||||
{
|
||||
$this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->nom);
|
||||
}
|
||||
@ -348,7 +348,7 @@ class Societe {
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->db->errno() == $this->db->ERROR_DUPLICATE)
|
||||
if ($this->db->errno() == DB_ERROR_RECORD_ALREADY_EXISTS)
|
||||
{
|
||||
// Doublon
|
||||
$this->error = $langs->trans("ErrorPrefixAlreadyExists",$this->prefix_comm);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user