PageRenderTime 26ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/system/application/plugins/doctrine/lib/Doctrine/Connection/Firebird/Exception.php

https://github.com/cawago/ci_campusync_auth
PHP | 136 lines | 69 code | 4 blank | 63 comment | 2 complexity | 3403a1a013640acd29c2ae15ec6fbc8c MD5 | raw file
  1. <?php
  2. /*
  3. * $Id: Exception.php 5798 2009-06-02 15:10:46Z piccoloprincipe $
  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. /**
  22. * Doctrine_Connection_Firebird_Exception
  23. *
  24. * @package Doctrine
  25. * @subpackage Connection
  26. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  27. * @link www.phpdoctrine.org
  28. * @since 1.0
  29. * @version $Revision: 5798 $
  30. * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
  31. * @author Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver)
  32. * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
  33. */
  34. class Doctrine_Connection_Firebird_Exception extends Doctrine_Connection_Exception
  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. // todo: are the following lines needed?
  113. // memo for the interbase php module hackers: we need something similar
  114. // to mysql_errno() to retrieve error codes instead of this ugly hack
  115. if (preg_match('/^([^0-9\-]+)([0-9\-]+)\s+(.*)$/', $native_msg, $m)) {
  116. $native_code = (int)$m[2];
  117. } else {
  118. $native_code = null;
  119. }
  120. */
  121. foreach (self::$errorRegexps as $regexp => $code) {
  122. if (preg_match($regexp, $errorInfo[2])) {
  123. $errorInfo[3] = $code;
  124. break;
  125. }
  126. }
  127. if (isset(self::$errorCodeMap[$errorInfo[1]])) {
  128. $errorInfo[3] = self::$errorCodeMap[$errorInfo[1]];
  129. }
  130. return $errorInfo;
  131. }
  132. }