diff --git a/lib/Doctrine/Connection/Firebird/Exception.php b/lib/Doctrine/Connection/Firebird/Exception.php index dfea9a4b9..3494e835b 100644 --- a/lib/Doctrine/Connection/Firebird/Exception.php +++ b/lib/Doctrine/Connection/Firebird/Exception.php @@ -34,7 +34,7 @@ Doctrine::autoload('Doctrine_Connection_Exception'); */ class Doctrine_Connection_Firebird_Exception extends Doctrine_Connection_Exception { /** - * @var array $errorRegexps an array that is used for determining portable + * @var array $errorCodeMap an array that is used for determining portable * error code from a native database error code */ protected static $errorCodeMap = array( diff --git a/lib/Doctrine/Connection/Informix/Informix.php b/lib/Doctrine/Connection/Informix/Exception.php similarity index 100% rename from lib/Doctrine/Connection/Informix/Informix.php rename to lib/Doctrine/Connection/Informix/Exception.php diff --git a/lib/Doctrine/Connection/Mssql/Mssql.php b/lib/Doctrine/Connection/Mssql/Exception.php similarity index 95% rename from lib/Doctrine/Connection/Mssql/Mssql.php rename to lib/Doctrine/Connection/Mssql/Exception.php index c4a09fa9d..38f1c6331 100644 --- a/lib/Doctrine/Connection/Mssql/Mssql.php +++ b/lib/Doctrine/Connection/Mssql/Exception.php @@ -22,18 +22,18 @@ Doctrine::autoload('Doctrine_Connection_Exception'); /** * Doctrine_Connection_Mssql_Exception * - * @package Doctrine - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @author Konsta Vesterinen + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @author Konsta Vesterinen * @author Lukas Smith (PEAR MDB2 library) - * @since 1.0 - * @version $Revision$ - * @category Object Relational Mapping - * @link www.phpdoctrine.com - */ + * @since 1.0 + * @version $Revision$ + * @category Object Relational Mapping + * @link www.phpdoctrine.com + */ class Doctrine_Connection_Mssql_Exception extends Doctrine_Connection_Exception { /** - * @var array $errorRegexps an array that is used for determining portable + * @var array $errorCodeMap an array that is used for determining portable * error code from a native database error code */ protected static $errorCodeMap = array( diff --git a/lib/Doctrine/Connection/Mysql/Exception.php b/lib/Doctrine/Connection/Mysql/Exception.php index 2560487b7..35e1302d1 100644 --- a/lib/Doctrine/Connection/Mysql/Exception.php +++ b/lib/Doctrine/Connection/Mysql/Exception.php @@ -22,18 +22,18 @@ Doctrine::autoload('Doctrine_Connection_Exception'); /** * Doctrine_Connection_Mysql_Exception * - * @package Doctrine - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @author Konsta Vesterinen + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @author Konsta Vesterinen * @author Lukas Smith (PEAR MDB2 library) - * @since 1.0 - * @version $Revision$ - * @category Object Relational Mapping - * @link www.phpdoctrine.com - */ + * @since 1.0 + * @version $Revision$ + * @category Object Relational Mapping + * @link www.phpdoctrine.com + */ class Doctrine_Connection_Mysql_Exception extends Doctrine_Connection_Exception { /** - * @var array $errorRegexps an array that is used for determining portable + * @var array $errorCodeMap an array that is used for determining portable * error code from a native database error code */ protected static $errorCodeMap = array( diff --git a/lib/Doctrine/Connection/Oracle/Exception.php b/lib/Doctrine/Connection/Oracle/Exception.php index d578a8763..ddfa06866 100644 --- a/lib/Doctrine/Connection/Oracle/Exception.php +++ b/lib/Doctrine/Connection/Oracle/Exception.php @@ -22,18 +22,18 @@ Doctrine::autoload('Doctrine_Connection_Exception'); /** * Doctrine_Connection_Oracle_Exception * - * @package Doctrine - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @author Konsta Vesterinen + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @author Konsta Vesterinen * @author Lukas Smith (PEAR MDB2 library) - * @since 1.0 - * @version $Revision$ - * @category Object Relational Mapping - * @link www.phpdoctrine.com - */ + * @since 1.0 + * @version $Revision$ + * @category Object Relational Mapping + * @link www.phpdoctrine.com + */ class Doctrine_Connection_Oracle_Exception extends Doctrine_Connection_Exception { /** - * @var array $errorRegexps an array that is used for determining portable + * @var array $errorCodeMap an array that is used for determining portable * error code from a native database error code */ protected static $errorCodeMap = array( diff --git a/lib/Doctrine/Connection/Pgsql/Exception.php b/lib/Doctrine/Connection/Pgsql/Exception.php index d3f250f92..8bf9c4af8 100644 --- a/lib/Doctrine/Connection/Pgsql/Exception.php +++ b/lib/Doctrine/Connection/Pgsql/Exception.php @@ -22,12 +22,83 @@ Doctrine::autoload('Doctrine_Connection_Exception'); /** * Doctrine_Connection_Pgsql_Exception * - * @package Doctrine - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @category Object Relational Mapping - * @link www.phpdoctrine.com - * @since 1.0 - * @version $Revision$ - * @author Konsta Vesterinen - */ -class Doctrine_Connection_Pgsql_Exception extends Doctrine_Connection_Exception { } + * @package Doctrine + * @category Object Relational Mapping + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.phpdoctrine.com + * @author Konsta Vesterinen + * @author Paul Cooper (PEAR MDB2 Pgsql driver) + * @author Lukas Smith (PEAR MDB2 library) + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Connection_Pgsql_Exception extends Doctrine_Connection_Exception { + /** + * @var array $errorRegexps an array that is used for determining portable + * error code from a native database error message + */ + protected static $errorRegexps = array( + '/column .* (of relation .*)?does not exist/i' + => Doctrine::ERR_NOSUCHFIELD, + '/(relation|sequence|table).*does not exist|class .* not found/i' + => Doctrine::ERR_NOSUCHTABLE, + '/index .* does not exist/' + => Doctrine::ERR_NOT_FOUND, + '/relation .* already exists/i' + => Doctrine::ERR_ALREADY_EXISTS, + '/(divide|division) by zero$/i' + => Doctrine::ERR_DIVZERO, + '/pg_atoi: error in .*: can\'t parse /i' + => Doctrine::ERR_INVALID_NUMBER, + '/invalid input syntax for( type)? (integer|numeric)/i' + => Doctrine::ERR_INVALID_NUMBER, + '/value .* is out of range for type \w*int/i' + => Doctrine::ERR_INVALID_NUMBER, + '/integer out of range/i' + => Doctrine::ERR_INVALID_NUMBER, + '/value too long for type character/i' + => Doctrine::ERR_INVALID, + '/attribute .* not found|relation .* does not have attribute/i' + => Doctrine::ERR_NOSUCHFIELD, + '/column .* specified in USING clause does not exist in (left|right) table/i' + => Doctrine::ERR_NOSUCHFIELD, + '/parser: parse error at or near/i' + => Doctrine::ERR_SYNTAX, + '/syntax error at/' + => Doctrine::ERR_SYNTAX, + '/column reference .* is ambiguous/i' + => Doctrine::ERR_SYNTAX, + '/permission denied/' + => Doctrine::ERR_ACCESS_VIOLATION, + '/violates not-null constraint/' + => Doctrine::ERR_CONSTRAINT_NOT_NULL, + '/violates [\w ]+ constraint/' + => Doctrine::ERR_CONSTRAINT, + '/referential integrity violation/' + => Doctrine::ERR_CONSTRAINT, + '/more expressions than target columns/i' + => Doctrine::ERR_VALUE_COUNT_ON_ROW, + ); + /** + * This method checks if native error code/message can be + * converted into a portable code and then adds this + * portable error code to errorInfo array and returns the modified array + * + * the portable error code is added at the end of array + * + * @param array $errorInfo error info array + * @since 1.0 + * @return array + */ + public function processErrorInfo(array $errorInfo) { + foreach (self::$errorRegexps as $regexp => $code) { + if (preg_match($regexp, $errorInfo[2])) { + $errorInfo[3] = $code; + break; + } + } + + return $errorInfo; + } + +}