1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Doctrine\DBAL\Driver; |
21
|
|
|
|
22
|
|
|
use Doctrine\DBAL\DBALException; |
23
|
|
|
use Doctrine\DBAL\Driver; |
24
|
|
|
use Doctrine\DBAL\Platforms\SQLServer2005Platform; |
25
|
|
|
use Doctrine\DBAL\Platforms\SQLServer2008Platform; |
26
|
|
|
use Doctrine\DBAL\Platforms\SQLServer2012Platform; |
27
|
|
|
use Doctrine\DBAL\Platforms\SQLServerPlatform; |
28
|
|
|
use Doctrine\DBAL\Schema\SQLServerSchemaManager; |
29
|
|
|
use Doctrine\DBAL\VersionAwarePlatformDriver; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Microsoft SQL Server based drivers. |
33
|
|
|
* |
34
|
|
|
* @author Steve Müller <[email protected]> |
35
|
|
|
* @link www.doctrine-project.org |
36
|
|
|
* @since 2.5 |
37
|
|
|
*/ |
38
|
|
|
abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDriver |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
6 |
|
public function createDatabasePlatformForVersion($version) |
44
|
|
|
{ |
45
|
6 |
|
if ( ! preg_match( |
46
|
6 |
|
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/', |
47
|
6 |
|
$version, |
48
|
6 |
|
$versionParts |
49
|
|
|
)) { |
50
|
3 |
|
throw DBALException::invalidPlatformVersionSpecified( |
51
|
3 |
|
$version, |
52
|
3 |
|
'<major_version>.<minor_version>.<patch_version>.<build_version>' |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
3 |
|
$majorVersion = $versionParts['major']; |
57
|
3 |
|
$minorVersion = $versionParts['minor'] ?? 0; |
58
|
3 |
|
$patchVersion = $versionParts['patch'] ?? 0; |
59
|
3 |
|
$buildVersion = $versionParts['build'] ?? 0; |
60
|
3 |
|
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion; |
61
|
|
|
|
62
|
|
|
switch(true) { |
63
|
3 |
|
case version_compare($version, '11.00.2100', '>='): |
|
|
|
|
64
|
3 |
|
return new SQLServer2012Platform(); |
65
|
3 |
|
case version_compare($version, '10.00.1600', '>='): |
|
|
|
|
66
|
3 |
|
return new SQLServer2008Platform(); |
67
|
3 |
|
case version_compare($version, '9.00.1399', '>='): |
|
|
|
|
68
|
3 |
|
return new SQLServer2005Platform(); |
69
|
|
|
default: |
|
|
|
|
70
|
3 |
|
return new SQLServerPlatform(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
3 |
|
public function getDatabase(\Doctrine\DBAL\Connection $conn) |
78
|
|
|
{ |
79
|
3 |
|
$params = $conn->getParams(); |
80
|
|
|
|
81
|
3 |
|
return $params['dbname'] ?? $conn->query('SELECT DB_NAME()')->fetchColumn(); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
4 |
|
public function getDatabasePlatform() |
88
|
|
|
{ |
89
|
4 |
|
return new SQLServer2008Platform(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
|
|
|
96
|
3 |
|
public function getSchemaManager(\Doctrine\DBAL\Connection $conn) |
97
|
|
|
{ |
98
|
3 |
|
return new SQLServerSchemaManager($conn); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next
break
.There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.