AbstractOracleDriver.php 3.2 KB

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