Commit f12cf9c1 authored by Steve Müller's avatar Steve Müller

extract abstract base driver classes for vendors

parent 3176f51d
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Schema\DB2SchemaManager;
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for IBM DB2 based drivers.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
abstract class AbstractDB2Driver implements Driver
{
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
return $params['dbname'];
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new DB2Platform();
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
{
return new DB2SchemaManager($conn);
}
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\MySQL57Platform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\MySqlSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for MySQL based drivers.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
{
/**
* {@inheritdoc}
*
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-client.html
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html
*/
public function convertException($message, DriverException $exception)
{
switch ($exception->getErrorCode()) {
case '1050':
return new Exception\TableExistsException($message, $exception);
case '1051':
case '1146':
return new Exception\TableNotFoundException($message, $exception);
case '1216':
case '1217':
case '1451':
case '1452':
return new Exception\ForeignKeyConstraintViolationException($message, $exception);
case '1062':
case '1557':
case '1569':
case '1586':
return new Exception\UniqueConstraintViolationException($message, $exception);
case '1054':
case '1166':
case '1611':
return new Exception\InvalidFieldNameException($message, $exception);
case '1052':
case '1060':
case '1110':
return new Exception\NonUniqueFieldNameException($message, $exception);
case '1064':
case '1149':
case '1287':
case '1341':
case '1342':
case '1343':
case '1344':
case '1382':
case '1479':
case '1541':
case '1554':
case '1626':
return new Exception\SyntaxErrorException($message, $exception);
case '1044':
case '1045':
case '1046':
case '1049':
case '1095':
case '1142':
case '1143':
case '1227':
case '1370':
case '2002':
case '2005':
return new Exception\ConnectionException($message, $exception);
case '1048':
case '1121':
case '1138':
case '1171':
case '1252':
case '1263':
case '1566':
return new Exception\NotNullConstraintViolationException($message, $exception);
}
return new Exception\DriverException($message, $exception);
}
/**
* {@inheritdoc}
*/
public function createDatabasePlatformForVersion($version)
{
if ( ! preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts)) {
throw DBALException::invalidPlatformVersionSpecified(
$version,
'<major_version>.<minor_version>.<patch_version>'
);
}
$majorVersion = $versionParts['major'];
$minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
$patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
if (version_compare($version, '5.7', '>=')) {
return new MySQL57Platform();
}
return $this->getDatabasePlatform();
}
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
if (isset($params['dbname'])) {
return $params['dbname'];
}
return $conn->query('SELECT DATABASE()')->fetchColumn();
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new MySqlPlatform();
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
{
return new MySqlSchemaManager($conn);
}
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Schema\OracleSchemaManager;
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Oracle based drivers.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver
{
/**
* {@inheritdoc}
*/
public function convertException($message, DriverException $exception)
{
switch ($exception->getErrorCode()) {
case '1':
case '2299':
case '38911':
return new Exception\UniqueConstraintViolationException($message, $exception);
case '904':
return new Exception\InvalidFieldNameException($message, $exception);
case '918':
case '960':
return new Exception\NonUniqueFieldNameException($message, $exception);
case '923':
return new Exception\SyntaxErrorException($message, $exception);
case '942':
return new Exception\TableNotFoundException($message, $exception);
case '955':
return new Exception\TableExistsException($message, $exception);
case '1017':
case '12545':
return new Exception\ConnectionException($message, $exception);
case '1400':
return new Exception\NotNullConstraintViolationException($message, $exception);
case '2292':
return new Exception\ForeignKeyConstraintViolationException($message, $exception);
}
return new Exception\DriverException($message, $exception);
}
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
return $params['user'];
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new OraclePlatform();
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
{
return new OracleSchemaManager($conn);
}
/**
* Returns an appropriate Easy Connect String for the given parameters.
*
* @param array $params The connection parameters to return the Easy Connect STring for.
*
* @return string
*
* @link http://download.oracle.com/docs/cd/E11882_01/network.112/e10836/naming.htm
*/
protected function getEasyConnectString(array $params)
{
if ( ! empty($params['host'])) {
if ( ! isset($params['port'])) {
$params['port'] = 1521;
}
$serviceName = $params['dbname'];
if ( ! empty($params['servicename'])) {
$serviceName = $params['servicename'];
}
$service = 'SID=' . $serviceName;
$pooled = '';
if (isset($params['service']) && $params['service'] == true) {
$service = 'SERVICE_NAME=' . $serviceName;
}
if (isset($params['pooled']) && $params['pooled'] == true) {
$pooled = '(SERVER=POOLED)';
}
return '(DESCRIPTION=' .
'(ADDRESS=(PROTOCOL=TCP)(HOST=' . $params['host'] . ')(PORT=' . $params['port'] . '))' .
'(CONNECT_DATA=(' . $service . ')' . $pooled . '))';
}
return isset($params['dbname']) ? $params['dbname'] : '';
}
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\PostgreSQL92Platform;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Schema\PostgreSqlSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for PostgreSQL based drivers.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
{
/**
* {@inheritdoc}
*
* @link http://www.postgresql.org/docs/9.3/static/errcodes-appendix.html
*/
public function convertException($message, DriverException $exception)
{
switch ($exception->getSQLState()) {
case '23502':
return new Exception\NotNullConstraintViolationException($message, $exception);
case '23503':
return new Exception\ForeignKeyConstraintViolationException($message, $exception);
case '23505':
return new Exception\UniqueConstraintViolationException($message, $exception);
case '42601':
return new Exception\SyntaxErrorException($message, $exception);
case '42702':
return new Exception\NonUniqueFieldNameException($message, $exception);
case '42703':
return new Exception\InvalidFieldNameException($message, $exception);
case '42P01':
return new Exception\TableNotFoundException($message, $exception);
case '42P07':
return new Exception\TableExistsException($message, $exception);
case '7':
// In some case (mainly connection errors) the PDO exception does not provide a SQLSTATE via its code.
// The exception code is always set to 7 here.
// We have to match against the SQLSTATE in the error message in these cases.
if (strpos($exception->getMessage(), 'SQLSTATE[08006]') !== false) {
return new Exception\ConnectionException($message, $exception);
}
break;
}
return new Exception\DriverException($message, $exception);
}
/**
* {@inheritdoc}
*/
public function createDatabasePlatformForVersion($version)
{
if ( ! preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts)) {
throw DBALException::invalidPlatformVersionSpecified(
$version,
'<major_version>.<minor_version>.<patch_version>'
);
}
$majorVersion = $versionParts['major'];
$minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
$patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
if (version_compare($version, '9.2', '>=')) {
return new PostgreSQL92Platform();
}
return $this->getDatabasePlatform();
}
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
return (isset($params['dbname']))
? $params['dbname']
: $conn->query('SELECT CURRENT_DATABASE()')->fetchColumn();
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new PostgreSqlPlatform();
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
{
return new PostgreSqlSchemaManager($conn);
}
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\SQLAnywhere11Platform;
use Doctrine\DBAL\Platforms\SQLAnywhere12Platform;
use Doctrine\DBAL\Platforms\SQLAnywhere16Platform;
use Doctrine\DBAL\Platforms\SQLAnywherePlatform;
use Doctrine\DBAL\Schema\SQLAnywhereSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for SAP Sybase SQL Anywhere based drivers.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
{
/**
* {@inheritdoc}
*
* @link http://dcx.sybase.com/index.html#sa160/en/saerrors/sqlerror.html
*/
public function convertException($message, DriverException $exception)
{
switch ($exception->getErrorCode()) {
case '-100':
case '-103':
case '-832':
return new Exception\ConnectionException($message, $exception);
case '-143':
return new Exception\InvalidFieldNameException($message, $exception);
case '-193':
case '-196':
return new Exception\UniqueConstraintViolationException($message, $exception);
case '-198':
return new Exception\ForeignKeyConstraintViolationException($message, $exception);
case '-144':
return new Exception\NonUniqueFieldNameException($message, $exception);
case '-184':
case '-195':
return new Exception\NotNullConstraintViolationException($message, $exception);
case '-131':
return new Exception\SyntaxErrorException($message, $exception);
case '-110':
return new Exception\TableExistsException($message, $exception);
case '-141':
case '-1041':
return new Exception\TableNotFoundException($message, $exception);
}
return new Exception\DriverException($message, $exception);
}
/**
* {@inheritdoc}
*/
public function createDatabasePlatformForVersion($version)
{
if ( ! preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/',
$version,
$versionParts
)) {
throw DBALException::invalidPlatformVersionSpecified(
$version,
'<major_version>.<minor_version>.<patch_version>.<build_version>'
);
}
$majorVersion = $versionParts['major'];
$minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
$patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0;
$buildVersion = isset($versionParts['build']) ? $versionParts['build'] : 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion;
switch(true) {
case version_compare($version, '16', '>='):
return new SQLAnywhere16Platform();
case version_compare($version, '12', '>='):
return new SQLAnywhere12Platform();
case version_compare($version, '11', '>='):
return new SQLAnywhere11Platform();
default:
return new SQLAnywherePlatform();
}
}
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
return $params['dbname'];
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new SQLAnywhere12Platform();
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
{
return new SQLAnywhereSchemaManager($conn);
}
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\SQLServer2005Platform;
use Doctrine\DBAL\Platforms\SQLServer2008Platform;
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\SQLServerSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Microsoft SQL Server based drivers.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDriver
{
/**
* {@inheritdoc}
*/
public function createDatabasePlatformForVersion($version)
{
if ( ! preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/',
$version,
$versionParts
)) {
throw DBALException::invalidPlatformVersionSpecified(
$version,
'<major_version>.<minor_version>.<patch_version>.<build_version>'
);
}
$majorVersion = $versionParts['major'];
$minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
$patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0;
$buildVersion = isset($versionParts['build']) ? $versionParts['build'] : 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . $buildVersion;
switch(true) {
case version_compare($version, '11.00.2100', '>='):
return new SQLServer2012Platform();
case version_compare($version, '10.00.1600', '>='):
return new SQLServer2008Platform();
case version_compare($version, '9.00.1399', '>='):
return new SQLServer2005Platform();
default:
return new SQLServerPlatform();
}
}
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
return $params['dbname'];
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new SQLServer2008Platform();
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
{
return new SQLServerSchemaManager($conn);
}
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\SqliteSchemaManager;
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for SQLite based drivers.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver
{
/**
* {@inheritdoc}
*
* @link http://www.sqlite.org/c3ref/c_abort.html
*/
public function convertException($message, DriverException $exception)
{
if (strpos($exception->getMessage(), 'must be unique') !== false) {
return new Exception\UniqueConstraintViolationException($message, $exception);
}
if (strpos($exception->getMessage(), 'may not be NULL') !== false) {
return new Exception\NotNullConstraintViolationException($message, $exception);
}
if (strpos($exception->getMessage(), 'is not unique') !== false) {
return new Exception\UniqueConstraintViolationException($message, $exception);
}
if (strpos($exception->getMessage(), 'no such table:') !== false) {
return new Exception\TableNotFoundException($message, $exception);
}
if (strpos($exception->getMessage(), 'already exists') !== false) {
return new Exception\TableExistsException($message, $exception);
}
if (strpos($exception->getMessage(), 'has no column named') !== false) {
return new Exception\InvalidFieldNameException($message, $exception);
}
if (strpos($exception->getMessage(), 'ambiguous column name') !== false) {
return new Exception\NonUniqueFieldNameException($message, $exception);
}
if (strpos($exception->getMessage(), 'syntax error') !== false) {
return new Exception\SyntaxErrorException($message, $exception);
}
if (strpos($exception->getMessage(), 'attempt to write a readonly database') !== false) {
return new Exception\ReadOnlyException($message, $exception);
}
if (strpos($exception->getMessage(), 'unable to open database file') !== false) {
return new Exception\ConnectionException($message, $exception);
}
return new Exception\DriverException($message, $exception);
}
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
return isset($params['path']) ? $params['path'] : null;
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new SqlitePlatform();
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
{
return new SqliteSchemaManager($conn);
}
}
......@@ -19,19 +19,15 @@
namespace Doctrine\DBAL\Driver\DrizzlePDOMySql;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\DrizzlePlatform;
use Doctrine\DBAL\Schema\DrizzleSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
/**
* Drizzle driver using PDO MySql.
*
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
*/
class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
class Driver extends \Doctrine\DBAL\Driver\PDOMySql\Driver
{
/**
* {@inheritdoc}
......@@ -39,7 +35,7 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{
$conn = new Connection(
$this->_constructPdoDsn($params),
$this->constructPdoDsn($params),
$username,
$password,
$driverOptions
......@@ -48,32 +44,6 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
return $conn;
}
/**
* Constructs the Drizzle MySql PDO DSN.
*
* @param array $params
*
* @return string The DSN.
*/
private function _constructPdoDsn(array $params)
{
$dsn = 'mysql:';
if (isset($params['host']) && $params['host'] != '') {
$dsn .= 'host=' . $params['host'] . ';';
}
if (isset($params['port'])) {
$dsn .= 'port=' . $params['port'] . ';';
}
if (isset($params['dbname'])) {
$dsn .= 'dbname=' . $params['dbname'] . ';';
}
if (isset($params['unix_socket'])) {
$dsn .= 'unix_socket=' . $params['unix_socket'] . ';';
}
return $dsn;
}
/**
* {@inheritdoc}
*/
......@@ -105,92 +75,4 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
{
return 'drizzle_pdo_mysql';
}
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
return $params['dbname'];
}
/**
* {@inheritdoc}
*
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-client.html
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html
*/
public function convertException($message, DriverException $exception)
{
switch ($exception->getErrorCode()) {
case '1050':
return new Exception\TableExistsException($message, $exception);
case '1051':
case '1146':
return new Exception\TableNotFoundException($message, $exception);
case '1216':
case '1217':
case '1451':
case '1452':
return new Exception\ForeignKeyConstraintViolationException($message, $exception);
case '1062':
case '1557':
case '1569':
case '1586':
return new Exception\UniqueConstraintViolationException($message, $exception);
case '1054':
case '1166':
case '1611':
return new Exception\InvalidFieldNameException($message, $exception);
case '1052':
case '1060':
case '1110':
return new Exception\NonUniqueFieldNameException($message, $exception);
case '1064':
case '1149':
case '1287':
case '1341':
case '1342':
case '1343':
case '1344':
case '1382':
case '1479':
case '1541':
case '1554':
case '1626':
return new Exception\SyntaxErrorException($message, $exception);
case '1044':
case '1045':
case '1046':
case '1049':
case '1095':
case '1142':
case '1143':
case '1227':
case '1370':
case '2002':
case '2005':
return new Exception\ConnectionException($message, $exception);
case '1048':
case '1121':
case '1138':
case '1171':
case '1252':
case '1263':
case '1566':
return new Exception\NotNullConstraintViolationException($message, $exception);
}
return new Exception\DriverException($message, $exception);
}
}
......@@ -19,11 +19,7 @@
namespace Doctrine\DBAL\Driver\IBMDB2;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Schema\DB2SchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
use Doctrine\DBAL\Driver\AbstractDB2Driver;
/**
* IBM DB2 Driver.
......@@ -31,7 +27,7 @@ use Doctrine\DBAL\VersionAwarePlatformDriver;
* @since 2.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class DB2Driver implements Driver, VersionAwarePlatformDriver
class DB2Driver extends AbstractDB2Driver
{
/**
* {@inheritdoc}
......@@ -61,30 +57,6 @@ class DB2Driver implements Driver, VersionAwarePlatformDriver
return new DB2Connection($params, $username, $password, $driverOptions);
}
/**
* {@inheritdoc}
*/
public function createDatabasePlatformForVersion($version)
{
return $this->getDatabasePlatform();
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new DB2Platform();
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(Connection $conn)
{
return new DB2SchemaManager($conn);
}
/**
* {@inheritdoc}
*/
......@@ -92,22 +64,4 @@ class DB2Driver implements Driver, VersionAwarePlatformDriver
{
return 'ibm_db2';
}
/**
* {@inheritdoc}
*/
public function getDatabase(Connection $conn)
{
$params = $conn->getParams();
return $params['dbname'];
}
/**
* {@inheritdoc}
*/
public function convertExceptionCode(\Exception $exception)
{
return 0;
}
}
......@@ -19,19 +19,13 @@
namespace Doctrine\DBAL\Driver\Mysqli;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\AbstractMySQLDriver;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\MySQL57Platform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\VersionAwarePlatformDriver;
/**
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
*/
class Driver implements DriverInterface, ExceptionConverterDriver, VersionAwarePlatformDriver
class Driver extends AbstractMySQLDriver
{
/**
* {@inheritdoc}
......@@ -52,132 +46,4 @@ class Driver implements DriverInterface, ExceptionConverterDriver, VersionAwareP
{
return 'mysqli';
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(Connection $conn)
{
return new \Doctrine\DBAL\Schema\MySqlSchemaManager($conn);
}
/**
* {@inheritdoc}
*/
public function createDatabasePlatformForVersion($version)
{
if ( ! preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts)) {
throw DBALException::invalidPlatformVersionSpecified(
$version,
'<major_version>.<minor_version>.<patch_version>'
);
}
$majorVersion = $versionParts['major'];
$minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
$patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
if (version_compare($version, '5.7', '>=')) {
return new MySQL57Platform();
}
return $this->getDatabasePlatform();
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new MySqlPlatform();
}
/**
* {@inheritdoc}
*/
public function getDatabase(Connection $conn)
{
$params = $conn->getParams();
return $params['dbname'];
}
/**
* {@inheritdoc}
*
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-client.html
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html
*/
public function convertException($message, DriverInterface\DriverException $exception)
{
switch ($exception->getErrorCode()) {
case '1050':
return new Exception\TableExistsException($message, $exception);
case '1051':
case '1146':
return new Exception\TableNotFoundException($message, $exception);
case '1216':
case '1217':
case '1451':
case '1452':
return new Exception\ForeignKeyConstraintViolationException($message, $exception);
case '1062':
case '1557':
case '1569':
case '1586':
return new Exception\UniqueConstraintViolationException($message, $exception);
case '1054':
case '1166':
case '1611':
return new Exception\InvalidFieldNameException($message, $exception);
case '1052':
case '1060':
case '1110':
return new Exception\NonUniqueFieldNameException($message, $exception);
case '1064':
case '1149':
case '1287':
case '1341':
case '1342':
case '1343':
case '1344':
case '1382':
case '1479':
case '1541':
case '1554':
case '1626':
return new Exception\SyntaxErrorException($message, $exception);
case '1044':
case '1045':
case '1046':
case '1049':
case '1095':
case '1142':
case '1143':
case '1227':
case '1370':
case '2002':
case '2005':
return new Exception\ConnectionException($message, $exception);
case '1048':
case '1121':
case '1138':
case '1171':
case '1252':
case '1263':
case '1566':
return new Exception\NotNullConstraintViolationException($message, $exception);
}
return new Exception\DriverException($message, $exception);
}
}
......@@ -19,14 +19,8 @@
namespace Doctrine\DBAL\Driver\OCI8;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Schema\OracleSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
use Doctrine\DBAL\Driver\AbstractOracleDriver;
/**
* A Doctrine DBAL driver for the Oracle OCI8 PHP extensions.
......@@ -34,7 +28,7 @@ use Doctrine\DBAL\VersionAwarePlatformDriver;
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
class Driver extends AbstractOracleDriver
{
/**
* {@inheritdoc}
......@@ -64,64 +58,7 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
*/
protected function _constructDsn(array $params)
{
$dsn = '';
if (isset($params['host']) && $params['host'] != '') {
$dsn .= '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)' .
'(HOST=' . $params['host'] . ')';
if (isset($params['port'])) {
$dsn .= '(PORT=' . $params['port'] . ')';
} else {
$dsn .= '(PORT=1521)';
}
$serviceName = $params['dbname'];
if ( ! empty($params['servicename'])) {
$serviceName = $params['servicename'];
}
$service = 'SID=' . $serviceName;
$pooled = '';
if (isset($params['service']) && $params['service'] == true) {
$service = 'SERVICE_NAME=' . $serviceName;
}
if (isset($params['pooled']) && $params['pooled'] == true) {
$pooled = '(SERVER=POOLED)';
}
$dsn .= '))(CONNECT_DATA=(' . $service . ')' . $pooled . '))';
} else {
$dsn .= $params['dbname'];
}
return $dsn;
}
/**
* {@inheritdoc}
*/
public function createDatabasePlatformForVersion($version)
{
return $this->getDatabasePlatform();
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new OraclePlatform();
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(Connection $conn)
{
return new OracleSchemaManager($conn);
return $this->getEasyConnectString($params);
}
/**
......@@ -131,55 +68,4 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
{
return 'oci8';
}
/**
* {@inheritdoc}
*/
public function getDatabase(Connection $conn)
{
$params = $conn->getParams();
return $params['user'];
}
/**
* {@inheritdoc}
*/
public function convertException($message, DriverException $exception)
{
switch ($exception->getErrorCode()) {
case '1':
case '2299':
case '38911':
return new Exception\UniqueConstraintViolationException($message, $exception);
case '904':
return new Exception\InvalidFieldNameException($message, $exception);
case '918':
case '960':
return new Exception\NonUniqueFieldNameException($message, $exception);
case '923':
return new Exception\SyntaxErrorException($message, $exception);
case '942':
return new Exception\TableNotFoundException($message, $exception);
case '955':
return new Exception\TableExistsException($message, $exception);
case '1017':
case '12545':
return new Exception\ConnectionException($message, $exception);
case '1400':
return new Exception\NotNullConstraintViolationException($message, $exception);
case '2292':
return new Exception\ForeignKeyConstraintViolationException($message, $exception);
}
return new Exception\DriverException($message, $exception);
}
}
......@@ -19,10 +19,8 @@
namespace Doctrine\DBAL\Driver\PDOIbm;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\AbstractDB2Driver;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Schema\DB2SchemaManager;
/**
* Driver for the PDO IBM extension.
......@@ -34,7 +32,7 @@ use Doctrine\DBAL\Schema\DB2SchemaManager;
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class Driver implements \Doctrine\DBAL\Driver
class Driver extends AbstractDB2Driver
{
/**
* {@inheritdoc}
......@@ -75,22 +73,6 @@ class Driver implements \Doctrine\DBAL\Driver
return $dsn;
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new DB2Platform();
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(Connection $conn)
{
return new DB2SchemaManager($conn);
}
/**
* {@inheritdoc}
*/
......@@ -98,22 +80,4 @@ class Driver implements \Doctrine\DBAL\Driver
{
return 'pdo_ibm';
}
/**
* {@inheritdoc}
*/
public function getDatabase(Connection $conn)
{
$params = $conn->getParams();
return $params['dbname'];
}
/**
* {@inheritdoc}
*/
public function convertExceptionCode(\Exception $exception)
{
return 0;
}
}
......@@ -19,16 +19,9 @@
namespace Doctrine\DBAL\Driver\PDOMySql;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
use Doctrine\DBAL\Driver\AbstractMySQLDriver;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\MySQL57Platform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\VersionAwarePlatformDriver;
use Doctrine\DBAL\Schema\MySqlSchemaManager;
use PDOException;
/**
......@@ -36,7 +29,7 @@ use PDOException;
*
* @since 2.0
*/
class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
class Driver extends AbstractMySQLDriver
{
/**
* {@inheritdoc}
......@@ -45,7 +38,7 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
{
try {
$conn = new PDOConnection(
$this->_constructPdoDsn($params),
$this->constructPdoDsn($params),
$username,
$password,
$driverOptions
......@@ -64,7 +57,7 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
*
* @return string The DSN.
*/
private function _constructPdoDsn(array $params)
protected function constructPdoDsn(array $params)
{
$dsn = 'mysql:';
if (isset($params['host']) && $params['host'] != '') {
......@@ -86,46 +79,6 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
return $dsn;
}
/**
* {@inheritdoc}
*/
public function createDatabasePlatformForVersion($version)
{
if ( ! preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts)) {
throw DBALException::invalidPlatformVersionSpecified(
$version,
'<major_version>.<minor_version>.<patch_version>'
);
}
$majorVersion = $versionParts['major'];
$minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
$patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
if (version_compare($version, '5.7', '>=')) {
return new MySQL57Platform();
}
return $this->getDatabasePlatform();
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new MySqlPlatform();
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(Connection $conn)
{
return new MySqlSchemaManager($conn);
}
/**
* {@inheritdoc}
*/
......@@ -133,95 +86,4 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
{
return 'pdo_mysql';
}
/**
* {@inheritdoc}
*/
public function getDatabase(Connection $conn)
{
$params = $conn->getParams();
if (isset($params['dbname'])) {
return $params['dbname'];
}
return $conn->query('SELECT DATABASE()')->fetchColumn();
}
/**
* {@inheritdoc}
*
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-client.html
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html
*/
public function convertException($message, DriverException $exception)
{
switch ($exception->getErrorCode()) {
case '1050':
return new Exception\TableExistsException($message, $exception);
case '1051':
case '1146':
return new Exception\TableNotFoundException($message, $exception);
case '1216':
case '1217':
case '1451':
case '1452':
return new Exception\ForeignKeyConstraintViolationException($message, $exception);
case '1062':
case '1557':
case '1569':
case '1586':
return new Exception\UniqueConstraintViolationException($message, $exception);
case '1054':
case '1166':
case '1611':
return new Exception\InvalidFieldNameException($message, $exception);
case '1052':
case '1060':
case '1110':
return new Exception\NonUniqueFieldNameException($message, $exception);
case '1064':
case '1149':
case '1287':
case '1341':
case '1342':
case '1343':
case '1344':
case '1382':
case '1479':
case '1541':
case '1554':
case '1626':
return new Exception\SyntaxErrorException($message, $exception);
case '1044':
case '1045':
case '1046':
case '1049':
case '1095':
case '1142':
case '1143':
case '1227':
case '1370':
case '2002':
case '2005':
return new Exception\ConnectionException($message, $exception);
case '1048':
case '1121':
case '1138':
case '1171':
case '1252':
case '1263':
case '1566':
return new Exception\NotNullConstraintViolationException($message, $exception);
}
return new Exception\DriverException($message, $exception);
}
}
......@@ -19,15 +19,9 @@
namespace Doctrine\DBAL\Driver\PDOOracle;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
use Doctrine\DBAL\Driver\AbstractOracleDriver;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Schema\OracleSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
/**
* PDO Oracle driver.
......@@ -37,7 +31,7 @@ use Doctrine\DBAL\VersionAwarePlatformDriver;
* which leads us to the recommendation to use the "oci8" driver to connect
* to Oracle instead.
*/
class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
class Driver extends AbstractOracleDriver
{
/**
* {@inheritdoc}
......@@ -46,7 +40,7 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
{
try {
return new PDOConnection(
$this->_constructPdoDsn($params),
$this->constructPdoDsn($params),
$username,
$password,
$driverOptions
......@@ -63,41 +57,9 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
*
* @return string The DSN.
*/
private function _constructPdoDsn(array $params)
private function constructPdoDsn(array $params)
{
$dsn = 'oci:dbname=';
if (isset($params['host']) && $params['host'] != '') {
$dsn .= '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)' .
'(HOST=' . $params['host'] . ')';
if (isset($params['port'])) {
$dsn .= '(PORT=' . $params['port'] . ')';
} else {
$dsn .= '(PORT=1521)';
}
$serviceName = $params['dbname'];
if ( ! empty($params['servicename'])) {
$serviceName = $params['servicename'];
}
$service = 'SID=' . $serviceName;
$pooled = '';
if (isset($params['service']) && $params['service'] == true) {
$service = 'SERVICE_NAME=' . $serviceName;
}
if (isset($params['pooled']) && $params['pooled'] == true) {
$pooled = '(SERVER=POOLED)';
}
$dsn .= '))(CONNECT_DATA=(' . $service . ')' . $pooled . '))';
} else {
$dsn .= $params['dbname'];
}
$dsn = 'oci:dbname=' . $this->getEasyConnectString($params);
if (isset($params['charset'])) {
$dsn .= ';charset=' . $params['charset'];
......@@ -106,30 +68,6 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
return $dsn;
}
/**
* {@inheritdoc}
*/
public function createDatabasePlatformForVersion($version)
{
return $this->getDatabasePlatform();
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new OraclePlatform();
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(Connection $conn)
{
return new OracleSchemaManager($conn);
}
/**
* {@inheritdoc}
*/
......@@ -137,55 +75,4 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
{
return 'pdo_oracle';
}
/**
* {@inheritdoc}
*/
public function getDatabase(Connection $conn)
{
$params = $conn->getParams();
return $params['user'];
}
/**
* {@inheritdoc}
*/
public function convertException($message, DriverException $exception)
{
switch ($exception->getErrorCode()) {
case '1':
case '2299':
case '38911':
return new Exception\UniqueConstraintViolationException($message, $exception);
case '904':
return new Exception\InvalidFieldNameException($message, $exception);
case '918':
case '960':
return new Exception\NonUniqueFieldNameException($message, $exception);
case '923':
return new Exception\SyntaxErrorException($message, $exception);
case '942':
return new Exception\TableNotFoundException($message, $exception);
case '955':
return new Exception\TableExistsException($message, $exception);
case '1017':
case '12545':
return new Exception\ConnectionException($message, $exception);
case '1400':
return new Exception\NotNullConstraintViolationException($message, $exception);
case '2292':
return new Exception\ForeignKeyConstraintViolationException($message, $exception);
}
return new Exception\DriverException($message, $exception);
}
}
......@@ -19,24 +19,17 @@
namespace Doctrine\DBAL\Driver\PDOPgSql;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\PostgreSQL92Platform;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\PostgreSqlSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
use PDOException;
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
/**
* Driver that connects through pdo_pgsql.
*
* @since 2.0
*/
class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
class Driver extends AbstractPostgreSQLDriver
{
/**
* {@inheritdoc}
......@@ -50,7 +43,7 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
$password,
$driverOptions
);
} catch(PDOException $e) {
} catch (PDOException $e) {
throw DBALException::driverException($this, $e);
}
}
......@@ -89,46 +82,6 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
return $dsn;
}
/**
* {@inheritdoc}
*/
public function createDatabasePlatformForVersion($version)
{
if ( ! preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts)) {
throw DBALException::invalidPlatformVersionSpecified(
$version,
'<major_version>.<minor_version>.<patch_version>'
);
}
$majorVersion = $versionParts['major'];
$minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
$patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
if (version_compare($version, '9.2', '>=')) {
return new PostgreSQL92Platform();
}
return $this->getDatabasePlatform();
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new PostgreSqlPlatform();
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(Connection $conn)
{
return new PostgreSqlSchemaManager($conn);
}
/**
* {@inheritdoc}
*/
......@@ -136,61 +89,4 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
{
return 'pdo_pgsql';
}
/**
* {@inheritdoc}
*/
public function getDatabase(Connection $conn)
{
$params = $conn->getParams();
return (isset($params['dbname']))
? $params['dbname']
: $conn->query('SELECT CURRENT_DATABASE()')->fetchColumn();
}
/**
* {@inheritdoc}
*
* @link http://www.postgresql.org/docs/9.3/static/errcodes-appendix.html
*/
public function convertException($message, DriverException $exception)
{
switch ($exception->getSQLState()) {
case '23502':
return new Exception\NotNullConstraintViolationException($message, $exception);
case '23503':
return new Exception\ForeignKeyConstraintViolationException($message, $exception);
case '23505':
return new Exception\UniqueConstraintViolationException($message, $exception);
case '42601':
return new Exception\SyntaxErrorException($message, $exception);
case '42702':
return new Exception\NonUniqueFieldNameException($message, $exception);
case '42703':
return new Exception\InvalidFieldNameException($message, $exception);
case '42P01':
return new Exception\TableNotFoundException($message, $exception);
case '42P07':
return new Exception\TableExistsException($message, $exception);
case '7':
// In some case (mainly connection errors) the PDO exception does not provide a SQLSTATE via its code.
// The exception code is always set to 7 here.
// We have to match against the SQLSTATE in the error message in these cases.
if (strpos($exception->getMessage(), 'SQLSTATE[08006]') !== false) {
return new Exception\ConnectionException($message, $exception);
}
break;
}
return new Exception\DriverException($message, $exception);
}
}
......@@ -19,15 +19,9 @@
namespace Doctrine\DBAL\Driver\PDOSqlite;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
use Doctrine\DBAL\Driver\AbstractSQLiteDriver;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\SqliteSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
use PDOException;
/**
......@@ -35,7 +29,7 @@ use PDOException;
*
* @since 2.0
*/
class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
class Driver extends AbstractSQLiteDriver
{
/**
* @var array
......@@ -94,30 +88,6 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
return $dsn;
}
/**
* {@inheritdoc}
*/
public function createDatabasePlatformForVersion($version)
{
return $this->getDatabasePlatform();
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new SqlitePlatform();
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(Connection $conn)
{
return new SqliteSchemaManager($conn);
}
/**
* {@inheritdoc}
*/
......@@ -125,64 +95,4 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
{
return 'pdo_sqlite';
}
/**
* {@inheritdoc}
*/
public function getDatabase(Connection $conn)
{
$params = $conn->getParams();
return isset($params['path']) ? $params['path'] : null;
}
/**
* {@inheritdoc}
*
* @link http://www.sqlite.org/c3ref/c_abort.html
*/
public function convertException($message, DriverException $exception)
{
if (strpos($exception->getMessage(), 'must be unique') !== false) {
return new Exception\UniqueConstraintViolationException($message, $exception);
}
if (strpos($exception->getMessage(), 'may not be NULL') !== false) {
return new Exception\NotNullConstraintViolationException($message, $exception);
}
if (strpos($exception->getMessage(), 'is not unique') !== false) {
return new Exception\UniqueConstraintViolationException($message, $exception);
}
if (strpos($exception->getMessage(), 'no such table:') !== false) {
return new Exception\TableNotFoundException($message, $exception);
}
if (strpos($exception->getMessage(), 'already exists') !== false) {
return new Exception\TableExistsException($message, $exception);
}
if (strpos($exception->getMessage(), 'has no column named') !== false) {
return new Exception\InvalidFieldNameException($message, $exception);
}
if (strpos($exception->getMessage(), 'ambiguous column name') !== false) {
return new Exception\NonUniqueFieldNameException($message, $exception);
}
if (strpos($exception->getMessage(), 'syntax error') !== false) {
return new Exception\SyntaxErrorException($message, $exception);
}
if (strpos($exception->getMessage(), 'attempt to write a readonly database') !== false) {
return new Exception\ReadOnlyException($message, $exception);
}
if (strpos($exception->getMessage(), 'unable to open database file') !== false) {
return new Exception\ConnectionException($message, $exception);
}
return new Exception\DriverException($message, $exception);
}
}
......@@ -19,20 +19,14 @@
namespace Doctrine\DBAL\Driver\PDOSqlsrv;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\SQLServer2005Platform;
use Doctrine\DBAL\Platforms\SQLServer2008Platform;
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\SQLServerSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
use Doctrine\DBAL\Driver\AbstractSQLServerDriver;
/**
* The PDO-based Sqlsrv driver.
*
* @since 2.0
*/
class Driver implements \Doctrine\DBAL\Driver, VersionAwarePlatformDriver
class Driver extends AbstractSQLServerDriver
{
/**
* {@inheritdoc}
......@@ -66,7 +60,7 @@ class Driver implements \Doctrine\DBAL\Driver, VersionAwarePlatformDriver
$dsn .= ',' . $params['port'];
}
if (isset($params['dbname'])) {;
if (isset($params['dbname'])) {
$dsn .= ';Database=' . $params['dbname'];
}
......@@ -77,56 +71,6 @@ class Driver implements \Doctrine\DBAL\Driver, VersionAwarePlatformDriver
return $dsn;
}
/**
* {@inheritdoc}
*/
public function createDatabasePlatformForVersion($version)
{
if ( ! preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/',
$version,
$versionParts
)) {
throw DBALException::invalidPlatformVersionSpecified(
$version,
'<major_version>.<minor_version>.<patch_version>.<build_version>'
);
}
$majorVersion = $versionParts['major'];
$minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
$patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0;
$buildVersion = isset($versionParts['build']) ? $versionParts['build'] : 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . $buildVersion;
switch(true) {
case version_compare($version, '11.00.2100', '>='):
return new SQLServer2012Platform();
case version_compare($version, '10.00.1600', '>='):
return new SQLServer2008Platform();
case version_compare($version, '9.00.1399', '>='):
return new SQLServer2005Platform();
default:
return new SQLServerPlatform();
}
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new SQLServer2008Platform();
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
{
return new SQLServerSchemaManager($conn);
}
/**
* {@inheritdoc}
*/
......@@ -134,22 +78,4 @@ class Driver implements \Doctrine\DBAL\Driver, VersionAwarePlatformDriver
{
return 'pdo_sqlsrv';
}
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
return $params['dbname'];
}
/**
* {@inheritdoc}
*/
public function convertExceptionCode(\Exception $exception)
{
return 0;
}
}
......@@ -19,17 +19,8 @@
namespace Doctrine\DBAL\Driver\SQLAnywhere;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\SQLAnywhere11Platform;
use Doctrine\DBAL\Platforms\SQLAnywhere12Platform;
use Doctrine\DBAL\Platforms\SQLAnywhere16Platform;
use Doctrine\DBAL\Platforms\SQLAnywherePlatform;
use Doctrine\DBAL\Schema\SQLAnywhereSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
use Doctrine\DBAL\Driver\AbstractSQLAnywhereDriver;
/**
* A Doctrine DBAL driver for the SAP Sybase SQL Anywhere PHP extension.
......@@ -38,7 +29,7 @@ use Doctrine\DBAL\VersionAwarePlatformDriver;
* @link www.doctrine-project.org
* @since 2.5
*/
class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
class Driver extends AbstractSQLAnywhereDriver
{
/**
* {@inheritdoc}
......@@ -78,94 +69,6 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
}
}
/**
* {@inheritdoc}
*/
public function createDatabasePlatformForVersion($version)
{
if ( ! preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/',
$version,
$versionParts
)) {
throw DBALException::invalidPlatformVersionSpecified(
$version,
'<major_version>.<minor_version>.<patch_version>.<build_version>'
);
}
$majorVersion = $versionParts['major'];
$minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
$patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0;
$buildVersion = isset($versionParts['build']) ? $versionParts['build'] : 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion;
switch(true) {
case version_compare($version, '16', '>='):
return new SQLAnywhere16Platform();
case version_compare($version, '12', '>='):
return new SQLAnywhere12Platform();
case version_compare($version, '11', '>='):
return new SQLAnywhere11Platform();
default:
return new SQLAnywherePlatform();
}
}
/**
* {@inheritdoc}
*
* @link http://dcx.sybase.com/index.html#sa160/en/saerrors/sqlerror.html
*/
public function convertException($message, DriverException $exception)
{
switch ($exception->getErrorCode()) {
case '-100':
case '-103':
case '-832':
return new Exception\ConnectionException($message, $exception);
case '-143':
return new Exception\InvalidFieldNameException($message, $exception);
case '-193':
case '-196':
return new Exception\UniqueConstraintViolationException($message, $exception);
case '-198':
return new Exception\ForeignKeyConstraintViolationException($message, $exception);
case '-144':
return new Exception\NonUniqueFieldNameException($message, $exception);
case '-184':
case '-195':
return new Exception\NotNullConstraintViolationException($message, $exception);
case '-131':
return new Exception\SyntaxErrorException($message, $exception);
case '-110':
return new Exception\TableExistsException($message, $exception);
case '-141':
case '-1041':
return new Exception\TableNotFoundException($message, $exception);
}
return new Exception\DriverException($message, $exception);
}
/**
* {@inheritdoc}
*/
public function getDatabase(Connection $conn)
{
$params = $conn->getParams();
return $params['dbname'];
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new SQLAnywhere12Platform();
}
/**
* {@inheritdoc}
*/
......@@ -174,14 +77,6 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver, Version
return 'sqlanywhere';
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(Connection $conn)
{
return new SQLAnywhereSchemaManager($conn);
}
/**
* Build the connection string for given connection parameters and driver options.
*
......
......@@ -19,19 +19,12 @@
namespace Doctrine\DBAL\Driver\SQLSrv;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\SQLServer2005Platform;
use Doctrine\DBAL\Platforms\SQLServer2008Platform;
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\SQLServerSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
use Doctrine\DBAL\Driver\AbstractSQLServerDriver;
/**
* Driver for ext/sqlsrv.
*/
class Driver implements \Doctrine\DBAL\Driver, VersionAwarePlatformDriver
class Driver extends AbstractSQLServerDriver
{
/**
* {@inheritdoc}
......@@ -61,56 +54,6 @@ class Driver implements \Doctrine\DBAL\Driver, VersionAwarePlatformDriver
return new SQLSrvConnection($serverName, $driverOptions);
}
/**
* {@inheritdoc}
*/
public function createDatabasePlatformForVersion($version)
{
if ( ! preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/',
$version,
$versionParts
)) {
throw DBALException::invalidPlatformVersionSpecified(
$version,
'<major_version>.<minor_version>.<patch_version>.<build_version>'
);
}
$majorVersion = $versionParts['major'];
$minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
$patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0;
$buildVersion = isset($versionParts['build']) ? $versionParts['build'] : 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . $buildVersion;
switch(true) {
case version_compare($version, '11.00.2100', '>='):
return new SQLServer2012Platform();
case version_compare($version, '10.00.1600', '>='):
return new SQLServer2008Platform();
case version_compare($version, '9.00.1399', '>='):
return new SQLServer2005Platform();
default:
return new SQLServerPlatform();
}
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new SQLServer2008Platform();
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(Connection $conn)
{
return new SQLServerSchemaManager($conn);
}
/**
* {@inheritdoc}
*/
......@@ -118,21 +61,4 @@ class Driver implements \Doctrine\DBAL\Driver, VersionAwarePlatformDriver
{
return 'sqlsrv';
}
/**
* {@inheritdoc}
*/
public function getDatabase(Connection $conn)
{
$params = $conn->getParams();
return $params['dbname'];
}
/**
* {@inheritdoc}
*/
public function convertExceptionCode(\Exception $exception)
{
return 0;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment