FirebirdPlatform.php 3.36 KB
Newer Older
1 2
<?php

3
namespace Doctrine\DBAL\Platforms;
4

5
class FirebirdPlatform extends AbstractPlatform
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
{
    /**
     * Constructor.
     */
    public function __construct()
    {
        parent::__construct();
    }
    
    /**
     * Adds an driver-specific LIMIT clause to the query
     *
     * @param string $query     query to modify
     * @param integer $limit    limit the number of rows
     * @param integer $offset   start reading from given offset
     * @return string modified  query
     * @override
     */
    public function writeLimitClause($query, $limit, $offset)
    {
        if ( ! $offset) {
            $offset = 0;
        }
        if ($limit > 0) {
            $query = preg_replace('/^([\s(])*SELECT(?!\s*FIRST\s*\d+)/i',
                "SELECT FIRST $limit SKIP $offset", $query);
        }
        return $query;
    }
    
    /**
     * return string for internal table used when calling only a function
     *
     * @return string for internal table used when calling only a function
     */
    public function getFunctionTableExpression()
    {
        return ' FROM RDB$DATABASE';
    }

    /**
     * build string to define escape pattern string
     *
     * @return string define escape pattern
     * @override
     */
    public function getPatternEscapeStringExpression()
    {
        return " ESCAPE '". $this->_properties['escape_pattern'] ."'";
    }

    /**
     * Obtain DBMS specific SQL code portion needed to set the CHARACTER SET
     * of a field declaration to be used in statements like CREATE TABLE.
     *
     * @param string $charset   name of the charset
     * @return string  DBMS specific SQL code portion needed to set the CHARACTER SET
     *                 of a field declaration.
     */
    public function getCharsetFieldDeclaration($charset)
    {
        return 'CHARACTER SET ' . $charset;
    }

    /**
     * Obtain DBMS specific SQL code portion needed to set the COLLATION
     * of a field declaration to be used in statements like CREATE TABLE.
     *
     * @param string $collation   name of the collation
     * @return string  DBMS specific SQL code portion needed to set the COLLATION
     *                 of a field declaration.
     */
    public function getCollationFieldDeclaration($collation)
    {
        return 'COLLATE ' . $collation;
    }
82

romanb's avatar
romanb committed
83 84 85 86
    public function getSequenceNextValSql($sequenceName)
    {
        return 'SELECT GEN_ID(' . $this->quoteIdentifier($sequenceName) . ', 1) FROM RDB$DATABASE';
    }
87

romanb's avatar
romanb committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
    protected function _getTransactionIsolationLevelSql($level)
    {
        switch ($level) {
            case Doctrine_DBAL_Connection::TRANSACTION_READ_UNCOMMITTED:
                return 'READ COMMITTED RECORD_VERSION';
            case Doctrine_DBAL_Connection::TRANSACTION_READ_COMMITTED:
                return 'READ COMMITTED NO RECORD_VERSION';
            case Doctrine_DBAL_Connection::TRANSACTION_REPEATABLE_READ:
                return 'SNAPSHOT';
            case Doctrine_DBAL_Connection::TRANSACTION_SERIALIZABLE:
                return 'SNAPSHOT TABLE STABILITY';
            default:
                return parent::_getTransactionIsolationLevelSql($level);
        }
    }
103

romanb's avatar
romanb committed
104 105 106 107
    public function getSetTransactionIsolationSql($level)
    {
        return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level);
    }
108 109 110 111 112

    public function getName()
    {
        return 'firebird';
    }
113
}