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
888968bb
Commit
888968bb
authored
May 05, 2012
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DBAL-255] Fix dropping columns with default contraints in SQLSrv
parent
c5e7533e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
2 deletions
+57
-2
SQLServerSchemaManager.php
lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php
+31
-0
doctrine-common
lib/vendor/doctrine-common
+1
-1
SQLServerSchemaManagerTest.php
...sts/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php
+25
-1
No files found.
lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php
View file @
888968bb
...
...
@@ -213,4 +213,35 @@ class SQLServerSchemaManager extends AbstractSchemaManager
return
$this
->
_getPortableTableIndexesList
(
$tableIndexes
,
$table
);
}
/**
* @override
*/
public
function
alterTable
(
TableDiff
$tableDiff
)
{
if
(
count
(
$tableDiff
->
removedColumns
)
>
0
)
{
foreach
(
$tableDiff
->
removedColumns
as
$col
){
$columnConstraintSql
=
$this
->
getColumnConstraintSQL
(
$tableDiff
->
name
,
$col
->
getName
());
foreach
(
$this
->
_conn
->
fetchAll
(
$columnConstraintSql
)
as
$constraint
)
{
$this
->
_conn
->
exec
(
"ALTER TABLE
$tableDiff->name
DROP CONSTRAINT "
.
$constraint
[
'Name'
]);
}
}
}
return
parent
::
alterTable
(
$tableDiff
);
}
/**
* This function retrieves the constraints for a given column.
*/
private
function
getColumnConstraintSQL
(
$table
,
$column
)
{
return
"SELECT SysObjects.[Name]
FROM SysObjects INNER JOIN (SELECT [Name],[ID] FROM SysObjects WHERE XType = 'U') AS Tab
ON Tab.[ID] = Sysobjects.[Parent_Obj]
INNER JOIN sys.default_constraints DefCons ON DefCons.[object_id] = Sysobjects.[ID]
INNER JOIN SysColumns Col ON Col.[ColID] = DefCons.[parent_column_id] AND Col.[ID] = Tab.[ID]
WHERE Col.[Name] = "
.
$this
->
_conn
->
quote
(
$column
)
.
" AND Tab.[Name] = "
.
$this
->
_conn
->
quote
(
$table
)
.
"
ORDER BY Col.[Name]"
;
}
}
doctrine-common
@
17e77400
Subproject commit 1
4eb4d62b6e0a87cd99200078c38644bbd216e42
Subproject commit 1
7e774007b98beb2e253e645260e0f9c32f4c936
tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php
View file @
888968bb
...
...
@@ -2,7 +2,11 @@
namespace
Doctrine\Tests\DBAL\Functional\Schema
;
use
Doctrine\DBAL\Schema
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\Schema\ColumnDiff
;
use
Doctrine\DBAL\Schema\Column
;
use
Doctrine\DBAL\Types\Type
;
class
SQLServerSchemaManagerTest
extends
SchemaManagerFunctionalTestCase
{
...
...
@@ -10,4 +14,24 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
return
"mssql"
;
}
/**
* @group DBAL-255
*/
public
function
testDropColumnConstraints
()
{
$table
=
new
Table
(
'sqlsrv_drop_column'
);
$table
->
addColumn
(
'id'
,
'integer'
);
$table
->
addColumn
(
'todrop'
,
'decimal'
,
array
(
'default'
=>
10.2
));
$this
->
_sm
->
createTable
(
$table
);
$diff
=
new
TableDiff
(
'sqlsrv_drop_column'
,
array
(),
array
(),
array
(
new
Column
(
'todrop'
,
Type
::
getType
(
'decimal'
))
));
$this
->
_sm
->
alterTable
(
$diff
);
$columns
=
$this
->
_sm
->
listTableColumns
(
'sqlsrv_drop_column'
);
$this
->
assertEquals
(
1
,
count
(
$columns
));
}
}
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