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
03be671e
Commit
03be671e
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
0e6bb9b0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
2 deletions
+64
-2
SQLServerSchemaManager.php
lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php
+38
-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 @
03be671e
...
@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Schema;
...
@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Schema;
use
Doctrine\DBAL\Events
;
use
Doctrine\DBAL\Events
;
use
Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs
;
use
Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs
;
use
Doctrine\DBAL\Driver\SQLSrv\SQLSrvException
;
/**
/**
* SQL Server Schema Manager
* SQL Server Schema Manager
...
@@ -218,8 +219,45 @@ class SQLServerSchemaManager extends AbstractSchemaManager
...
@@ -218,8 +219,45 @@ class SQLServerSchemaManager extends AbstractSchemaManager
}
else
{
}
else
{
throw
$e
;
throw
$e
;
}
}
}
catch
(
SQLSrvException
$e
)
{
if
(
strpos
(
$e
->
getMessage
(),
'SQLSTATE [01000, 15472]'
)
===
0
)
{
return
array
();
}
else
{
throw
$e
;
}
}
}
return
$this
->
_getPortableTableIndexesList
(
$tableIndexes
,
$table
);
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
@
1c9d2ab3
Subproject commit 1
7e774007b98beb2e253e645260e0f9c32f4c936
Subproject commit 1
c9d2ab329746637d1c6c058523ec1ee769da31c
tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php
View file @
03be671e
...
@@ -2,7 +2,11 @@
...
@@ -2,7 +2,11 @@
namespace
Doctrine\Tests\DBAL\Functional\Schema
;
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
class
SQLServerSchemaManagerTest
extends
SchemaManagerFunctionalTestCase
{
{
...
@@ -10,4 +14,24 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
...
@@ -10,4 +14,24 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
{
return
"mssql"
;
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