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_Firebird_Exception
  24.  *
  25.  * @package     Doctrine
  26.  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
  27.  * @category    Object Relational Mapping
  28.  * @link        www.phpdoctrine.com
  29.  * @since       1.0
  30.  * @version     $Revision: 1080 $
  31.  * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
  32.  * @author      Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver)
  33.  * @author      Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
  34.  */
  35. {
  36.     /**
  37.      * @var array $errorCodeMap         an array that is used for determining portable
  38.      *                                   error code from a native database error code
  39.      */
  40.     protected static $errorCodeMap array(
  41.                                     -104 => Doctrine::ERR_SYNTAX,
  42.                                     -150 => Doctrine::ERR_ACCESS_VIOLATION,
  43.                                     -151 => Doctrine::ERR_ACCESS_VIOLATION,
  44.                                     -155 => Doctrine::ERR_NOSUCHTABLE,
  45.                                     -157 => Doctrine::ERR_NOSUCHFIELD,
  46.                                     -158 => Doctrine::ERR_VALUE_COUNT_ON_ROW,
  47.                                     -170 => Doctrine::ERR_MISMATCH,
  48.                                     -171 => Doctrine::ERR_MISMATCH,
  49.                                     -172 => Doctrine::ERR_INVALID,
  50.                                     // -204 =>  // Covers too many errors, need to use regex on msg
  51.                                     -205 => Doctrine::ERR_NOSUCHFIELD,
  52.                                     -206 => Doctrine::ERR_NOSUCHFIELD,
  53.                                     -208 => Doctrine::ERR_INVALID,
  54.                                     -219 => Doctrine::ERR_NOSUCHTABLE,
  55.                                     -297 => Doctrine::ERR_CONSTRAINT,
  56.                                     -303 => Doctrine::ERR_INVALID,
  57.                                     -413 => Doctrine::ERR_INVALID_NUMBER,
  58.                                     -530 => Doctrine::ERR_CONSTRAINT,
  59.                                     -551 => Doctrine::ERR_ACCESS_VIOLATION,
  60.                                     -552 => Doctrine::ERR_ACCESS_VIOLATION,
  61.                                     // -607 =>  // Covers too many errors, need to use regex on msg
  62.                                     -625 => Doctrine::ERR_CONSTRAINT_NOT_NULL,
  63.                                     -803 => Doctrine::ERR_CONSTRAINT,
  64.                                     -804 => Doctrine::ERR_VALUE_COUNT_ON_ROW,
  65.                                     -904 => Doctrine::ERR_CONNECT_FAILED,
  66.                                     -922 => Doctrine::ERR_NOSUCHDB,
  67.                                     -923 => Doctrine::ERR_CONNECT_FAILED,
  68.                                     -924 => Doctrine::ERR_CONNECT_FAILED
  69.                                     );
  70.     /**
  71.      * @var array $errorRegexps         an array that is used for determining portable
  72.      *                                   error code from a native database error message
  73.      */
  74.     protected static $errorRegexps array(
  75.                                     '/generator .* is not defined/'
  76.                                         => Doctrine::ERR_SYNTAX,  // for compat. w ibase_errcode()
  77.                                     '/table.*(not exist|not found|unknown)/i'
  78.                                         => Doctrine::ERR_NOSUCHTABLE,
  79.                                     '/table .* already exists/i'
  80.                                         => Doctrine::ERR_ALREADY_EXISTS,
  81.                                     '/unsuccessful metadata update .* failed attempt to store duplicate value/i'
  82.                                         => Doctrine::ERR_ALREADY_EXISTS,
  83.                                     '/unsuccessful metadata update .* not found/i'
  84.                                         => Doctrine::ERR_NOT_FOUND,
  85.                                     '/validation error for column .* value "\*\*\* null/i'
  86.                                         => Doctrine::ERR_CONSTRAINT_NOT_NULL,
  87.                                     '/violation of [\w ]+ constraint/i'
  88.                                         => Doctrine::ERR_CONSTRAINT,
  89.                                     '/conversion error from string/i'
  90.                                         => Doctrine::ERR_INVALID_NUMBER,
  91.                                     '/no permission for/i'
  92.                                         => Doctrine::ERR_ACCESS_VIOLATION,
  93.                                     '/arithmetic exception, numeric overflow, or string truncation/i'
  94.                                         => Doctrine::ERR_INVALID,
  95.                                     '/table unknown/i'
  96.                                         => Doctrine::ERR_NOSUCHTABLE,
  97.                                     );
  98.     /**
  99.      * This method checks if native error code/message can be
  100.      * converted into a portable code and then adds this
  101.      * portable error code to errorInfo array and returns the modified array
  102.      *
  103.      * the portable error code is added at the end of array
  104.      *
  105.      * @param array $errorInfo      error info array
  106.      * @since 1.0
  107.      * @return array 
  108.      */
  109.     public function processErrorInfo(array $errorInfo)
  110.     {
  111.             /**
  112. /**
  113.             // todo: are the following lines needed?
  114.             // memo for the interbase php module hackers: we need something similar
  115.             // to mysql_errno() to retrieve error codes instead of this ugly hack
  116.             if (preg_match('/^([^0-9\-]+)([0-9\-]+)\s+(.*)$/', $native_msg, $m)) {
  117.                 $native_code = (int)$m[2];
  118.             } else {
  119.                 $native_code = null;
  120.             }
  121.             */
  122.  
  123.         foreach (self::$errorRegexps as $regexp => $code{
  124.             if (preg_match($regexp$errorInfo[2])) {
  125.                 $errorInfo[3$code;
  126.                 break;
  127.             }
  128.         }
  129.         if (isset(self::$errorCodeMap[$errorInfo[1]])) {
  130.             $errorInfo[3self::$errorCodeMap[$errorInfo[1]];
  131.         }
  132.         return $errorInfo;
  133.     }
  134. }