Вход Регистрация
Файл: concrete5.7.5.6/concrete/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php
Строк: 232
<?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 DoctrineDBALDriver;

use 
DoctrineDBALDBALException;
use 
DoctrineDBALDriver;
use 
DoctrineDBALException;
use 
DoctrineDBALPlatformsPostgreSQL91Platform;
use 
DoctrineDBALPlatformsPostgreSQL92Platform;
use 
DoctrineDBALPlatformsPostgreSqlPlatform;
use 
DoctrineDBALSchemaPostgreSqlSchemaManager;
use 
DoctrineDBALVersionAwarePlatformDriver;

/**
 * Abstract base implementation of the {@link DoctrineDBALDriver} 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 DriverExceptionConverterDriverVersionAwarePlatformDriver
{
    
/**
     * {@inheritdoc}
     *
     * @link http://www.postgresql.org/docs/9.3/static/errcodes-appendix.html
     */
    
public function convertException($messageDriverException $exception)
    {
        switch (
$exception->getSQLState()) {
            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 
ExceptionForeignKeyConstraintViolationException($message$exception);
                }

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

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

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

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

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

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

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

            case 
'42P07':
                return new 
ExceptionTableExistsException($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 
ExceptionConnectionException($message$exception);
                }

                break;
        }

        return new 
ExceptionDriverException($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;

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

    
/**
     * {@inheritdoc}
     */
    
public function getDatabase(DoctrineDBALConnection $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(DoctrineDBALConnection $conn)
    {
        return new 
PostgreSqlSchemaManager($conn);
    }
}
Онлайн: 0
Реклама