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
a1b18d86
Commit
a1b18d86
authored
Dec 09, 2011
by
jsor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add alter table events to missing platforms
parent
6abba72f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
213 additions
and
7 deletions
+213
-7
DB2Platform.php
lib/Doctrine/DBAL/Platforms/DB2Platform.php
+51
-1
MsSqlPlatform.php
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
+52
-2
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+53
-2
OraclePlatform.php
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
+52
-2
SqlitePlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
+5
-0
No files found.
lib/Doctrine/DBAL/Platforms/DB2Platform.php
View file @
a1b18d86
...
...
@@ -22,6 +22,11 @@ namespace Doctrine\DBAL\Platforms;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Schema\Index
;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\Events
;
use
Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs
;
use
Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs
;
use
Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs
;
use
Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs
;
class
DB2Platform
extends
AbstractPlatform
{
...
...
@@ -373,17 +378,51 @@ class DB2Platform extends AbstractPlatform
public
function
getAlterTableSQL
(
TableDiff
$diff
)
{
$sql
=
array
();
$columnSql
=
array
();
$queryParts
=
array
();
foreach
(
$diff
->
addedColumns
AS
$fieldName
=>
$column
)
{
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
onSchemaAlterTableAddColumn
))
{
$eventArgs
=
new
SchemaAlterTableAddColumnEventArgs
(
$column
,
$diff
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
onSchemaAlterTableAddColumn
,
$eventArgs
);
$columnSql
=
array_merge
(
$columnSql
,
$eventArgs
->
getSql
());
if
(
$eventArgs
->
isDefaultPrevented
())
{
continue
;
}
}
$queryParts
[]
=
'ADD COLUMN '
.
$this
->
getColumnDeclarationSQL
(
$column
->
getQuotedName
(
$this
),
$column
->
toArray
());
}
foreach
(
$diff
->
removedColumns
AS
$column
)
{
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
onSchemaAlterTableRemoveColumn
))
{
$eventArgs
=
new
SchemaAlterTableRemoveColumnEventArgs
(
$column
,
$diff
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
onSchemaAlterTableRemoveColumn
,
$eventArgs
);
$columnSql
=
array_merge
(
$columnSql
,
$eventArgs
->
getSql
());
if
(
$eventArgs
->
isDefaultPrevented
())
{
continue
;
}
}
$queryParts
[]
=
'DROP COLUMN '
.
$column
->
getQuotedName
(
$this
);
}
foreach
(
$diff
->
changedColumns
AS
$columnDiff
)
{
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
onSchemaAlterTableChangeColumn
))
{
$eventArgs
=
new
SchemaAlterTableChangeColumnEventArgs
(
$columnDiff
,
$diff
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
onSchemaAlterTableChangeColumn
,
$eventArgs
);
$columnSql
=
array_merge
(
$columnSql
,
$eventArgs
->
getSql
());
if
(
$eventArgs
->
isDefaultPrevented
())
{
continue
;
}
}
/* @var $columnDiff Doctrine\DBAL\Schema\ColumnDiff */
$column
=
$columnDiff
->
column
;
$queryParts
[]
=
'ALTER '
.
(
$columnDiff
->
oldColumnName
)
.
' '
...
...
@@ -391,6 +430,17 @@ class DB2Platform extends AbstractPlatform
}
foreach
(
$diff
->
renamedColumns
AS
$oldColumnName
=>
$column
)
{
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
onSchemaAlterTableRenameColumn
))
{
$eventArgs
=
new
SchemaAlterTableRenameColumnEventArgs
(
$oldColumnName
,
$column
,
$diff
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
onSchemaAlterTableRenameColumn
,
$eventArgs
);
$columnSql
=
array_merge
(
$columnSql
,
$eventArgs
->
getSql
());
if
(
$eventArgs
->
isDefaultPrevented
())
{
continue
;
}
}
$queryParts
[]
=
'RENAME '
.
$oldColumnName
.
' TO '
.
$column
->
getQuotedName
(
$this
);
}
...
...
@@ -404,7 +454,7 @@ class DB2Platform extends AbstractPlatform
$sql
[]
=
'RENAME TABLE TO '
.
$diff
->
newName
;
}
return
$sql
;
return
array_merge
(
$sql
,
$columnSql
)
;
}
public
function
getDefaultValueDeclarationSQL
(
$field
)
...
...
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
View file @
a1b18d86
...
...
@@ -23,7 +23,12 @@ namespace Doctrine\DBAL\Platforms;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Schema\Index
,
Doctrine\DBAL\Schema\Table
;
Doctrine\DBAL\Schema\Table
,
Doctrine\DBAL\Events
,
Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs
,
Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs
,
Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs
,
Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs
;
/**
* The MsSqlPlatform provides the behavior, features and SQL dialect of the
...
...
@@ -278,20 +283,54 @@ class MsSqlPlatform extends AbstractPlatform
{
$queryParts
=
array
();
$sql
=
array
();
$columnSql
=
array
();
if
(
$diff
->
newName
!==
false
)
{
$queryParts
[]
=
'RENAME TO '
.
$diff
->
newName
;
}
foreach
(
$diff
->
addedColumns
AS
$fieldName
=>
$column
)
{
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
onSchemaAlterTableAddColumn
))
{
$eventArgs
=
new
SchemaAlterTableAddColumnEventArgs
(
$column
,
$diff
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
onSchemaAlterTableAddColumn
,
$eventArgs
);
$columnSql
=
array_merge
(
$columnSql
,
$eventArgs
->
getSql
());
if
(
$eventArgs
->
isDefaultPrevented
())
{
continue
;
}
}
$queryParts
[]
=
'ADD '
.
$this
->
getColumnDeclarationSQL
(
$column
->
getQuotedName
(
$this
),
$column
->
toArray
());
}
foreach
(
$diff
->
removedColumns
AS
$column
)
{
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
onSchemaAlterTableRemoveColumn
))
{
$eventArgs
=
new
SchemaAlterTableRemoveColumnEventArgs
(
$column
,
$diff
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
onSchemaAlterTableRemoveColumn
,
$eventArgs
);
$columnSql
=
array_merge
(
$columnSql
,
$eventArgs
->
getSql
());
if
(
$eventArgs
->
isDefaultPrevented
())
{
continue
;
}
}
$queryParts
[]
=
'DROP COLUMN '
.
$column
->
getQuotedName
(
$this
);
}
foreach
(
$diff
->
changedColumns
AS
$columnDiff
)
{
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
onSchemaAlterTableChangeColumn
))
{
$eventArgs
=
new
SchemaAlterTableChangeColumnEventArgs
(
$columnDiff
,
$diff
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
onSchemaAlterTableChangeColumn
,
$eventArgs
);
$columnSql
=
array_merge
(
$columnSql
,
$eventArgs
->
getSql
());
if
(
$eventArgs
->
isDefaultPrevented
())
{
continue
;
}
}
/* @var $columnDiff Doctrine\DBAL\Schema\ColumnDiff */
$column
=
$columnDiff
->
column
;
$queryParts
[]
=
'ALTER COLUMN '
.
...
...
@@ -299,6 +338,17 @@ class MsSqlPlatform extends AbstractPlatform
}
foreach
(
$diff
->
renamedColumns
AS
$oldColumnName
=>
$column
)
{
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
onSchemaAlterTableRenameColumn
))
{
$eventArgs
=
new
SchemaAlterTableRenameColumnEventArgs
(
$oldColumnName
,
$column
,
$diff
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
onSchemaAlterTableRenameColumn
,
$eventArgs
);
$columnSql
=
array_merge
(
$columnSql
,
$eventArgs
->
getSql
());
if
(
$eventArgs
->
isDefaultPrevented
())
{
continue
;
}
}
$sql
[]
=
"sp_RENAME '"
.
$diff
->
name
.
"."
.
$oldColumnName
.
"' , '"
.
$column
->
getQuotedName
(
$this
)
.
"', 'COLUMN'"
;
$queryParts
[]
=
'ALTER COLUMN '
.
$this
->
getColumnDeclarationSQL
(
$column
->
getQuotedName
(
$this
),
$column
->
toArray
());
...
...
@@ -308,7 +358,7 @@ class MsSqlPlatform extends AbstractPlatform
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' '
.
$query
;
}
$sql
=
array_merge
(
$sql
,
$this
->
_getAlterTableIndexForeignKeySQL
(
$diff
));
$sql
=
array_merge
(
$sql
,
$this
->
_getAlterTableIndexForeignKeySQL
(
$diff
)
,
$columnSql
);
return
$sql
;
}
...
...
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
a1b18d86
...
...
@@ -22,7 +22,12 @@ namespace Doctrine\DBAL\Platforms;
use
Doctrine\DBAL\DBALException
,
Doctrine\DBAL\Schema\TableDiff
,
Doctrine\DBAL\Schema\Index
,
Doctrine\DBAL\Schema\Table
;
Doctrine\DBAL\Schema\Table
,
Doctrine\DBAL\Events
,
Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs
,
Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs
,
Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs
,
Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs
;
/**
* The MySqlPlatform provides the behavior, features and SQL dialect of the
...
...
@@ -454,22 +459,56 @@ class MySqlPlatform extends AbstractPlatform
*/
public
function
getAlterTableSQL
(
TableDiff
$diff
)
{
$columnSql
=
array
();
$queryParts
=
array
();
if
(
$diff
->
newName
!==
false
)
{
$queryParts
[]
=
'RENAME TO '
.
$diff
->
newName
;
}
foreach
(
$diff
->
addedColumns
AS
$fieldName
=>
$column
)
{
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
onSchemaAlterTableAddColumn
))
{
$eventArgs
=
new
SchemaAlterTableAddColumnEventArgs
(
$column
,
$diff
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
onSchemaAlterTableAddColumn
,
$eventArgs
);
$columnSql
=
array_merge
(
$columnSql
,
$eventArgs
->
getSql
());
if
(
$eventArgs
->
isDefaultPrevented
())
{
continue
;
}
}
$columnArray
=
$column
->
toArray
();
$columnArray
[
'comment'
]
=
$this
->
getColumnComment
(
$column
);
$queryParts
[]
=
'ADD '
.
$this
->
getColumnDeclarationSQL
(
$column
->
getQuotedName
(
$this
),
$columnArray
);
}
foreach
(
$diff
->
removedColumns
AS
$column
)
{
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
onSchemaAlterTableRemoveColumn
))
{
$eventArgs
=
new
SchemaAlterTableRemoveColumnEventArgs
(
$column
,
$diff
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
onSchemaAlterTableRemoveColumn
,
$eventArgs
);
$columnSql
=
array_merge
(
$columnSql
,
$eventArgs
->
getSql
());
if
(
$eventArgs
->
isDefaultPrevented
())
{
continue
;
}
}
$queryParts
[]
=
'DROP '
.
$column
->
getQuotedName
(
$this
);
}
foreach
(
$diff
->
changedColumns
AS
$columnDiff
)
{
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
onSchemaAlterTableChangeColumn
))
{
$eventArgs
=
new
SchemaAlterTableChangeColumnEventArgs
(
$columnDiff
,
$diff
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
onSchemaAlterTableChangeColumn
,
$eventArgs
);
$columnSql
=
array_merge
(
$columnSql
,
$eventArgs
->
getSql
());
if
(
$eventArgs
->
isDefaultPrevented
())
{
continue
;
}
}
/* @var $columnDiff Doctrine\DBAL\Schema\ColumnDiff */
$column
=
$columnDiff
->
column
;
$columnArray
=
$column
->
toArray
();
...
...
@@ -479,6 +518,17 @@ class MySqlPlatform extends AbstractPlatform
}
foreach
(
$diff
->
renamedColumns
AS
$oldColumnName
=>
$column
)
{
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
onSchemaAlterTableRenameColumn
))
{
$eventArgs
=
new
SchemaAlterTableRenameColumnEventArgs
(
$oldColumnName
,
$column
,
$diff
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
onSchemaAlterTableRenameColumn
,
$eventArgs
);
$columnSql
=
array_merge
(
$columnSql
,
$eventArgs
->
getSql
());
if
(
$eventArgs
->
isDefaultPrevented
())
{
continue
;
}
}
$columnArray
=
$column
->
toArray
();
$columnArray
[
'comment'
]
=
$this
->
getColumnComment
(
$column
);
$queryParts
[]
=
'CHANGE '
.
$oldColumnName
.
' '
...
...
@@ -492,7 +542,8 @@ class MySqlPlatform extends AbstractPlatform
$sql
=
array_merge
(
$this
->
getPreAlterTableIndexForeignKeySQL
(
$diff
),
$sql
,
$this
->
getPostAlterTableIndexForeignKeySQL
(
$diff
)
$this
->
getPostAlterTableIndexForeignKeySQL
(
$diff
),
$columnSql
);
return
$sql
;
}
...
...
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
View file @
a1b18d86
...
...
@@ -19,7 +19,12 @@
namespace
Doctrine\DBAL\Platforms
;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\Schema\TableDiff
,
Doctrine\DBAL\Events
,
Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs
,
Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs
,
Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs
,
Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs
;
/**
* OraclePlatform.
...
...
@@ -540,9 +545,21 @@ LEFT JOIN all_cons_columns r_cols
{
$sql
=
array
();
$commentsSQL
=
array
();
$columnSql
=
array
();
$fields
=
array
();
foreach
(
$diff
->
addedColumns
AS
$column
)
{
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
onSchemaAlterTableAddColumn
))
{
$eventArgs
=
new
SchemaAlterTableAddColumnEventArgs
(
$column
,
$diff
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
onSchemaAlterTableAddColumn
,
$eventArgs
);
$columnSql
=
array_merge
(
$columnSql
,
$eventArgs
->
getSql
());
if
(
$eventArgs
->
isDefaultPrevented
())
{
continue
;
}
}
$fields
[]
=
$this
->
getColumnDeclarationSQL
(
$column
->
getQuotedName
(
$this
),
$column
->
toArray
());
if
(
$comment
=
$this
->
getColumnComment
(
$column
))
{
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
getName
(),
$comment
);
...
...
@@ -554,6 +571,17 @@ LEFT JOIN all_cons_columns r_cols
$fields
=
array
();
foreach
(
$diff
->
changedColumns
AS
$columnDiff
)
{
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
onSchemaAlterTableChangeColumn
))
{
$eventArgs
=
new
SchemaAlterTableChangeColumnEventArgs
(
$columnDiff
,
$diff
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
onSchemaAlterTableChangeColumn
,
$eventArgs
);
$columnSql
=
array_merge
(
$columnSql
,
$eventArgs
->
getSql
());
if
(
$eventArgs
->
isDefaultPrevented
())
{
continue
;
}
}
$column
=
$columnDiff
->
column
;
$fields
[]
=
$column
->
getQuotedName
(
$this
)
.
' '
.
$this
->
getColumnDeclarationSQL
(
''
,
$column
->
toArray
());
if
(
$columnDiff
->
hasChanged
(
'comment'
)
&&
$comment
=
$this
->
getColumnComment
(
$column
))
{
...
...
@@ -565,11 +593,33 @@ LEFT JOIN all_cons_columns r_cols
}
foreach
(
$diff
->
renamedColumns
AS
$oldColumnName
=>
$column
)
{
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
onSchemaAlterTableRenameColumn
))
{
$eventArgs
=
new
SchemaAlterTableRenameColumnEventArgs
(
$oldColumnName
,
$column
,
$diff
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
onSchemaAlterTableRenameColumn
,
$eventArgs
);
$columnSql
=
array_merge
(
$columnSql
,
$eventArgs
->
getSql
());
if
(
$eventArgs
->
isDefaultPrevented
())
{
continue
;
}
}
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' RENAME COLUMN '
.
$oldColumnName
.
' TO '
.
$column
->
getQuotedName
(
$this
);
}
$fields
=
array
();
foreach
(
$diff
->
removedColumns
AS
$column
)
{
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
onSchemaAlterTableRemoveColumn
))
{
$eventArgs
=
new
SchemaAlterTableRemoveColumnEventArgs
(
$column
,
$diff
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
onSchemaAlterTableRemoveColumn
,
$eventArgs
);
$columnSql
=
array_merge
(
$columnSql
,
$eventArgs
->
getSql
());
if
(
$eventArgs
->
isDefaultPrevented
())
{
continue
;
}
}
$fields
[]
=
$column
->
getQuotedName
(
$this
);
}
if
(
count
(
$fields
))
{
...
...
@@ -580,7 +630,7 @@ LEFT JOIN all_cons_columns r_cols
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' RENAME TO '
.
$diff
->
newName
;
}
return
array_merge
(
$sql
,
$this
->
_getAlterTableIndexForeignKeySQL
(
$diff
),
$commentsSQL
);
return
array_merge
(
$sql
,
$this
->
_getAlterTableIndexForeignKeySQL
(
$diff
),
$commentsSQL
,
$columnSql
);
}
/**
...
...
tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
View file @
a1b18d86
...
...
@@ -126,4 +126,9 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
{
$this
->
markTestSkipped
(
'SQlite does not support ALTER Table.'
);
}
public
function
testGetAlterTableSqlDispatchEvent
()
{
$this
->
markTestSkipped
(
'SQlite does not support ALTER Table.'
);
}
}
\ No newline at end of file
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