DriverException.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the MIT license. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\DBAL\Exception;
  20. use Doctrine\DBAL\DBALException;
  21. /**
  22. * Base class for all errors detected in the driver.
  23. *
  24. * @author Steve Müller <st.mueller@dzh-online.de>
  25. * @link www.doctrine-project.org
  26. * @since 2.5
  27. */
  28. class DriverException extends DBALException
  29. {
  30. /**
  31. * The previous DBAL driver exception.
  32. *
  33. * @var \Doctrine\DBAL\Driver\DriverException
  34. */
  35. private $driverException;
  36. /**
  37. * Constructor.
  38. *
  39. * @param string $message The exception message.
  40. * @param \Doctrine\DBAL\Driver\DriverException $driverException The DBAL driver exception to chain.
  41. */
  42. public function __construct($message, \Doctrine\DBAL\Driver\DriverException $driverException)
  43. {
  44. $exception = null;
  45. if ($driverException instanceof \Exception) {
  46. $exception = $driverException;
  47. }
  48. parent::__construct($message, 0, $exception);
  49. $this->driverException = $driverException;
  50. }
  51. /**
  52. * Returns the driver specific error code if given.
  53. *
  54. * Returns null if no error code was given by the driver.
  55. *
  56. * @return integer|string|null
  57. */
  58. public function getErrorCode()
  59. {
  60. return $this->driverException->getErrorCode();
  61. }
  62. /**
  63. * Returns the SQLSTATE the driver was in at the time the error occurred, if given.
  64. *
  65. * Returns null if no SQLSTATE was given by the driver.
  66. *
  67. * @return string|null
  68. */
  69. public function getSQLState()
  70. {
  71. return $this->driverException->getSQLState();
  72. }
  73. }