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