|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\DBAL\Driver; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Connection; |
|
|
|
|
|
|
8
|
|
|
use Doctrine\DBAL\Driver; |
|
9
|
|
|
use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString; |
|
10
|
|
|
use Doctrine\DBAL\Driver\DriverException as DriverExceptionInterface; |
|
11
|
|
|
use Doctrine\DBAL\Exception; |
|
12
|
|
|
use Doctrine\DBAL\Exception\DriverException; |
|
|
|
|
|
|
13
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
|
14
|
|
|
use Doctrine\DBAL\Platforms\OraclePlatform; |
|
15
|
|
|
use Doctrine\DBAL\Schema\AbstractSchemaManager; |
|
16
|
|
|
use Doctrine\DBAL\Schema\OracleSchemaManager; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Oracle based drivers. |
|
20
|
|
|
*/ |
|
21
|
|
|
abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
239 |
|
public function convertException(string $message, DriverExceptionInterface $exception) : DriverException |
|
27
|
|
|
{ |
|
28
|
239 |
|
switch ($exception->getCode()) { |
|
29
|
164 |
|
case 1: |
|
30
|
160 |
|
case 2299: |
|
31
|
159 |
|
case 38911: |
|
32
|
6 |
|
return new Exception\UniqueConstraintViolationException($message, $exception); |
|
33
|
|
|
|
|
34
|
158 |
|
case 904: |
|
35
|
2 |
|
return new Exception\InvalidFieldNameException($message, $exception); |
|
36
|
|
|
|
|
37
|
156 |
|
case 918: |
|
38
|
154 |
|
case 960: |
|
39
|
3 |
|
return new Exception\NonUniqueFieldNameException($message, $exception); |
|
40
|
|
|
|
|
41
|
153 |
|
case 923: |
|
42
|
2 |
|
return new Exception\SyntaxErrorException($message, $exception); |
|
43
|
|
|
|
|
44
|
151 |
|
case 942: |
|
45
|
65 |
|
return new Exception\TableNotFoundException($message, $exception); |
|
46
|
|
|
|
|
47
|
149 |
|
case 955: |
|
48
|
3 |
|
return new Exception\TableExistsException($message, $exception); |
|
49
|
|
|
|
|
50
|
146 |
|
case 1017: |
|
51
|
143 |
|
case 12545: |
|
52
|
80 |
|
return new Exception\ConnectionException($message, $exception); |
|
53
|
|
|
|
|
54
|
141 |
|
case 1400: |
|
55
|
2 |
|
return new Exception\NotNullConstraintViolationException($message, $exception); |
|
56
|
|
|
|
|
57
|
139 |
|
case 2266: |
|
58
|
139 |
|
case 2291: |
|
59
|
139 |
|
case 2292: |
|
60
|
5 |
|
return new Exception\ForeignKeyConstraintViolationException($message, $exception); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
138 |
|
return new DriverException($message, $exception); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* {@inheritdoc} |
|
68
|
|
|
*/ |
|
69
|
190 |
|
public function getDatabasePlatform() : AbstractPlatform |
|
70
|
|
|
{ |
|
71
|
190 |
|
return new OraclePlatform(); |
|
72
|
|
|
} |
|
73
|
190 |
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* {@inheritdoc} |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getSchemaManager(Connection $conn) : AbstractSchemaManager |
|
78
|
|
|
{ |
|
79
|
70 |
|
return new OracleSchemaManager($conn); |
|
80
|
|
|
} |
|
81
|
70 |
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Returns an appropriate Easy Connect String for the given parameters. |
|
84
|
|
|
* |
|
85
|
|
|
* @param mixed[] $params The connection parameters to return the Easy Connect String for. |
|
86
|
|
|
*/ |
|
87
|
36 |
|
protected function getEasyConnectString(array $params) : string |
|
88
|
|
|
{ |
|
89
|
36 |
|
return (string) EasyConnectString::fromConnectionParameters($params); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: