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
b94e0091
Commit
b94e0091
authored
Feb 19, 2011
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DBAL-42] Add support for inline and COMMENT ON syntax for MySQL, PostgreSQL and Oracle.
parent
45975b07
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
155 additions
and
5 deletions
+155
-5
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+39
-1
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+5
-0
OraclePlatform.php
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
+13
-3
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+8
-0
Column.php
lib/Doctrine/DBAL/Schema/Column.php
+1
-0
AbstractPlatformTestCase.php
...octrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
+39
-0
MsSqlPlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/MsSqlPlatformTest.php
+1
-0
MySqlPlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
+10
-0
OraclePlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
+17
-0
PostgreSqlPlatformTest.php
.../Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
+16
-0
ColumnTest.php
tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php
+6
-1
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
b94e0091
...
...
@@ -797,6 +797,7 @@ abstract class AbstractPlatform
$columnData
[
'default'
]
=
$column
->
getDefault
();
$columnData
[
'columnDefinition'
]
=
$column
->
getColumnDefinition
();
$columnData
[
'autoincrement'
]
=
$column
->
getAutoincrement
();
$columnData
[
'comment'
]
=
$column
->
getComment
();
if
(
in_array
(
$column
->
getName
(),
$options
[
'primary'
]))
{
$columnData
[
'primary'
]
=
true
;
...
...
@@ -812,7 +813,20 @@ abstract class AbstractPlatform
}
}
return
$this
->
_getCreateTableSQL
(
$tableName
,
$columns
,
$options
);
$sql
=
$this
->
_getCreateTableSQL
(
$tableName
,
$columns
,
$options
);
if
(
$this
->
supportsCommentOnStatement
())
{
foreach
(
$table
->
getColumns
()
AS
$column
)
{
if
(
$column
->
getComment
())
{
$sql
[]
=
$this
->
getCommentOnColumnSQL
(
$tableName
,
$column
->
getName
(),
$column
->
getComment
());
}
}
}
return
$sql
;
}
public
function
getCommentOnColumnSQL
(
$tableName
,
$columnName
,
$comment
)
{
return
"COMMENT ON "
.
$tableName
.
"."
.
$columnName
.
" IS '"
.
$comment
.
"'"
;
}
/**
...
...
@@ -1142,6 +1156,10 @@ abstract class AbstractPlatform
$columnDef
=
$typeDecl
.
$charset
.
$default
.
$notnull
.
$unique
.
$check
.
$collation
;
}
if
(
$this
->
supportsInlineColumnComments
()
&&
isset
(
$field
[
'comment'
])
&&
$field
[
'comment'
])
{
$columnDef
.=
" COMMENT '"
.
$field
[
'comment'
]
.
"'"
;
}
return
$name
.
' '
.
$columnDef
;
}
...
...
@@ -1880,6 +1898,26 @@ abstract class AbstractPlatform
return
true
;
}
/**
* Does this plaform support to add inline column comments as postfix.
*
* @return bool
*/
public
function
supportsInlineColumnComments
()
{
return
false
;
}
/**
* Does this platform support the propriortary synatx "COMMENT ON asset"
*
* @return bool
*/
public
function
supportsCommentOnStatement
()
{
return
false
;
}
public
function
getIdentityColumnNullInsertSQL
()
{
return
""
;
...
...
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
b94e0091
...
...
@@ -259,6 +259,11 @@ class MySqlPlatform extends AbstractPlatform
return
true
;
}
public
function
supportsInlineColumnComments
()
{
return
true
;
}
public
function
getShowDatabasesSQL
()
{
return
'SHOW DATABASES'
;
...
...
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
View file @
b94e0091
...
...
@@ -499,10 +499,14 @@ LEFT JOIN all_cons_columns r_cols
public
function
getAlterTableSQL
(
TableDiff
$diff
)
{
$sql
=
array
();
$commentsSQL
=
array
();
$fields
=
array
();
foreach
(
$diff
->
addedColumns
AS
$column
)
{
$fields
[]
=
$this
->
getColumnDeclarationSQL
(
$column
->
getQuotedName
(
$this
),
$column
->
toArray
());
if
(
$column
->
getComment
())
{
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
getName
(),
$column
->
getComment
());
}
}
if
(
count
(
$fields
))
{
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' ADD ('
.
implode
(
', '
,
$fields
)
.
')'
;
...
...
@@ -512,6 +516,9 @@ LEFT JOIN all_cons_columns r_cols
foreach
(
$diff
->
changedColumns
AS
$columnDiff
)
{
$column
=
$columnDiff
->
column
;
$fields
[]
=
$column
->
getQuotedName
(
$this
)
.
' '
.
$this
->
getColumnDeclarationSQL
(
''
,
$column
->
toArray
());
if
(
$columnDiff
->
hasChanged
(
'comment'
)
&&
$column
->
getComment
())
{
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
getName
(),
$column
->
getComment
());
}
}
if
(
count
(
$fields
))
{
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' MODIFY ('
.
implode
(
', '
,
$fields
)
.
')'
;
...
...
@@ -533,9 +540,7 @@ LEFT JOIN all_cons_columns r_cols
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' RENAME TO '
.
$diff
->
newName
;
}
$sql
=
array_merge
(
$sql
,
$this
->
_getAlterTableIndexForeignKeySQL
(
$diff
));
return
$sql
;
return
array_merge
(
$sql
,
$this
->
_getAlterTableIndexForeignKeySQL
(
$diff
),
$commentsSQL
);
}
/**
...
...
@@ -548,6 +553,11 @@ LEFT JOIN all_cons_columns r_cols
return
true
;
}
public
function
supportsCommentOnStatement
()
{
return
true
;
}
/**
* Get the platform name for this instance
*
...
...
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
b94e0091
...
...
@@ -135,6 +135,11 @@ class PostgreSqlPlatform extends AbstractPlatform
{
return
true
;
}
public
function
supportsCommentOnStatement
()
{
return
true
;
}
/**
* Whether the platform prefers sequences for ID generation.
...
...
@@ -385,6 +390,9 @@ class PostgreSqlPlatform extends AbstractPlatform
$sql
[]
=
"ALTER TABLE "
.
$diff
->
name
.
" "
.
$query
;
}
}
if
(
$columnDiff
->
hasChanged
(
'comment'
))
{
$sql
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
getName
(),
$column
->
getComment
());
}
}
foreach
(
$diff
->
renamedColumns
as
$oldColumnName
=>
$column
)
{
...
...
lib/Doctrine/DBAL/Schema/Column.php
View file @
b94e0091
...
...
@@ -357,6 +357,7 @@ class Column extends AbstractAsset
'unsigned'
=>
$this
->
_unsigned
,
'autoincrement'
=>
$this
->
_autoincrement
,
'columnDefinition'
=>
$this
->
_columnDefinition
,
'comment'
=>
$this
->
_comment
,
),
$this
->
_platformOptions
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
View file @
b94e0091
...
...
@@ -165,4 +165,43 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$field
=
array
(
'columnDefinition'
=>
'MEDIUMINT(6) UNSIGNED'
);
$this
->
assertEquals
(
'foo MEDIUMINT(6) UNSIGNED'
,
$this
->
_platform
->
getColumnDeclarationSQL
(
'foo'
,
$field
));
}
/**
* @group DBAL-42
*/
public
function
testCreateTableColumnComments
()
{
$table
=
new
\Doctrine\DBAL\Schema\Table
(
'test'
);
$table
->
addColumn
(
'id'
,
'integer'
,
array
(
'comment'
=>
'This is a comment'
));
$table
->
setPrimaryKey
(
array
(
'id'
));
$this
->
assertEquals
(
$this
->
getCreateTableColumnCommentsSQL
(),
$this
->
_platform
->
getCreateTableSQL
(
$table
));
}
/**
* @group DBAL-42
*/
public
function
testAlterTableColumnComments
()
{
$tableDiff
=
new
\Doctrine\DBAL\Schema\TableDiff
(
'mytable'
);
$tableDiff
->
addedColumns
[
'quota'
]
=
new
\Doctrine\DBAL\Schema\Column
(
'quota'
,
\Doctrine\DBAL\Types\Type
::
getType
(
'integer'
),
array
(
'comment'
=>
'A comment'
));
$tableDiff
->
changedColumns
[
'bar'
]
=
new
\Doctrine\DBAL\Schema\ColumnDiff
(
'bar'
,
new
\Doctrine\DBAL\Schema\Column
(
'baz'
,
\Doctrine\DBAL\Types\Type
::
getType
(
'string'
),
array
(
'comment'
=>
'B comment'
)
),
array
(
'comment'
)
);
$this
->
assertEquals
(
$this
->
getAlterTableColumnCommentsSQL
(),
$this
->
_platform
->
getAlterTableSQL
(
$tableDiff
));
}
public
function
getCreateTableColumnCommentsSQL
()
{
$this
->
markTestSkipped
(
'Platform does not support Column comments.'
);
}
public
function
getAlterTableColumnCommentsSQL
()
{
$this
->
markTestSkipped
(
'Platform does not support Column comments.'
);
}
}
tests/Doctrine/Tests/DBAL/Platforms/MsSqlPlatformTest.php
View file @
b94e0091
...
...
@@ -171,4 +171,5 @@ class MsSqlPlatformTest extends AbstractPlatformTestCase
$this
->
assertEquals
(
'SELECT TOP 10 * FROM user ORDER BY username DESC'
,
$sql
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
View file @
b94e0091
...
...
@@ -166,4 +166,14 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
$this
->
assertEquals
(
"TIMESTAMP"
,
$this
->
_platform
->
getDateTimeTypeDeclarationSQL
(
array
(
'version'
=>
true
)));
$this
->
assertEquals
(
"DATETIME"
,
$this
->
_platform
->
getDateTimeTypeDeclarationSQL
(
array
()));
}
public
function
getCreateTableColumnCommentsSQL
()
{
return
array
(
"CREATE TABLE test (id INT NOT NULL COMMENT 'This is a comment', PRIMARY KEY(id)) ENGINE = InnoDB"
);
}
public
function
getAlterTableColumnCommentsSQL
()
{
return
array
(
"ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'"
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
View file @
b94e0091
...
...
@@ -186,4 +186,21 @@ class OraclePlatformTest extends AbstractPlatformTestCase
$sql
=
$this
->
_platform
->
modifyLimitQuery
(
'SELECT * FROM user ORDER BY username DESC'
,
10
);
$this
->
assertEquals
(
'SELECT a.* FROM (SELECT * FROM user ORDER BY username DESC) a WHERE ROWNUM <= 10'
,
$sql
);
}
public
function
getCreateTableColumnCommentsSQL
()
{
return
array
(
"CREATE TABLE test (id NUMBER(10) NOT NULL, PRIMARY KEY(id))"
,
"COMMENT ON test.id IS 'This is a comment'"
,
);
}
public
function
getAlterTableColumnCommentsSQL
()
{
return
array
(
"ALTER TABLE mytable ADD (quota NUMBER(10) NOT NULL)"
,
"ALTER TABLE mytable MODIFY (baz VARCHAR2(255) NOT NULL)"
,
"COMMENT ON mytable.baz IS 'B comment'"
,
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
View file @
b94e0091
...
...
@@ -199,4 +199,20 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
$sql
=
$this
->
_platform
->
modifyLimitQuery
(
'SELECT * FROM user'
,
10
);
$this
->
assertEquals
(
'SELECT * FROM user LIMIT 10'
,
$sql
);
}
public
function
getCreateTableColumnCommentsSQL
()
{
return
array
(
"CREATE TABLE test (id INT NOT NULL, PRIMARY KEY(id))"
,
"COMMENT ON test.id IS 'This is a comment'"
,
);
}
public
function
getAlterTableColumnCommentsSQL
()
{
return
array
(
"ALTER TABLE mytable ADD quota INT NOT NULL"
,
"COMMENT ON mytable.baz IS 'B comment'"
,
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php
View file @
b94e0091
...
...
@@ -46,6 +46,7 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
'unsigned'
=>
true
,
'autoincrement'
=>
false
,
'columnDefinition'
=>
null
,
'comment'
=>
null
,
'foo'
=>
'bar'
,
);
...
...
@@ -93,10 +94,14 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
*/
public
function
testColumnComment
()
{
$column
=
new
Column
(
"
`bar`
"
,
Type
::
getType
(
'string'
));
$column
=
new
Column
(
"
bar
"
,
Type
::
getType
(
'string'
));
$this
->
assertNull
(
$column
->
getComment
());
$column
->
setComment
(
"foo"
);
$this
->
assertEquals
(
"foo"
,
$column
->
getComment
());
$columnArray
=
$column
->
toArray
();
$this
->
assertArrayHasKey
(
'comment'
,
$columnArray
);
$this
->
assertEquals
(
'foo'
,
$columnArray
[
'comment'
]);
}
}
\ 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