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