Вход Регистрация
Файл: vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php
Строк: 293
<?php

namespace DoctrineDBALDriver;

use 
DoctrineDBALConnection;
use 
DoctrineDBALDriver;
use 
DoctrineDBALDriverDriverException as DeprecatedDriverException;
use 
DoctrineDBALException;
use 
DoctrineDBALExceptionConnectionException;
use 
DoctrineDBALExceptionDeadlockException;
use 
DoctrineDBALExceptionDriverException;
use 
DoctrineDBALExceptionForeignKeyConstraintViolationException;
use 
DoctrineDBALExceptionInvalidFieldNameException;
use 
DoctrineDBALExceptionNonUniqueFieldNameException;
use 
DoctrineDBALExceptionNotNullConstraintViolationException;
use 
DoctrineDBALExceptionSyntaxErrorException;
use 
DoctrineDBALExceptionTableExistsException;
use 
DoctrineDBALExceptionTableNotFoundException;
use 
DoctrineDBALExceptionUniqueConstraintViolationException;
use 
DoctrineDBALPlatformsPostgreSQL100Platform;
use 
DoctrineDBALPlatformsPostgreSQL91Platform;
use 
DoctrineDBALPlatformsPostgreSQL92Platform;
use 
DoctrineDBALPlatformsPostgreSQL94Platform;
use 
DoctrineDBALPlatformsPostgreSqlPlatform;
use 
DoctrineDBALSchemaPostgreSqlSchemaManager;
use 
DoctrineDBALVersionAwarePlatformDriver;

use function 
assert;
use function 
preg_match;
use function 
strpos;
use function 
version_compare;

/**
 * Abstract base implementation of the {@link Driver} interface for PostgreSQL based drivers.
 */
abstract class AbstractPostgreSQLDriver implements DriverExceptionConverterDriverVersionAwarePlatformDriver
{
    
/**
     * {@inheritdoc}
     *
     * @deprecated
     *
     * @link http://www.postgresql.org/docs/9.3/static/errcodes-appendix.html
     */
    
public function convertException($messageDeprecatedDriverException $exception)
    {
        
$sqlState $exception->getSQLState();

        switch (
$sqlState) {
            case 
'40001':
            case 
'40P01':
                return new 
DeadlockException($message$exception);

            case 
'0A000':
                
// Foreign key constraint violations during a TRUNCATE operation
                // are considered "feature not supported" in PostgreSQL.
                
if (strpos($exception->getMessage(), 'truncate') !== false) {
                    return new 
ForeignKeyConstraintViolationException($message$exception);
                }

                break;

            case 
'23502':
                return new 
NotNullConstraintViolationException($message$exception);

            case 
'23503':
                return new 
ForeignKeyConstraintViolationException($message$exception);

            case 
'23505':
                return new 
UniqueConstraintViolationException($message$exception);

            case 
'42601':
                return new 
SyntaxErrorException($message$exception);

            case 
'42702':
                return new 
NonUniqueFieldNameException($message$exception);

            case 
'42703':
                return new 
InvalidFieldNameException($message$exception);

            case 
'42P01':
                return new 
TableNotFoundException($message$exception);

            case 
'42P07':
                return new 
TableExistsException($message$exception);

            case 
'08006':
                return new 
ExceptionConnectionException($message$exception);

            case 
'7':
                
// Prior to fixing https://bugs.php.net/bug.php?id=64705 (PHP 7.3.22 and PHP 7.4.10),
                // in some cases (mainly connection errors) the PDO exception wouldn't provide a SQLSTATE via its code.
                // The exception code would be 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 
ConnectionException($message$exception);
                }

                break;
        }

        return new 
DriverException($message$exception);
    }

    
/**
     * {@inheritdoc}
     */
    
public function createDatabasePlatformForVersion($version)
    {
        if (! 
preg_match('/^(?P<major>d+)(?:.(?P<minor>d+)(?:.(?P<patch>d+))?)?/'$version$versionParts)) {
            throw 
Exception::invalidPlatformVersionSpecified(
                
$version,
                
'<major_version>.<minor_version>.<patch_version>'
            
);
        }

        
$majorVersion $versionParts['major'];
        
$minorVersion $versionParts['minor'] ?? 0;
        
$patchVersion $versionParts['patch'] ?? 0;
        
$version      $majorVersion '.' $minorVersion '.' $patchVersion;

        switch (
true) {
            case 
version_compare($version'10.0''>='):
                return new 
PostgreSQL100Platform();
            case 
version_compare($version'9.4''>='):
                return new 
PostgreSQL94Platform();
            case 
version_compare($version'9.2''>='):
                return new 
PostgreSQL92Platform();
            case 
version_compare($version'9.1''>='):
                return new 
PostgreSQL91Platform();
            default:
                return new 
PostgreSqlPlatform();
        }
    }

    
/**
     * {@inheritdoc}
     *
     * @deprecated Use Connection::getDatabase() instead.
     */
    
public function getDatabase(Connection $conn)
    {
        
$params $conn->getParams();

        if (isset(
$params['dbname'])) {
            return 
$params['dbname'];
        }

        
$database $conn->query('SELECT CURRENT_DATABASE()')->fetchColumn();

        
assert($database !== false);

        return 
$database;
    }

    
/**
     * {@inheritdoc}
     */
    
public function getDatabasePlatform()
    {
        return new 
PostgreSqlPlatform();
    }

    
/**
     * {@inheritdoc}
     */
    
public function getSchemaManager(Connection $conn)
    {
        return new 
PostgreSqlSchemaManager($conn);
    }
}
Онлайн: 2
Реклама