Commit 1605e5c3 authored by Benjamin Eberlei's avatar Benjamin Eberlei

DDC-1202 fix identifier quoting on MSSQL Platform

parent 0985b38b
...@@ -22,7 +22,8 @@ namespace Doctrine\DBAL\Platforms; ...@@ -22,7 +22,8 @@ namespace Doctrine\DBAL\Platforms;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\Index, Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Index,
Doctrine\DBAL\Schema\Table;
/** /**
* The MsSqlPlatform provides the behavior, features and SQL dialect of the * The MsSqlPlatform provides the behavior, features and SQL dialect of the
...@@ -441,11 +442,11 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -441,11 +442,11 @@ class MsSqlPlatform extends AbstractPlatform
$pattern = "'%[^' + $char + ']%'"; $pattern = "'%[^' + $char + ']%'";
if ($pos == self::TRIM_LEADING) { if ($pos == self::TRIM_LEADING) {
return 'stuff(' . $str . ', 1, patindex(' . $pattern .', ' . $str . ') - 1, null)'; return 'stuff(' . $str . ', 1, patindex(' . $pattern . ', ' . $str . ') - 1, null)';
} else if ($pos == self::TRIM_TRAILING) { } else if ($pos == self::TRIM_TRAILING) {
return 'reverse(stuff(reverse(' . $str . '), 1, patindex(' . $pattern .', reverse(' . $str . ')) - 1, null))'; return 'reverse(stuff(reverse(' . $str . '), 1, patindex(' . $pattern . ', reverse(' . $str . ')) - 1, null))';
} else { } else {
return 'reverse(stuff(reverse(stuff(' . $str . ', 1, patindex(' . $pattern .', ' . $str . ') - 1, null)), 1, patindex(' . $pattern .', reverse(stuff(' . $str . ', 1, patindex(' . $pattern .', ' . $str . ') - 1, null))) - 1, null))'; return 'reverse(stuff(reverse(stuff(' . $str . ', 1, patindex(' . $pattern . ', ' . $str . ') - 1, null)), 1, patindex(' . $pattern . ', reverse(stuff(' . $str . ', 1, patindex(' . $pattern . ', ' . $str . ') - 1, null))) - 1, null))';
} }
} }
} }
...@@ -761,8 +762,7 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -761,8 +762,7 @@ class MsSqlPlatform extends AbstractPlatform
return $fromClause . ' WITH (tablockx)'; return $fromClause . ' WITH (tablockx)';
} else if ($lockMode == \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE) { } else if ($lockMode == \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE) {
return $fromClause . ' WITH (tablockx)'; return $fromClause . ' WITH (tablockx)';
} } else {
else {
return $fromClause; return $fromClause;
} }
} }
...@@ -779,4 +779,20 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -779,4 +779,20 @@ class MsSqlPlatform extends AbstractPlatform
{ {
return 'Doctrine\DBAL\Platforms\Keywords\MsSQLKeywords'; return 'Doctrine\DBAL\Platforms\Keywords\MsSQLKeywords';
} }
/**
* Quotes a string so that it can be safely used as a table or column name,
* even if it is a reserved word of the platform.
*
* NOTE: Just because you CAN use quoted identifiers doesn't mean
* you SHOULD use them. In general, they end up causing way more
* problems than they solve.
*
* @param string $str identifier name to be quoted
* @return string quoted identifier string
*/
public function quoteIdentifier($str)
{
return "[" . $str . "]";
}
} }
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