Exception.php 5.11 KB
Newer Older
zYne's avatar
zYne committed
1
<?php
lsmith's avatar
lsmith committed
2
/*
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *  $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>.
 */
zYne's avatar
zYne committed
21 22
Doctrine::autoload('Doctrine_Exception');
/**
23 24
 * Doctrine_Exception
 *
25
 * @package     Doctrine
26
 * @subpackage  Connection
27 28 29 30 31 32
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @link        www.phpdoctrine.com
 * @since       1.0
 * @version     $Revision$
 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
 */
lsmith's avatar
lsmith committed
33 34
class Doctrine_Connection_Exception extends Doctrine_Exception
{
35 36 37
    /**
     * @var array $errorMessages        an array containing messages for portable error codes
     */
38
    static protected $errorMessages = array(
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
                Doctrine::ERR                    => 'unknown error',
                Doctrine::ERR_ALREADY_EXISTS     => 'already exists',
                Doctrine::ERR_CANNOT_CREATE      => 'can not create',
                Doctrine::ERR_CANNOT_ALTER       => 'can not alter',
                Doctrine::ERR_CANNOT_REPLACE     => 'can not replace',
                Doctrine::ERR_CANNOT_DELETE      => 'can not delete',
                Doctrine::ERR_CANNOT_DROP        => 'can not drop',
                Doctrine::ERR_CONSTRAINT         => 'constraint violation',
                Doctrine::ERR_CONSTRAINT_NOT_NULL=> 'null value violates not-null constraint',
                Doctrine::ERR_DIVZERO            => 'division by zero',
                Doctrine::ERR_INVALID            => 'invalid',
                Doctrine::ERR_INVALID_DATE       => 'invalid date or time',
                Doctrine::ERR_INVALID_NUMBER     => 'invalid number',
                Doctrine::ERR_MISMATCH           => 'mismatch',
                Doctrine::ERR_NODBSELECTED       => 'no database selected',
                Doctrine::ERR_NOSUCHFIELD        => 'no such field',
                Doctrine::ERR_NOSUCHTABLE        => 'no such table',
                Doctrine::ERR_NOT_CAPABLE        => 'Doctrine backend not capable',
                Doctrine::ERR_NOT_FOUND          => 'not found',
                Doctrine::ERR_NOT_LOCKED         => 'not locked',
                Doctrine::ERR_SYNTAX             => 'syntax error',
                Doctrine::ERR_UNSUPPORTED        => 'not supported',
                Doctrine::ERR_VALUE_COUNT_ON_ROW => 'value count on row',
                Doctrine::ERR_INVALID_DSN        => 'invalid DSN',
                Doctrine::ERR_CONNECT_FAILED     => 'connect failed',
                Doctrine::ERR_NEED_MORE_DATA     => 'insufficient data supplied',
                Doctrine::ERR_EXTENSION_NOT_FOUND=> 'extension not found',
                Doctrine::ERR_NOSUCHDB           => 'no such database',
                Doctrine::ERR_ACCESS_VIOLATION   => 'insufficient permissions',
                Doctrine::ERR_LOADMODULE         => 'error while including on demand module',
                Doctrine::ERR_TRUNCATED          => 'truncated',
                Doctrine::ERR_DEADLOCK           => 'deadlock detected',
lsmith's avatar
lsmith committed
71
                );
72 73 74 75 76 77 78 79 80 81 82 83
    /**
     * @see Doctrine::ERR_* constants
     * @since 1.0
     * @var integer $portableCode           portable error code
     */
    protected $portableCode;
    /**
     * getPortableCode
     * returns portable error code
     *
     * @return integer      portable error code
     */
lsmith's avatar
lsmith committed
84 85
    public function getPortableCode()
    {
86 87 88 89 90 91 92 93
        return $this->portableCode;
    }
    /**
     * getPortableMessage
     * returns portable error message
     *
     * @return string       portable error message
     */
lsmith's avatar
lsmith committed
94 95
    public function getPortableMessage()
    {
96 97
        return self::errorMessage($this->portableCode);
    }
98 99 100 101
    /**
     * Return a textual error message for a Doctrine error code
     *
     * @param   int|array   integer error code,
102 103
     *                           null to get the current error code-message map,
     *                           or an array with a new error code-message map
104 105 106 107
     *
     * @return  string  error message, or false if the error code was
     *                  not recognized
     */
108
    public function errorMessage($value = null)
lsmith's avatar
lsmith committed
109
    {
110 111 112
        return isset(self::$errorMessages[$value]) ?
           self::$errorMessages[$value] : self::$errorMessages[Doctrine::ERR];
    }
113
}