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\DriverException as DriverExceptionInterface; |
10
|
|
|
use Doctrine\DBAL\Exception; |
11
|
|
|
use Doctrine\DBAL\Exception\DriverException; |
|
|
|
|
12
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
13
|
|
|
use Doctrine\DBAL\Platforms\Exception\InvalidPlatformVersion; |
14
|
|
|
use Doctrine\DBAL\Platforms\SQLAnywherePlatform; |
15
|
|
|
use Doctrine\DBAL\Schema\AbstractSchemaManager; |
16
|
|
|
use Doctrine\DBAL\Schema\SQLAnywhereSchemaManager; |
17
|
|
|
use Doctrine\DBAL\VersionAwarePlatformDriver; |
18
|
|
|
use function preg_match; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for SAP Sybase SQL Anywhere based drivers. |
22
|
|
|
*/ |
23
|
|
|
abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
* |
28
|
|
|
* @link http://dcx.sybase.com/index.html#sa160/en/saerrors/sqlerror.html |
29
|
|
|
*/ |
30
|
196 |
|
public function convertException(string $message, DriverExceptionInterface $exception) : DriverException |
31
|
|
|
{ |
32
|
196 |
|
switch ($exception->getCode()) { |
33
|
|
|
case -306: |
34
|
|
|
case -307: |
35
|
|
|
case -684: |
36
|
3 |
|
return new Exception\DeadlockException($message, $exception); |
37
|
|
|
case -210: |
38
|
|
|
case -1175: |
39
|
|
|
case -1281: |
40
|
3 |
|
return new Exception\LockWaitTimeoutException($message, $exception); |
41
|
|
|
case -100: |
42
|
|
|
case -103: |
43
|
|
|
case -832: |
44
|
178 |
|
return new Exception\ConnectionException($message, $exception); |
45
|
|
|
case -143: |
46
|
1 |
|
return new Exception\InvalidFieldNameException($message, $exception); |
47
|
|
|
case -193: |
48
|
|
|
case -196: |
49
|
2 |
|
return new Exception\UniqueConstraintViolationException($message, $exception); |
50
|
|
|
case -194: |
51
|
|
|
case -198: |
52
|
1 |
|
return new Exception\ForeignKeyConstraintViolationException($message, $exception); |
53
|
|
|
case -144: |
54
|
1 |
|
return new Exception\NonUniqueFieldNameException($message, $exception); |
55
|
|
|
case -184: |
56
|
|
|
case -195: |
57
|
2 |
|
return new Exception\NotNullConstraintViolationException($message, $exception); |
58
|
|
|
case -131: |
59
|
1 |
|
return new Exception\SyntaxErrorException($message, $exception); |
60
|
|
|
case -110: |
61
|
1 |
|
return new Exception\TableExistsException($message, $exception); |
62
|
|
|
case -141: |
63
|
|
|
case -1041: |
64
|
2 |
|
return new Exception\TableNotFoundException($message, $exception); |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
return new DriverException($message, $exception); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
127 |
|
public function createDatabasePlatformForVersion(string $version) : AbstractPlatform |
74
|
|
|
{ |
75
|
127 |
|
if (! preg_match( |
76
|
2 |
|
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/', |
77
|
127 |
|
$version, |
78
|
127 |
|
$versionParts |
79
|
|
|
)) { |
80
|
101 |
|
throw InvalidPlatformVersion::new( |
81
|
101 |
|
$version, |
82
|
101 |
|
'<major_version>.<minor_version>.<patch_version>.<build_version>' |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
126 |
|
switch (true) { |
87
|
|
|
default: |
88
|
126 |
|
return new SQLAnywherePlatform(); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
76 |
|
public function getDatabasePlatform() : AbstractPlatform |
96
|
|
|
{ |
97
|
76 |
|
return new SQLAnywherePlatform(); |
98
|
|
|
} |
99
|
76 |
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
|
|
public function getSchemaManager(Connection $conn) : AbstractSchemaManager |
104
|
|
|
{ |
105
|
51 |
|
return new SQLAnywhereSchemaManager($conn); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are 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.php
However, as
OtherDir/Foo.php
does 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: