AbstractOracleDriver.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace Doctrine\DBAL\Driver;
  3. use Doctrine\DBAL\Connection;
  4. use Doctrine\DBAL\Driver;
  5. use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString;
  6. use Doctrine\DBAL\Exception;
  7. use Doctrine\DBAL\Platforms\OraclePlatform;
  8. use Doctrine\DBAL\Schema\OracleSchemaManager;
  9. /**
  10. * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Oracle based drivers.
  11. */
  12. abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver
  13. {
  14. /**
  15. * {@inheritdoc}
  16. */
  17. public function convertException($message, DriverException $exception)
  18. {
  19. switch ($exception->getErrorCode()) {
  20. case '1':
  21. case '2299':
  22. case '38911':
  23. return new Exception\UniqueConstraintViolationException($message, $exception);
  24. case '904':
  25. return new Exception\InvalidFieldNameException($message, $exception);
  26. case '918':
  27. case '960':
  28. return new Exception\NonUniqueFieldNameException($message, $exception);
  29. case '923':
  30. return new Exception\SyntaxErrorException($message, $exception);
  31. case '942':
  32. return new Exception\TableNotFoundException($message, $exception);
  33. case '955':
  34. return new Exception\TableExistsException($message, $exception);
  35. case '1017':
  36. case '12545':
  37. return new Exception\ConnectionException($message, $exception);
  38. case '1400':
  39. return new Exception\NotNullConstraintViolationException($message, $exception);
  40. case '2266':
  41. case '2291':
  42. case '2292':
  43. return new Exception\ForeignKeyConstraintViolationException($message, $exception);
  44. }
  45. return new Exception\DriverException($message, $exception);
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function getDatabase(Connection $conn)
  51. {
  52. $params = $conn->getParams();
  53. return $params['user'];
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function getDatabasePlatform()
  59. {
  60. return new OraclePlatform();
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function getSchemaManager(Connection $conn)
  66. {
  67. return new OracleSchemaManager($conn);
  68. }
  69. /**
  70. * Returns an appropriate Easy Connect String for the given parameters.
  71. *
  72. * @param mixed[] $params The connection parameters to return the Easy Connect String for.
  73. *
  74. * @return string
  75. */
  76. protected function getEasyConnectString(array $params)
  77. {
  78. return (string) EasyConnectString::fromConnectionParameters($params);
  79. }
  80. }