# 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. 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. * @var array $errorRegexps an array that is used for determining portable
73. * error code from a native database error message
74. */
75. protected static $errorRegexps = array(
76. '/generator .* is not defined/'
77. => Doctrine::ERR_SYNTAX, // for compat. w ibase_errcode()
78. '/table.*(not exist|not found|unknown)/i'
79. => Doctrine::ERR_NOSUCHTABLE,
80. '/table .* already exists/i'
81. => Doctrine::ERR_ALREADY_EXISTS,
82. '/unsuccessful metadata update .* failed attempt to store duplicate value/i'
83. => Doctrine::ERR_ALREADY_EXISTS,
84. '/unsuccessful metadata update .* not found/i'
85. => Doctrine::ERR_NOT_FOUND,
86. '/validation error for column .* value "\*\*\* null/i'
87. => Doctrine::ERR_CONSTRAINT_NOT_NULL,
88. '/violation of [\w ]+ constraint/i'
89. => Doctrine::ERR_CONSTRAINT,
90. '/conversion error from string/i'
91. => Doctrine::ERR_INVALID_NUMBER,
92. '/no permission for/i'
93. => Doctrine::ERR_ACCESS_VIOLATION,
94. '/arithmetic exception, numeric overflow, or string truncation/i'
95. => Doctrine::ERR_INVALID,
96. '/table unknown/i'
97. => Doctrine::ERR_NOSUCHTABLE,
98. );
99. /**
100. * This method checks if native error code/message can be
101. * converted into a portable code and then adds this
102. * portable error code to errorInfo array and returns the modified array
103. *
104. * the portable error code is added at the end of array
105. *
106. * @param array $errorInfo error info array
107. * @since 1.0
108. * @return array
109. */
110. public function processErrorInfo(array $errorInfo)
111. {
112. /**
113. /**
114. // todo: are the following lines needed?
115. // memo for the interbase php module hackers: we need something similar
116. // to mysql_errno() to retrieve error codes instead of this ugly hack
117. if (preg_match('/^([^0-9\-]+)([0-9\-]+)\s+(.*)$/', $native_msg, $m)) {
118. $native_code = (int)$m[2];
119. } else {
120. $native_code = null;
121. }
122. */
124. foreach (self::$errorRegexps as $regexp => $code) {
125. if (preg_match($regexp, $errorInfo[2])) {
126. $errorInfo[3] = $code;
127. break;
128. }
129. }
130. if (isset(self::$errorCodeMap[$errorInfo[1]])) {
131. $errorInfo[3] = self::$errorCodeMap[$errorInfo[1]];
132. }
133. return $errorInfo;
134. }
135. }