Portable error code updates
This commit is contained in:
parent
90e2887428
commit
eef1bd4882
@ -31,55 +31,43 @@ require_once("Doctrine/Exception.php");
|
||||
*/
|
||||
final class Doctrine {
|
||||
/**
|
||||
* ERROR MODE CONSTANTS
|
||||
* error constants
|
||||
*/
|
||||
|
||||
/**
|
||||
* NO PRIMARY KEY COLUMN ERROR
|
||||
* no primary key column found error code
|
||||
*/
|
||||
const ERR_NO_PK = 0;
|
||||
/**
|
||||
* PRIMARY KEY MISMATCH ERROR
|
||||
* this error code is used when user uses factory refresh for a
|
||||
* given Doctrine_Record and the old primary key doesn't match the new one
|
||||
*/
|
||||
const ERR_REFRESH = 1;
|
||||
/**
|
||||
* FIND ERROR
|
||||
* this code used when for example Doctrine_Table::find() is called and
|
||||
* a Data Access Object is not found
|
||||
*/
|
||||
const ERR_FIND = 2;
|
||||
/**
|
||||
* TABLE NOT FOUND ERROR
|
||||
* this error code is used when user tries to initialize
|
||||
* a table and there is no database table for this factory
|
||||
*/
|
||||
const ERR_NOSUCH_TABLE = 3;
|
||||
/**
|
||||
* NAMING ERROR
|
||||
* this code is used when user defined Doctrine_Table is badly named
|
||||
*/
|
||||
const ERR_NAMING = 5;
|
||||
/**
|
||||
* TABLE INSTANCE ERROR
|
||||
* this code is used when user tries to initialize
|
||||
* a table that is already initialized
|
||||
*/
|
||||
const ERR_TABLE_INSTANCE = 6;
|
||||
/**
|
||||
* NO OPEN SESSIONS ERROR
|
||||
* error code which is used when user tries to get
|
||||
* current session are there are no sessions open
|
||||
*/
|
||||
const ERR_NO_SESSIONS = 7;
|
||||
/**
|
||||
* MAPPING ERROR
|
||||
* if there is something wrong with mapping logic
|
||||
* this error code is used
|
||||
*/
|
||||
const ERR_MAPPING = 8;
|
||||
const ERR = -1;
|
||||
const ERR_SYNTAX = -2;
|
||||
const ERR_CONSTRAINT = -3;
|
||||
const ERR_NOT_FOUND = -4;
|
||||
const ERR_ALREADY_EXISTS = -5;
|
||||
const ERR_UNSUPPORTED = -6;
|
||||
const ERR_MISMATCH = -7;
|
||||
const ERR_INVALID = -8;
|
||||
const ERR_NOT_CAPABLE = -9;
|
||||
const ERR_TRUNCATED = -10;
|
||||
const ERR_INVALID_NUMBER = -11;
|
||||
const ERR_INVALID_DATE = -12;
|
||||
const ERR_DIVZERO = -13;
|
||||
const ERR_NODBSELECTED = -14;
|
||||
const ERR_CANNOT_CREATE = -15;
|
||||
const ERR_CANNOT_DELETE = -16;
|
||||
const ERR_CANNOT_DROP = -17;
|
||||
const ERR_NOSUCHTABLE = -18;
|
||||
const ERR_NOSUCHFIELD = -19;
|
||||
const ERR_NEED_MORE_DATA = -20;
|
||||
const ERR_NOT_LOCKED = -21;
|
||||
const ERR_VALUE_COUNT_ON_ROW = -22;
|
||||
const ERR_INVALID_DSN = -23;
|
||||
const ERR_CONNECT_FAILED = -24;
|
||||
const ERR_EXTENSION_NOT_FOUND = -25;
|
||||
const ERR_NOSUCHDB = -26;
|
||||
const ERR_ACCESS_VIOLATION = -27;
|
||||
const ERR_CANNOT_REPLACE = -28;
|
||||
const ERR_CONSTRAINT_NOT_NULL = -29;
|
||||
const ERR_DEADLOCK = -30;
|
||||
const ERR_CANNOT_ALTER = -31;
|
||||
const ERR_MANAGER = -32;
|
||||
const ERR_MANAGER_PARSE = -33;
|
||||
const ERR_LOADMODULE = -34;
|
||||
const ERR_INSUFFICIENT_DATA = -35;
|
||||
|
||||
/**
|
||||
* ATTRIBUTE CONSTANTS
|
||||
|
@ -22,8 +22,50 @@ Doctrine::autoload('Doctrine_Connection_Exception');
|
||||
/**
|
||||
* Doctrine_Connection_Mssql_Exception
|
||||
*
|
||||
* @package Doctrine ORM
|
||||
* @url www.phpdoctrine.com
|
||||
* @license LGPL
|
||||
* @package Doctrine
|
||||
* @url http://www.phpdoctrine.com
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @author Konsta Vesterinen
|
||||
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
|
||||
* @since 1.0
|
||||
* @version $Id$
|
||||
*/
|
||||
class Doctrine_Connection_Mssql_Exception extends Doctrine_Connection_Exception { }
|
||||
class Doctrine_Connection_Mssql_Exception extends Doctrine_Connection_Exception {
|
||||
/**
|
||||
* @var array $errorRegexps an array that is used for determining portable
|
||||
* error code from a native database error code
|
||||
*/
|
||||
protected static $errorCodeMap = array(
|
||||
110 => MDB2_ERROR_VALUE_COUNT_ON_ROW,
|
||||
155 => MDB2_ERROR_NOSUCHFIELD,
|
||||
170 => MDB2_ERROR_SYNTAX,
|
||||
207 => MDB2_ERROR_NOSUCHFIELD,
|
||||
208 => MDB2_ERROR_NOSUCHTABLE,
|
||||
245 => MDB2_ERROR_INVALID_NUMBER,
|
||||
515 => MDB2_ERROR_CONSTRAINT_NOT_NULL,
|
||||
547 => MDB2_ERROR_CONSTRAINT,
|
||||
1913 => MDB2_ERROR_ALREADY_EXISTS,
|
||||
2627 => MDB2_ERROR_CONSTRAINT,
|
||||
2714 => MDB2_ERROR_ALREADY_EXISTS,
|
||||
3701 => MDB2_ERROR_NOSUCHTABLE,
|
||||
8134 => MDB2_ERROR_DIVZERO,
|
||||
);
|
||||
/**
|
||||
* 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) {
|
||||
$code = $errorInfo[1];
|
||||
if(isset(self::$errorCodeMap[$code]))
|
||||
$errorInfo[3] = self::$errorCodeMap[$code];
|
||||
|
||||
return $errorInfo;
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ class Doctrine_Connection_Sqlite_Exception extends Doctrine_Connection_Exception
|
||||
*
|
||||
* the portable error code is added at the end of array
|
||||
*
|
||||
* @param array $errorInfo
|
||||
* @param array $errorInfo error info array
|
||||
* @since 1.0
|
||||
* @return array
|
||||
*/
|
||||
|
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.com>.
|
||||
*/
|
||||
Doctrine::autoload('Doctrine_Db');
|
||||
/**
|
||||
* @package Doctrine
|
||||
* @url http://www.phpdoctrine.com
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @author Konsta Vesterinen
|
||||
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
|
||||
* @version $Id$
|
||||
*/
|
||||
class Doctrine_Db_Sqlite extends Doctrine_Db {
|
||||
protected static $errorRegexps = array(
|
||||
'/^no such table:/' => Doctrine_Db::ERR_NOSUCHTABLE,
|
||||
'/^no such index:/' => Doctrine_Db::ERR_NOT_FOUND,
|
||||
'/^(table|index) .* already exists$/' => Doctrine_Db::ERR_ALREADY_EXISTS,
|
||||
'/PRIMARY KEY must be unique/i' => Doctrine_Db::ERR_CONSTRAINT,
|
||||
'/is not unique/' => Doctrine_Db::ERR_CONSTRAINT,
|
||||
'/columns .* are not unique/i' => Doctrine_Db::ERR_CONSTRAINT,
|
||||
'/uniqueness constraint failed/' => Doctrine_Db::ERR_CONSTRAINT,
|
||||
'/may not be NULL/' => Doctrine_Db::ERR_CONSTRAINT_NOT_NULL,
|
||||
'/^no such column:/' => Doctrine_Db::ERR_NOSUCHFIELD,
|
||||
'/column not present in both tables/i' => Doctrine_Db::ERR_NOSUCHFIELD,
|
||||
'/^near ".*": syntax error$/' => Doctrine_Db::ERR_SYNTAX,
|
||||
'/[0-9]+ values for [0-9]+ columns/i' => Doctrine_Db::ERR_VALUE_COUNT_ON_ROW,
|
||||
);
|
||||
|
||||
/**
|
||||
* This method is used to collect information about an error
|
||||
*
|
||||
* @param integer $error
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
public function processErrorInfo(array $errorInfo) {
|
||||
foreach (self::$errorRegexps as $regexp => $code) {
|
||||
if (preg_match($regexp, $native_msg)) {
|
||||
$error = $code;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return array($error, $native_code, $native_msg);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user