Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
c458fe72
Commit
c458fe72
authored
Sep 02, 2014
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix SQL Server default constraint name generation for quoted identifiers
parent
1a9408c5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
191 additions
and
5 deletions
+191
-5
SQLServerPlatform.php
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
+7
-2
AbstractSQLServerPlatformTestCase.php
...ests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php
+184
-3
No files found.
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
View file @
c458fe72
...
@@ -322,11 +322,13 @@ class SQLServerPlatform extends AbstractPlatform
...
@@ -322,11 +322,13 @@ class SQLServerPlatform extends AbstractPlatform
throw
new
\InvalidArgumentException
(
"Incomplete column definition. 'default' required."
);
throw
new
\InvalidArgumentException
(
"Incomplete column definition. 'default' required."
);
}
}
$columnName
=
new
Identifier
(
$column
[
'name'
]);
return
return
' CONSTRAINT '
.
' CONSTRAINT '
.
$this
->
generateDefaultConstraintName
(
$table
,
$column
[
'name'
])
.
$this
->
generateDefaultConstraintName
(
$table
,
$column
[
'name'
])
.
$this
->
getDefaultValueDeclarationSQL
(
$column
)
.
$this
->
getDefaultValueDeclarationSQL
(
$column
)
.
' FOR '
.
$column
[
'name'
]
;
' FOR '
.
$column
Name
->
getQuotedName
(
$this
)
;
}
}
/**
/**
...
@@ -1519,6 +1521,9 @@ class SQLServerPlatform extends AbstractPlatform
...
@@ -1519,6 +1521,9 @@ class SQLServerPlatform extends AbstractPlatform
*/
*/
private
function
generateIdentifierName
(
$identifier
)
private
function
generateIdentifierName
(
$identifier
)
{
{
return
strtoupper
(
dechex
(
crc32
(
$identifier
)));
// Always generate name for unquoted identifiers to ensure consistency.
$identifier
=
new
Identifier
(
$identifier
);
return
strtoupper
(
dechex
(
crc32
(
$identifier
->
getName
())));
}
}
}
}
tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php
View file @
c458fe72
...
@@ -920,4 +920,185 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
...
@@ -920,4 +920,185 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
"EXEC sp_RENAME N'[schema].[table].[foo]', N'[bar]', N'INDEX'"
,
"EXEC sp_RENAME N'[schema].[table].[foo]', N'[bar]', N'INDEX'"
,
);
);
}
}
/**
* @dataProvider getGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL
* @group DBAL-830
*/
public
function
testGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL
(
$table
,
$column
,
$expectedSql
)
{
$this
->
assertSame
(
$expectedSql
,
$this
->
_platform
->
getDefaultConstraintDeclarationSQL
(
$table
,
$column
));
}
public
function
getGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL
()
{
return
array
(
// Unquoted identifiers non-reserved keywords.
array
(
'mytable'
,
array
(
'name'
=>
'mycolumn'
,
'default'
=>
'foo'
),
" CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR mycolumn"
),
// Quoted identifiers non-reserved keywords.
array
(
'`mytable`'
,
array
(
'name'
=>
'`mycolumn`'
,
'default'
=>
'foo'
),
" CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR [mycolumn]"
),
// Unquoted identifiers reserved keywords.
array
(
'table'
,
array
(
'name'
=>
'select'
,
'default'
=>
'foo'
),
" CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]"
),
// Quoted identifiers reserved keywords.
array
(
'`table`'
,
array
(
'name'
=>
'`select`'
,
'default'
=>
'foo'
),
" CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]"
),
);
}
/**
* @dataProvider getGeneratesIdentifierNamesInCreateTableSQL
* @group DBAL-830
*/
public
function
testGeneratesIdentifierNamesInCreateTableSQL
(
$table
,
$expectedSql
)
{
$this
->
assertSame
(
$expectedSql
,
$this
->
_platform
->
getCreateTableSQL
(
$table
));
}
public
function
getGeneratesIdentifierNamesInCreateTableSQL
()
{
return
array
(
// Unquoted identifiers non-reserved keywords.
array
(
new
Table
(
'mytable'
,
array
(
new
Column
(
'mycolumn'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'foo'
)))),
array
(
'CREATE TABLE mytable (mycolumn NVARCHAR(255) NOT NULL)'
,
"ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR mycolumn"
)
),
// Quoted identifiers reserved keywords.
array
(
new
Table
(
'`mytable`'
,
array
(
new
Column
(
'`mycolumn`'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'foo'
)))),
array
(
'CREATE TABLE [mytable] ([mycolumn] NVARCHAR(255) NOT NULL)'
,
"ALTER TABLE [mytable] ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR [mycolumn]"
)
),
// Unquoted identifiers reserved keywords.
array
(
new
Table
(
'table'
,
array
(
new
Column
(
'select'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'foo'
)))),
array
(
'CREATE TABLE [table] ([select] NVARCHAR(255) NOT NULL)'
,
"ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]"
)
),
// Quoted identifiers reserved keywords.
array
(
new
Table
(
'`table`'
,
array
(
new
Column
(
'`select`'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'foo'
)))),
array
(
'CREATE TABLE [table] ([select] NVARCHAR(255) NOT NULL)'
,
"ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]"
)
),
);
}
/**
* @dataProvider getGeneratesIdentifierNamesInAlterTableSQL
* @group DBAL-830
*/
public
function
testGeneratesIdentifierNamesInAlterTableSQL
(
$tableDiff
,
$expectedSql
)
{
$this
->
assertSame
(
$expectedSql
,
$this
->
_platform
->
getAlterTableSQL
(
$tableDiff
));
}
public
function
getGeneratesIdentifierNamesInAlterTableSQL
()
{
return
array
(
// Unquoted identifiers non-reserved keywords.
array
(
new
TableDiff
(
'mytable'
,
array
(
new
Column
(
'addcolumn'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'foo'
))),
array
(
'mycolumn'
=>
new
ColumnDiff
(
'mycolumn'
,
new
Column
(
'mycolumn'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'bar'
)),
array
(
'default'
),
new
Column
(
'mycolumn'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'foo'
))
)
),
array
(
new
Column
(
'removecolumn'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'foo'
)))
),
array
(
'ALTER TABLE mytable ADD addcolumn NVARCHAR(255) NOT NULL'
,
"ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_4AD86123 DEFAULT 'foo' FOR addcolumn"
,
'ALTER TABLE mytable DROP COLUMN removecolumn'
,
'ALTER TABLE mytable DROP CONSTRAINT DF_6B2BD609_9BADD926'
,
'ALTER TABLE mytable ALTER COLUMN mycolumn NVARCHAR(255) NOT NULL'
,
"ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'bar' FOR mycolumn"
)
),
// Quoted identifiers non-reserved keywords.
array
(
new
TableDiff
(
'`mytable`'
,
array
(
new
Column
(
'`addcolumn`'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'foo'
))),
array
(
'mycolumn'
=>
new
ColumnDiff
(
'`mycolumn`'
,
new
Column
(
'`mycolumn`'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'bar'
)),
array
(
'default'
),
new
Column
(
'`mycolumn`'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'foo'
))
)
),
array
(
new
Column
(
'`removecolumn`'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'foo'
)))
),
array
(
'ALTER TABLE [mytable] ADD [addcolumn] NVARCHAR(255) NOT NULL'
,
"ALTER TABLE [mytable] ADD CONSTRAINT DF_6B2BD609_4AD86123 DEFAULT 'foo' FOR [addcolumn]"
,
'ALTER TABLE [mytable] DROP COLUMN [removecolumn]'
,
'ALTER TABLE [mytable] DROP CONSTRAINT DF_6B2BD609_9BADD926'
,
'ALTER TABLE [mytable] ALTER COLUMN [mycolumn] NVARCHAR(255) NOT NULL'
,
"ALTER TABLE [mytable] ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'bar' FOR [mycolumn]"
)
),
// Unquoted identifiers reserved keywords.
array
(
new
TableDiff
(
'table'
,
array
(
new
Column
(
'add'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'foo'
))),
array
(
'select'
=>
new
ColumnDiff
(
'select'
,
new
Column
(
'select'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'bar'
)),
array
(
'default'
),
new
Column
(
'select'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'foo'
))
)
),
array
(
new
Column
(
'drop'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'foo'
)))
),
array
(
'ALTER TABLE [table] ADD [add] NVARCHAR(255) NOT NULL'
,
"ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_FD1A73E7 DEFAULT 'foo' FOR [add]"
,
'ALTER TABLE [table] DROP COLUMN [drop]'
,
'ALTER TABLE [table] DROP CONSTRAINT DF_F6298F46_4BF2EAC0'
,
'ALTER TABLE [table] ALTER COLUMN [select] NVARCHAR(255) NOT NULL'
,
"ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'bar' FOR [select]"
)
),
// Quoted identifiers reserved keywords.
array
(
new
TableDiff
(
'`table`'
,
array
(
new
Column
(
'`add`'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'foo'
))),
array
(
'select'
=>
new
ColumnDiff
(
'`select`'
,
new
Column
(
'`select`'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'bar'
)),
array
(
'default'
),
new
Column
(
'`select`'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'foo'
))
)
),
array
(
new
Column
(
'`drop`'
,
Type
::
getType
(
'string'
),
array
(
'default'
=>
'foo'
)))
),
array
(
'ALTER TABLE [table] ADD [add] NVARCHAR(255) NOT NULL'
,
"ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_FD1A73E7 DEFAULT 'foo' FOR [add]"
,
'ALTER TABLE [table] DROP COLUMN [drop]'
,
'ALTER TABLE [table] DROP CONSTRAINT DF_F6298F46_4BF2EAC0'
,
'ALTER TABLE [table] ALTER COLUMN [select] NVARCHAR(255) NOT NULL'
,
"ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'bar' FOR [select]"
)
),
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment