SQLServer2008Platform.php 2.74 KB
Newer Older
1 2 3 4 5
<?php

namespace Doctrine\DBAL\Platforms;

/**
6
 * Platform to ensure compatibility of Doctrine with Microsoft SQL Server 2008 version.
7 8 9 10 11 12
 *
 * Differences to SQL Server 2005 and before are that a new DATETIME2 type was
 * introduced that has a higher precision.
 */
class SQLServer2008Platform extends SQLServer2005Platform
{
13 14 15 16 17 18 19 20 21 22
    /**
     * {@inheritDoc}
     */
    public function getListTablesSQL()
    {
        // "sysdiagrams" table must be ignored as it's internal SQL Server table for Database Diagrams
        // Category 2 must be ignored as it is "MS SQL Server 'pseudo-system' object[s]" for replication
        return "SELECT name, SCHEMA_NAME (uid) AS schema_name FROM sysobjects WHERE type = 'U' AND name != 'sysdiagrams' AND category != 2 ORDER BY name";
    }

23
    /**
24
     * {@inheritDoc}
25 26 27 28 29 30 31 32 33
     */
    public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
    {
        // 3 - microseconds precision length
        // http://msdn.microsoft.com/en-us/library/ms187819.aspx
        return 'DATETIME2(6)';
    }

    /**
34
     * {@inheritDoc}
35 36 37 38 39 40 41
     */
    public function getDateTypeDeclarationSQL(array $fieldDeclaration)
    {
        return 'DATE';
    }

    /**
42
     * {@inheritDoc}
43 44 45 46 47
     */
    public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
    {
        return 'TIME(0)';
    }
Steve Müller's avatar
Steve Müller committed
48

49 50 51 52 53 54 55
    /**
     * {@inheritDoc}
     */
    public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration)
    {
        return 'DATETIMEOFFSET(6)';
    }
56

57
    /**
58
     * {@inheritDoc}
59 60 61 62 63
     */
    public function getDateTimeFormatString()
    {
        return 'Y-m-d H:i:s.u';
    }
64

65
    /**
66
     * {@inheritDoc}
67 68 69 70 71 72
     */
    public function getDateTimeTzFormatString()
    {
        return 'Y-m-d H:i:s.u P';
    }

73
    /**
74 75
     * {@inheritDoc}
     */
76 77 78 79 80 81
    public function getDateFormatString()
    {
        return 'Y-m-d';
    }

    /**
82 83
     * {@inheritDoc}
     */
84 85 86 87
    public function getTimeFormatString()
    {
        return 'H:i:s';
    }
88 89

    /**
90 91
     * {@inheritDoc}
     *
92 93 94 95 96
     * Adding Datetime2 Type
     */
    protected function initializeDoctrineTypeMappings()
    {
        parent::initializeDoctrineTypeMappings();
97 98 99
        $this->doctrineTypeMapping['datetime2']      = 'datetime';
        $this->doctrineTypeMapping['date']           = 'date';
        $this->doctrineTypeMapping['time']           = 'time';
100
        $this->doctrineTypeMapping['datetimeoffset'] = 'datetimetz';
101
    }
102 103 104 105 106 107 108 109

    /**
     * {@inheritdoc}
     *
     * Returns Microsoft SQL Server 2008 specific keywords class
     */
    protected function getReservedKeywordsClass()
    {
110
        return Keywords\SQLServer2008Keywords::class;
111
    }
112

113
    protected function getLikeWildcardCharacters() : string
114
    {
115
        return parent::getLikeWildcardCharacters() . '[]^';
116
    }
117
}