|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\DBAL\Driver; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Connection; |
|
|
|
|
|
|
6
|
|
|
use Doctrine\DBAL\Driver; |
|
7
|
|
|
use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString; |
|
8
|
|
|
use Doctrine\DBAL\Exception; |
|
9
|
|
|
use Doctrine\DBAL\Platforms\OraclePlatform; |
|
10
|
|
|
use Doctrine\DBAL\Platforms\Oracle122Platform; |
|
11
|
|
|
use Doctrine\DBAL\Schema\OracleSchemaManager; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Oracle based drivers. |
|
15
|
|
|
*/ |
|
16
|
|
|
abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver |
|
|
|
|
|
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritdoc} |
|
20
|
1622 |
|
*/ |
|
21
|
|
|
public function convertException($message, DriverException $exception) |
|
22
|
1622 |
|
{ |
|
23
|
1622 |
|
switch ($exception->getErrorCode()) { |
|
24
|
1612 |
|
case '1': |
|
25
|
1606 |
|
case '2299': |
|
26
|
1022 |
|
case '38911': |
|
27
|
|
|
return new Exception\UniqueConstraintViolationException($message, $exception); |
|
28
|
1600 |
|
|
|
29
|
1183 |
|
case '904': |
|
30
|
|
|
return new Exception\InvalidFieldNameException($message, $exception); |
|
31
|
1592 |
|
|
|
32
|
1584 |
|
case '918': |
|
33
|
1164 |
|
case '960': |
|
34
|
|
|
return new Exception\NonUniqueFieldNameException($message, $exception); |
|
35
|
1578 |
|
|
|
36
|
1083 |
|
case '923': |
|
37
|
|
|
return new Exception\SyntaxErrorException($message, $exception); |
|
38
|
1570 |
|
|
|
39
|
1155 |
|
case '942': |
|
40
|
|
|
return new Exception\TableNotFoundException($message, $exception); |
|
41
|
1562 |
|
|
|
42
|
1099 |
|
case '955': |
|
43
|
|
|
return new Exception\TableExistsException($message, $exception); |
|
44
|
1514 |
|
|
|
45
|
1479 |
|
case '1017': |
|
46
|
1268 |
|
case '12545': |
|
47
|
|
|
return new Exception\ConnectionException($message, $exception); |
|
48
|
1446 |
|
|
|
49
|
1108 |
|
case '1400': |
|
50
|
|
|
return new Exception\NotNullConstraintViolationException($message, $exception); |
|
51
|
1438 |
|
|
|
52
|
1438 |
|
case '2266': |
|
53
|
1438 |
|
case '2291': |
|
54
|
1214 |
|
case '2292': |
|
55
|
|
|
return new Exception\ForeignKeyConstraintViolationException($message, $exception); |
|
56
|
|
|
} |
|
57
|
1157 |
|
|
|
58
|
|
|
return new Exception\DriverException($message, $exception); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* {@inheritdoc} |
|
63
|
1440 |
|
*/ |
|
64
|
|
|
public function createDatabasePlatformForVersion($version) |
|
65
|
1440 |
|
{ |
|
66
|
|
|
//Example: "Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production" |
|
67
|
1440 |
|
if (! preg_match('/\s+((?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\.(\d+)\.(\d+))\s+/', $version, $versionParts)) { |
|
68
|
|
|
throw DBALException::invalidPlatformVersionSpecified( |
|
|
|
|
|
|
69
|
|
|
$version, |
|
70
|
|
|
'<major_version>.<minor_version>.<patch_version>' |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
948 |
|
|
|
74
|
|
|
$majorVersion = $versionParts['major']; |
|
75
|
948 |
|
$minorVersion = $versionParts['minor'] ?? 0; |
|
76
|
|
|
$patchVersion = $versionParts['patch'] ?? 0; |
|
77
|
|
|
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion; |
|
78
|
|
|
|
|
79
|
|
|
switch (true) { |
|
80
|
|
|
case version_compare($version, '12.2', '>='): |
|
81
|
902 |
|
return new Oracle122Platform(); |
|
82
|
|
|
default: |
|
83
|
902 |
|
return new OraclePlatform(); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* {@inheritdoc} |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getDatabase(Connection $conn) |
|
91
|
|
|
{ |
|
92
|
|
|
$params = $conn->getParams(); |
|
93
|
64 |
|
|
|
94
|
|
|
return $params['user']; |
|
95
|
64 |
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* {@inheritdoc} |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getDatabasePlatform() |
|
101
|
|
|
{ |
|
102
|
|
|
return new OraclePlatform(); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* {@inheritdoc} |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getSchemaManager(Connection $conn) |
|
109
|
|
|
{ |
|
110
|
|
|
return new OracleSchemaManager($conn); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Returns an appropriate Easy Connect String for the given parameters. |
|
115
|
|
|
* |
|
116
|
|
|
* @param mixed[] $params The connection parameters to return the Easy Connect String for. |
|
117
|
|
|
* |
|
118
|
|
|
* @return string |
|
119
|
|
|
*/ |
|
120
|
|
|
protected function getEasyConnectString(array $params) |
|
121
|
|
|
{ |
|
122
|
|
|
return (string) EasyConnectString::fromConnectionParameters($params); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
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: