Commit 143c2510 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge pull request #272 from deeky666/refactor-mssql-keywords

Refactor SQL Server keyword dictionaries and MsSQL leftovers
parents f69a44e6 7c1893cf
......@@ -47,7 +47,7 @@ interfaces to use. It can be configured in one of three ways:
- ``pdo_oci``: An Oracle driver that uses the pdo\_oci PDO
extension.
**Note that this driver caused problems in our tests. Prefer the oci8 driver if possible.**
- ``pdo_sqlsrv``: An MSSQL driver that uses pdo\_sqlsrv PDO
- ``pdo_sqlsrv``: A Microsoft SQL Server driver that uses pdo\_sqlsrv PDO
- ``oci8``: An Oracle driver that uses the oci8 PHP extension.
- ``driverClass``: Specifies a custom driver implementation if no
......
......@@ -4,7 +4,7 @@ Portability
There are often cases when you need to write an application or library that is portable
across multiple different database vendors. The Doctrine ORM is one example of such
a library. It is an abstraction layer over all the currently supported vendors (MySQL, Oracle,
PostgreSQL, SQLite and MSSQL). If you want to use the DBAL to write a portable application
PostgreSQL, SQLite and Microsoft SQL Server). If you want to use the DBAL to write a portable application
or library you have to follow lots of rules to make all the different vendors work the
same.
......
......@@ -29,8 +29,9 @@ namespace Doctrine\DBAL\Platforms\Keywords;
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author David Coallier <davidc@php.net>
* @author Steve Müller <st.mueller@dzh-online.de>
* @deprecated Use SQLServerKeywords class instead.
*/
class MsSQLKeywords extends KeywordList
class MsSQLKeywords extends SQLServerKeywords
{
/**
* {@inheritdoc}
......@@ -39,212 +40,4 @@ class MsSQLKeywords extends KeywordList
{
return 'MsSQL';
}
/**
* {@inheritdoc}
*/
protected function getKeywords()
{
return array(
'ADD',
'CURRENT_TIMESTAMP',
'GROUP',
'OPENQUERY',
'SERIALIZABLE',
'ALL',
'CURRENT_USER',
'HAVING',
'OPENROWSET',
'SESSION_USER',
'ALTER',
'CURSOR',
'HOLDLOCK',
'OPTION',
'SET',
'AND',
'DATABASE',
'IDENTITY',
'OR',
'SETUSER',
'ANY',
'DBCC',
'IDENTITYCOL',
'ORDER',
'SHUTDOWN',
'AS',
'DEALLOCATE',
'IDENTITY_INSERT',
'OUTER',
'SOME',
'ASC',
'DECLARE',
'IF',
'OVER',
'STATISTICS',
'AUTHORIZATION',
'DEFAULT',
'IN',
'PERCENT',
'SUM',
'AVG',
'DELETE',
'INDEX',
'PERM',
'SYSTEM_USER',
'BACKUP',
'DENY',
'INNER',
'PERMANENT',
'TABLE',
'BEGIN',
'DESC',
'INSERT',
'PIPE',
'TAPE',
'BETWEEN',
'DISK',
'INTERSECT',
'PLAN',
'TEMP',
'BREAK',
'DISTINCT',
'INTO',
'PRECISION',
'TEMPORARY',
'BROWSE',
'DISTRIBUTED',
'IS',
'PREPARE',
'TEXTSIZE',
'BULK',
'DOUBLE',
'ISOLATION',
'PRIMARY',
'THEN',
'BY',
'DROP',
'JOIN',
'PRINT',
'TO',
'CASCADE',
'DUMMY',
'KEY',
'PRIVILEGES',
'TOP',
'CASE',
'DUMP',
'KILL',
'PROC',
'TRAN',
'CHECK',
'ELSE',
'LEFT',
'PROCEDURE',
'TRANSACTION',
'CHECKPOINT',
'END',
'LEVEL',
'PROCESSEXIT',
'TRIGGER',
'CLOSE',
'ERRLVL',
'LIKE',
'PUBLIC',
'TRUNCATE',
'CLUSTERED',
'ERROREXIT',
'LINENO',
'RAISERROR',
'TSEQUAL',
'COALESCE',
'ESCAPE',
'LOAD',
'READ',
'UNCOMMITTED',
'COLUMN',
'EXCEPT',
'MAX',
'READTEXT',
'UNION',
'COMMIT',
'EXEC',
'MIN',
'RECONFIGURE',
'UNIQUE',
'COMMITTED',
'EXECUTE',
'MIRROREXIT',
'REFERENCES',
'UPDATE',
'COMPUTE',
'EXISTS',
'NATIONAL',
'REPEATABLE',
'UPDATETEXT',
'CONFIRM',
'EXIT',
'NOCHECK',
'REPLICATION',
'USE',
'CONSTRAINT',
'FETCH',
'NONCLUSTERED',
'RESTORE',
'USER',
'CONTAINS',
'FILE',
'NOT',
'RESTRICT',
'VALUES',
'CONTAINSTABLE',
'FILLFACTOR',
'NULL',
'RETURN',
'VARYING',
'CONTINUE',
'FLOPPY',
'NULLIF',
'REVOKE',
'VIEW',
'CONTROLROW',
'FOR',
'OF',
'RIGHT',
'WAITFOR',
'CONVERT',
'FOREIGN',
'OFF',
'ROLLBACK',
'WHEN',
'COUNT',
'FREETEXT',
'OFFSETS',
'ROWCOUNT',
'WHERE',
'CREATE',
'FREETEXTTABLE',
'ON',
'ROWGUIDCOL',
'WHILE',
'CROSS',
'FROM',
'ONCE',
'RULE',
'WITH',
'CURRENT',
'FULL',
'ONLY',
'SAVE',
'WORK',
'CURRENT_DATE',
'GOTO',
'OPEN',
'SCHEMA',
'WRITETEXT',
'CURRENT_TIME',
'GRANT',
'OPENDATASOURCE',
'SELECT'
);
}
}
<?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\Platforms\Keywords;
/**
* Microsoft SQL Server 2005 reserved keyword dictionary.
*
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @link www.doctrine-project.com
* @since 2.3
* @author Steve Müller <st.mueller@dzh-online.de>
*/
class SQLServer2005Keywords extends SQLServerKeywords
{
/**
* {@inheritdoc}
*/
public function getName()
{
return 'SQLServer2005';
}
/**
* {@inheritdoc}
*
* @link http://msdn.microsoft.com/en-US/library/ms189822%28v=sql.90%29.aspx
*/
protected function getKeywords()
{
return array_merge(array_diff(parent::getKeywords(), array('DUMMY')), array(
'EXTERNAL',
'PIVOT',
'REVERT',
'SECURITYAUDIT',
'TABLESAMPLE',
'UNPIVOT'
));
}
}
<?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\Platforms\Keywords;
/**
* Microsoft SQL Server 2008 reserved keyword dictionary.
*
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @link www.doctrine-project.com
* @since 2.3
* @author Steve Müller <st.mueller@dzh-online.de>
*/
class SQLServer2008Keywords extends SQLServer2005Keywords
{
/**
* {@inheritdoc}
*/
public function getName()
{
return 'SQLServer2008';
}
/**
* {@inheritdoc}
*
* @link http://msdn.microsoft.com/en-us/library/ms189822%28v=sql.100%29.aspx
*/
protected function getKeywords()
{
return array_merge(parent::getKeywords(), array(
'MERGE'
));
}
}
......@@ -20,14 +20,14 @@
namespace Doctrine\DBAL\Platforms\Keywords;
/**
* SQL Server 2012 reserved keywords list.
* Microsoft SQL Server 2012 reserved keyword dictionary.
*
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @link www.doctrine-project.com
* @since 2.3
* @author Steve Müller <st.mueller@dzh-online.de>
*/
class SQLServer2012Keywords extends MsSQLKeywords
class SQLServer2012Keywords extends SQLServer2008Keywords
{
/**
* {@inheritdoc}
......@@ -39,6 +39,8 @@ class SQLServer2012Keywords extends MsSQLKeywords
/**
* {@inheritdoc}
*
* @link http://msdn.microsoft.com/en-us/library/ms189822.aspx
*/
protected function getKeywords()
{
......@@ -47,8 +49,7 @@ class SQLServer2012Keywords extends MsSQLKeywords
'SEMANTICSIMILARITYDETAILSTABLE',
'SEMANTICSIMILARITYTABLE',
'TRY_CONVERT',
'WITHIN',
'SEQUENCE'
'WITHIN GROUP'
));
}
}
<?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\Platforms\Keywords;
/**
* Microsoft SQL Server 2000 reserved keyword dictionary.
*
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @link www.doctrine-project.com
* @since 2.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author David Coallier <davidc@php.net>
* @author Steve Müller <st.mueller@dzh-online.de>
*/
class SQLServerKeywords extends KeywordList
{
/**
* {@inheritdoc}
*/
public function getName()
{
return 'SQLServer';
}
/**
* {@inheritdoc}
*
* @link http://msdn.microsoft.com/en-us/library/aa238507%28v=sql.80%29.aspx
*/
protected function getKeywords()
{
return array(
'ADD',
'ALL',
'ALTER',
'AND',
'ANY',
'AS',
'ASC',
'AUTHORIZATION',
'BACKUP',
'BEGIN',
'BETWEEN',
'BREAK',
'BROWSE',
'BULK',
'BY',
'CASCADE',
'CASE',
'CHECK',
'CHECKPOINT',
'CLOSE',
'CLUSTERED',
'COALESCE',
'COLLATE',
'COLUMN',
'COMMIT',
'COMPUTE',
'CONSTRAINT',
'CONTAINS',
'CONTAINSTABLE',
'CONTINUE',
'CONVERT',
'CREATE',
'CROSS',
'CURRENT',
'CURRENT_DATE',
'CURRENT_TIME',
'CURRENT_TIMESTAMP',
'CURRENT_USER',
'CURSOR',
'DATABASE',
'DBCC',
'DEALLOCATE',
'DECLARE',
'DEFAULT',
'DELETE',
'DENY',
'DESC',
'DISK',
'DISTINCT',
'DISTRIBUTED',
'DOUBLE',
'DROP',
'DUMP',
'ELSE',
'END',
'ERRLVL',
'ESCAPE',
'EXCEPT',
'EXEC',
'EXECUTE',
'EXISTS',
'EXIT',
'EXTERNAL',
'FETCH',
'FILE',
'FILLFACTOR',
'FOR',
'FOREIGN',
'FREETEXT',
'FREETEXTTABLE',
'FROM',
'FULL',
'FUNCTION',
'GOTO',
'GRANT',
'GROUP',
'HAVING',
'HOLDLOCK',
'IDENTITY',
'IDENTITY_INSERT',
'IDENTITYCOL',
'IF',
'IN',
'INDEX',
'INNER',
'INSERT',
'INTERSECT',
'INTO',
'IS',
'JOIN',
'KEY',
'KILL',
'LEFT',
'LIKE',
'LINENO',
'LOAD',
'NATIONAL',
'NOCHECK ',
'NONCLUSTERED',
'NOT',
'NULL',
'NULLIF',
'OF',
'OFF',
'OFFSETS',
'ON',
'OPEN',
'OPENDATASOURCE',
'OPENQUERY',
'OPENROWSET',
'OPENXML',
'OPTION',
'OR',
'ORDER',
'OUTER',
'OVER',
'PERCENT',
'PIVOT',
'PLAN',
'PRECISION',
'PRIMARY',
'PRINT',
'PROC',
'PROCEDURE',
'PUBLIC',
'RAISERROR',
'READ',
'READTEXT',
'RECONFIGURE',
'REFERENCES',
'REPLICATION',
'RESTORE',
'RESTRICT',
'RETURN',
'REVERT',
'REVOKE',
'RIGHT',
'ROLLBACK',
'ROWCOUNT',
'ROWGUIDCOL',
'RULE',
'SAVE',
'SCHEMA',
'SECURITYAUDIT',
'SELECT',
'SESSION_USER',
'SET',
'SETUSER',
'SHUTDOWN',
'SOME',
'STATISTICS',
'SYSTEM_USER',
'TABLE',
'TABLESAMPLE',
'TEXTSIZE',
'THEN',
'TO',
'TOP',
'TRAN',
'TRANSACTION',
'TRIGGER',
'TRUNCATE',
'TSEQUAL',
'UNION',
'UNIQUE',
'UNPIVOT',
'UPDATE',
'UPDATETEXT',
'USE',
'USER',
'VALUES',
'VARYING',
'VIEW',
'WAITFOR',
'WHEN',
'WHERE',
'WHILE',
'WITH',
'WRITETEXT'
);
}
}
......@@ -20,7 +20,7 @@
namespace Doctrine\DBAL\Platforms;
/**
* Platform to ensure compatibility of Doctrine with SQLServer2005 version and
* Platform to ensure compatibility of Doctrine with Microsoft SQL Server 2005 version and
* higher.
*
* Differences to SQL Server 2008 are:
......@@ -50,5 +50,15 @@ class SQLServer2005Platform extends SQLServerPlatform
{
return 'VARCHAR(MAX)';
}
/**
* {@inheritdoc}
*
* Returns Microsoft SQL Server 2005 specific keywords class
*/
protected function getReservedKeywordsClass()
{
return 'Doctrine\DBAL\Platforms\Keywords\SQLServer2005Keywords';
}
}
......@@ -20,7 +20,7 @@
namespace Doctrine\DBAL\Platforms;
/**
* Platform to ensure compatibility of Doctrine with SQLServer2008 version.
* Platform to ensure compatibility of Doctrine with Microsoft SQL Server 2008 version.
*
* Differences to SQL Server 2005 and before are that a new DATETIME2 type was
* introduced that has a higher precision.
......@@ -97,4 +97,14 @@ class SQLServer2008Platform extends SQLServer2005Platform
$this->doctrineTypeMapping['date'] = 'date';
$this->doctrineTypeMapping['time'] = 'time';
}
/**
* {@inheritdoc}
*
* Returns Microsoft SQL Server 2008 specific keywords class
*/
protected function getReservedKeywordsClass()
{
return 'Doctrine\DBAL\Platforms\Keywords\SQLServer2008Keywords';
}
}
......@@ -22,7 +22,7 @@ namespace Doctrine\DBAL\Platforms;
use Doctrine\DBAL\Schema\Sequence;
/**
* Platform to ensure compatibility of Doctrine with SQLServer2012 version.
* Platform to ensure compatibility of Doctrine with Microsoft SQL Server 2012 version.
*
* Differences to SQL Server 2008 and before are that sequences are introduced.
*
......@@ -88,6 +88,8 @@ class SQLServer2012Platform extends SQLServer2008Platform
/**
* {@inheritdoc}
*
* Returns Microsoft SQL Server 2012 specific keywords class
*/
protected function getReservedKeywordsClass()
{
......
......@@ -82,8 +82,8 @@ class SQLServerPlatform extends AbstractPlatform
/**
* {@inheritDoc}
*
* MsSql prefers "autoincrement" identity columns since sequences can only
* be emulated with a table.
* Microsoft SQL Server prefers "autoincrement" identity columns
* since sequences can only be emulated with a table.
*/
public function prefersIdentityColumns()
{
......@@ -93,7 +93,7 @@ class SQLServerPlatform extends AbstractPlatform
/**
* {@inheritDoc}
*
* MsSql supports this through AUTO_INCREMENT columns.
* Microsoft SQL Server supports this through AUTO_INCREMENT columns.
*/
public function supportsIdentityColumns()
{
......@@ -921,7 +921,7 @@ class SQLServerPlatform extends AbstractPlatform
*/
protected function getReservedKeywordsClass()
{
return 'Doctrine\DBAL\Platforms\Keywords\MsSQLKeywords';
return 'Doctrine\DBAL\Platforms\Keywords\SQLServerKeywords';
}
/**
......
......@@ -31,7 +31,10 @@ class ReservedWordsCommand extends Command
{
private $keywordListClasses = array(
'mysql' => 'Doctrine\DBAL\Platforms\Keywords\MySQLKeywords',
'mssql' => 'Doctrine\DBAL\Platforms\Keywords\MsSQLKeywords',
'sqlserver' => 'Doctrine\DBAL\Platforms\Keywords\SQLServerKeywords',
'sqlserver2005' => 'Doctrine\DBAL\Platforms\Keywords\SQLServer2005Keywords',
'sqlserver2008' => 'Doctrine\DBAL\Platforms\Keywords\SQLServer2008Keywords',
'sqlserver2012' => 'Doctrine\DBAL\Platforms\Keywords\SQLServer2012Keywords',
'sqlite' => 'Doctrine\DBAL\Platforms\Keywords\SQLiteKeywords',
'pgsql' => 'Doctrine\DBAL\Platforms\Keywords\PostgreSQLKeywords',
'oracle' => 'Doctrine\DBAL\Platforms\Keywords\OracleKeywords',
......@@ -66,7 +69,7 @@ class ReservedWordsCommand extends Command
Checks if the current database contains tables and columns
with names that are identifiers in this dialect or in other SQL dialects.
By default SQLite, MySQL, PostgreSQL, MsSQL and Oracle
By default SQLite, MySQL, PostgreSQL, Microsoft SQL Server and Oracle
keywords are checked:
<info>%command.full_name%</info>
......@@ -82,7 +85,10 @@ The following keyword lists are currently shipped with Doctrine:
* pgsql
* sqlite
* oracle
* mssql
* sqlserver
* sqlserver2005
* sqlserver2008
* sqlserver2012
* db2 (Not checked by default)
EOT
);
......@@ -98,7 +104,16 @@ EOT
$keywordLists = (array)$input->getOption('list');
if ( ! $keywordLists) {
$keywordLists = array('mysql', 'pgsql', 'sqlite', 'oracle', 'mssql');
$keywordLists = array(
'mysql',
'pgsql',
'sqlite',
'oracle',
'sqlserver',
'sqlserver2005',
'sqlserver2008',
'sqlserver2012'
);
}
$keywords = array();
......
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