AbstractOracleDriver.php 2.65 KB
Newer Older
1 2 3 4
<?php

namespace Doctrine\DBAL\Driver;

5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\Driver;
7
use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString;
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Schema\OracleSchemaManager;

/**
 * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Oracle based drivers.
 */
abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver
{
    /**
     * {@inheritdoc}
     */
    public function convertException($message, DriverException $exception)
    {
        switch ($exception->getErrorCode()) {
            case '1':
            case '2299':
            case '38911':
                return new Exception\UniqueConstraintViolationException($message, $exception);

            case '904':
                return new Exception\InvalidFieldNameException($message, $exception);

            case '918':
            case '960':
                return new Exception\NonUniqueFieldNameException($message, $exception);

            case '923':
                return new Exception\SyntaxErrorException($message, $exception);

            case '942':
                return new Exception\TableNotFoundException($message, $exception);

            case '955':
                return new Exception\TableExistsException($message, $exception);

            case '1017':
            case '12545':
                return new Exception\ConnectionException($message, $exception);

            case '1400':
                return new Exception\NotNullConstraintViolationException($message, $exception);

51 52
            case '2266':
            case '2291':
53 54 55 56 57 58 59 60 61 62
            case '2292':
                return new Exception\ForeignKeyConstraintViolationException($message, $exception);
        }

        return new Exception\DriverException($message, $exception);
    }

    /**
     * {@inheritdoc}
     */
63
    public function getDatabase(Connection $conn)
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    {
        $params = $conn->getParams();

        return $params['user'];
    }

    /**
     * {@inheritdoc}
     */
    public function getDatabasePlatform()
    {
        return new OraclePlatform();
    }

    /**
     * {@inheritdoc}
     */
81
    public function getSchemaManager(Connection $conn)
82 83 84 85 86 87 88
    {
        return new OracleSchemaManager($conn);
    }

    /**
     * Returns an appropriate Easy Connect String for the given parameters.
     *
89
     * @param mixed[] $params The connection parameters to return the Easy Connect String for.
90 91 92 93 94
     *
     * @return string
     */
    protected function getEasyConnectString(array $params)
    {
95
        return (string) EasyConnectString::fromConnectionParameters($params);
96 97
    }
}