# Source for file Exception.php

Documentation is available at Exception.php

1. <?php
2. /*
3. * $Id: Exception.php 1345 2007-05-14 13:00:14Z meus $
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_Exception');
22. /**
23. * Doctrine_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: 1345 $
31. * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
32. */
33. class Doctrine_Connection_Exception extends Doctrine_Exception
34. {
35. /**
36. * @var array $errorMessages an array containing messages for portable error codes
37. */
38. static protected $errorMessages = array(
39. Doctrine::ERR => 'unknown error',
40. Doctrine::ERR_ALREADY_EXISTS => 'already exists',
41. Doctrine::ERR_CANNOT_CREATE => 'can not create',
42. Doctrine::ERR_CANNOT_ALTER => 'can not alter',
43. Doctrine::ERR_CANNOT_REPLACE => 'can not replace',
44. Doctrine::ERR_CANNOT_DELETE => 'can not delete',
45. Doctrine::ERR_CANNOT_DROP => 'can not drop',
46. Doctrine::ERR_CONSTRAINT => 'constraint violation',
47. Doctrine::ERR_CONSTRAINT_NOT_NULL=> 'null value violates not-null constraint',
48. Doctrine::ERR_DIVZERO => 'division by zero',
49. Doctrine::ERR_INVALID => 'invalid',
50. Doctrine::ERR_INVALID_DATE => 'invalid date or time',
51. Doctrine::ERR_INVALID_NUMBER => 'invalid number',
52. Doctrine::ERR_MISMATCH => 'mismatch',
53. Doctrine::ERR_NODBSELECTED => 'no database selected',
54. Doctrine::ERR_NOSUCHFIELD => 'no such field',
55. Doctrine::ERR_NOSUCHTABLE => 'no such table',
56. Doctrine::ERR_NOT_CAPABLE => 'Doctrine backend not capable',
57. Doctrine::ERR_NOT_FOUND => 'not found',
58. Doctrine::ERR_NOT_LOCKED => 'not locked',
59. Doctrine::ERR_SYNTAX => 'syntax error',
60. Doctrine::ERR_UNSUPPORTED => 'not supported',
61. Doctrine::ERR_VALUE_COUNT_ON_ROW => 'value count on row',
62. Doctrine::ERR_INVALID_DSN => 'invalid DSN',
63. Doctrine::ERR_CONNECT_FAILED => 'connect failed',
64. Doctrine::ERR_NEED_MORE_DATA => 'insufficient data supplied',
65. Doctrine::ERR_EXTENSION_NOT_FOUND=> 'extension not found',
66. Doctrine::ERR_NOSUCHDB => 'no such database',
67. Doctrine::ERR_ACCESS_VIOLATION => 'insufficient permissions',
68. Doctrine::ERR_LOADMODULE => 'error while including on demand module',
69. Doctrine::ERR_TRUNCATED => 'truncated',
70. Doctrine::ERR_DEADLOCK => 'deadlock detected',
71. );
72. /**
73. * @see Doctrine::ERR_* constants
74. * @since 1.0
75. * @var integer $portableCode portable error code
76. */
77. protected $portableCode;
78. /**
79. * getPortableCode
80. * returns portable error code
81. *
82. * @return integer portable error code
83. */
84. public function getPortableCode()
85. {
86. return $this->portableCode;
87. }
88. /**
89. * getPortableMessage
90. * returns portable error message
91. *
92. * @return string portable error message
93. */
94. public function getPortableMessage()
95. {
96. return self::errorMessage($this->portableCode);
97. }
98. /**
99. * Return a textual error message for a Doctrine error code
100. *
101. * @param int|array integer error code,
102. * null to get the current error code-message map,
103. * or an array with a new error code-message map
104. *
105. * @return string error message, or false if the error code was
106. * not recognized
107. */
108. public function errorMessage($value = null)
109. {
110. return isset(self::$errorMessages[$value]) ?
111. self::$errorMessages[$value] : self::$errorMessages[Doctrine::ERR];
112. }
113. }