Source for file Exception.php

Documentation is available at Exception.php

  1. <?php
  2. /*
  3.  *  $Id: Exception.php 1080 2007-02-10 18:17:08Z romanb $
  4.  *
  5.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16.  *
  17.  * This software consists of voluntary contributions made by many individuals
  18.  * and is licensed under the LGPL. For more information, see
  19.  * <http://www.phpdoctrine.com>.
  20.  */
  21. Doctrine::autoload('Doctrine_Connection_Exception');
  22. /**
  23.  * Doctrine_Connection_Pgsql_Exception
  24.  *
  25.  * @package     Doctrine
  26.  * @category    Object Relational Mapping
  27.  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
  28.  * @link        www.phpdoctrine.com
  29.  * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
  30.  * @author      Paul Cooper <pgc@ucecom.com> (PEAR MDB2 Pgsql driver)
  31.  * @author      Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
  32.  * @since       1.0
  33.  * @version     $Revision: 1080 $
  34.  */
  35. {
  36.     /**
  37.      * @var array $errorRegexps         an array that is used for determining portable
  38.      *                                   error code from a native database error message
  39.      */
  40.     protected static $errorRegexps array(
  41.                                     '/parser: parse error at or near/i'
  42.                                         => Doctrine::ERR_SYNTAX,
  43.                                     '/syntax error at/'
  44.                                         => Doctrine::ERR_SYNTAX,
  45.                                     '/column reference .* is ambiguous/i'
  46.                                         => Doctrine::ERR_SYNTAX,
  47.                                     '/column .* (of relation .*)?does not exist/i'
  48.                                         => Doctrine::ERR_NOSUCHFIELD,
  49.                                     '/attribute .* not found|relation .* does not have attribute/i'
  50.                                         => Doctrine::ERR_NOSUCHFIELD,
  51.                                     '/column .* specified in USING clause does not exist in (left|right) table/i'
  52.                                         => Doctrine::ERR_NOSUCHFIELD,
  53.                                     '/(relation|sequence|table).*does not exist|class .* not found/i'
  54.                                         => Doctrine::ERR_NOSUCHTABLE,
  55.                                     '/index .* does not exist/'
  56.                                         => Doctrine::ERR_NOT_FOUND,
  57.                                     '/relation .* already exists/i'
  58.                                         => Doctrine::ERR_ALREADY_EXISTS,
  59.                                     '/(divide|division) by zero$/i'
  60.                                         => Doctrine::ERR_DIVZERO,
  61.                                     '/pg_atoi: error in .*: can\'t parse /i'
  62.                                         => Doctrine::ERR_INVALID_NUMBER,
  63.                                     '/invalid input syntax for( type)? (integer|numeric)/i'
  64.                                         => Doctrine::ERR_INVALID_NUMBER,
  65.                                     '/value .* is out of range for type \w*int/i'
  66.                                         => Doctrine::ERR_INVALID_NUMBER,
  67.                                     '/integer out of range/i'
  68.                                         => Doctrine::ERR_INVALID_NUMBER,
  69.                                     '/value too long for type character/i'
  70.                                         => Doctrine::ERR_INVALID,
  71.                                     '/permission denied/'
  72.                                         => Doctrine::ERR_ACCESS_VIOLATION,
  73.                                     '/violates [\w ]+ constraint/'
  74.                                         => Doctrine::ERR_CONSTRAINT,
  75.                                     '/referential integrity violation/'
  76.                                         => Doctrine::ERR_CONSTRAINT,
  77.                                     '/violates not-null constraint/'
  78.                                         => Doctrine::ERR_CONSTRAINT_NOT_NULL,
  79.                                     '/more expressions than target columns/i'
  80.                                         => Doctrine::ERR_VALUE_COUNT_ON_ROW,
  81.                                 );
  82.     /**
  83.      * This method checks if native error code/message can be
  84.      * converted into a portable code and then adds this
  85.      * portable error code to $portableCode field
  86.      *
  87.      * the portable error code is added at the end of array
  88.      *
  89.      * @param array $errorInfo      error info array
  90.      * @since 1.0
  91.      * @see Doctrine::ERR_* constants
  92.      * @see Doctrine_Connection::$portableCode
  93.      * @return boolean              whether or not the error info processing was successfull
  94.      *                               (the process is successfull if portable error code was found)
  95.      */
  96.     public function processErrorInfo(array $errorInfo)
  97.     {
  98.         foreach (self::$errorRegexps as $regexp => $code{
  99.             if (preg_match($regexp$errorInfo[2])) {
  100.                 $this->portableCode = $code;
  101.                 return true;
  102.             }
  103.         }
  104.         return false;
  105.     }
  106. }