Coverage for Doctrine_Connection_Pgsql_Exception

Back to coverage report

1 <?php
2 /*
3  *  $Id: Exception.php 2963 2007-10-21 06:23:59Z Jonathan.Wage $
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.org>.
20  */
21 Doctrine::autoload('Doctrine_Connection_Exception');
22 /**
23  * Doctrine_Connection_Pgsql_Exception
24  *
25  * @package     Doctrine
26  * @subpackage  Connection
27  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
28  * @link        www.phpdoctrine.org
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: 2963 $
34  */
35 class Doctrine_Connection_Pgsql_Exception extends Doctrine_Connection_Exception
36 {
37     /**
38      * @var array $errorRegexps         an array that is used for determining portable
39      *                                  error code from a native database error message
40      */
41     protected static $errorRegexps = array(
42                                     '/parser: parse error at or near/i'
43                                         => Doctrine::ERR_SYNTAX,
44                                     '/syntax error at/'
45                                         => Doctrine::ERR_SYNTAX,
46                                     '/column reference .* is ambiguous/i'
47                                         => Doctrine::ERR_SYNTAX,
48                                     '/column .* (of relation .*)?does not exist/i'
49                                         => Doctrine::ERR_NOSUCHFIELD,
50                                     '/attribute .* not found|relation .* does not have attribute/i'
51                                         => Doctrine::ERR_NOSUCHFIELD,
52                                     '/column .* specified in USING clause does not exist in (left|right) table/i'
53                                         => Doctrine::ERR_NOSUCHFIELD,
54                                     '/(relation|sequence|table).*does not exist|class .* not found/i'
55                                         => Doctrine::ERR_NOSUCHTABLE,
56                                     '/index .* does not exist/'
57                                         => Doctrine::ERR_NOT_FOUND,
58                                     '/relation .* already exists/i'
59                                         => Doctrine::ERR_ALREADY_EXISTS,
60                                     '/(divide|division) by zero$/i'
61                                         => Doctrine::ERR_DIVZERO,
62                                     '/pg_atoi: error in .*: can\'t parse /i'
63                                         => Doctrine::ERR_INVALID_NUMBER,
64                                     '/invalid input syntax for( type)? (integer|numeric)/i'
65                                         => Doctrine::ERR_INVALID_NUMBER,
66                                     '/value .* is out of range for type \w*int/i'
67                                         => Doctrine::ERR_INVALID_NUMBER,
68                                     '/integer out of range/i'
69                                         => Doctrine::ERR_INVALID_NUMBER,
70                                     '/value too long for type character/i'
71                                         => Doctrine::ERR_INVALID,
72                                     '/permission denied/'
73                                         => Doctrine::ERR_ACCESS_VIOLATION,
74                                     '/violates [\w ]+ constraint/'
75                                         => Doctrine::ERR_CONSTRAINT,
76                                     '/referential integrity violation/'
77                                         => Doctrine::ERR_CONSTRAINT,
78                                     '/violates not-null constraint/'
79                                         => Doctrine::ERR_CONSTRAINT_NOT_NULL,
80                                     '/more expressions than target columns/i'
81                                         => Doctrine::ERR_VALUE_COUNT_ON_ROW,
82                                 );
83
84     /**
85      * This method checks if native error code/message can be
86      * converted into a portable code and then adds this
87      * portable error code to $portableCode field
88      *
89      * the portable error code is added at the end of array
90      *
91      * @param array $errorInfo      error info array
92      * @since 1.0
93      * @see Doctrine::ERR_* constants
94      * @see Doctrine_Connection::$portableCode
95      * @return boolean              whether or not the error info processing was successfull
96      *                              (the process is successfull if portable error code was found)
97      */
98     public function processErrorInfo(array $errorInfo)
99     {
100         foreach (self::$errorRegexps as $regexp => $code) {
101             if (preg_match($regexp, $errorInfo[2])) {
102                 $this->portableCode = $code;
103                 return true;
104             }
105         }
106         return false;
107     }
108 }