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
4b8b6434
Commit
4b8b6434
authored
Oct 15, 2014
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix generating COMMENT ON COLUMN statements for quoted identifiers
parent
fbd49846
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
206 additions
and
11 deletions
+206
-11
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+4
-1
OraclePlatform.php
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
+7
-3
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+11
-4
SQLAnywherePlatform.php
lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
+10
-3
AbstractMySQLPlatformTestCase.php
...ne/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php
+12
-0
AbstractPlatformTestCase.php
...octrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
+22
-0
AbstractPostgreSqlPlatformTestCase.php
...sts/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
+35
-0
AbstractSQLServerPlatformTestCase.php
...ests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php
+12
-0
DB2PlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php
+12
-0
OraclePlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
+35
-0
SQLAnywherePlatformTest.php
...Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php
+34
-0
SqlitePlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
+12
-0
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
4b8b6434
...
...
@@ -1594,9 +1594,12 @@ abstract class AbstractPlatform
*/
public
function
getCommentOnColumnSQL
(
$tableName
,
$columnName
,
$comment
)
{
$tableName
=
new
Identifier
(
$tableName
);
$columnName
=
new
Identifier
(
$columnName
);
$comment
=
$this
->
quoteStringLiteral
(
$comment
);
return
"COMMENT ON COLUMN "
.
$tableName
.
"."
.
$columnName
.
" IS "
.
$comment
;
return
"COMMENT ON COLUMN "
.
$tableName
->
getQuotedName
(
$this
)
.
"."
.
$columnName
->
getQuotedName
(
$this
)
.
" IS "
.
$comment
;
}
/**
...
...
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
View file @
4b8b6434
...
...
@@ -697,7 +697,11 @@ LEFT JOIN user_cons_columns r_cols
$fields
[]
=
$this
->
getColumnDeclarationSQL
(
$column
->
getQuotedName
(
$this
),
$column
->
toArray
());
if
(
$comment
=
$this
->
getColumnComment
(
$column
))
{
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
getName
(),
$comment
);
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
getName
(
$this
)
->
getQuotedName
(
$this
),
$column
->
getQuotedName
(
$this
),
$comment
);
}
}
...
...
@@ -741,8 +745,8 @@ LEFT JOIN user_cons_columns r_cols
if
(
$columnHasChangedComment
)
{
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
get
Name
(
),
$diff
->
getName
(
$this
)
->
getQuotedName
(
$this
)
,
$column
->
get
QuotedName
(
$this
),
$this
->
getColumnComment
(
$column
)
);
}
...
...
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
4b8b6434
...
...
@@ -458,7 +458,11 @@ class PostgreSqlPlatform extends AbstractPlatform
$comment
=
$this
->
getColumnComment
(
$column
);
if
(
null
!==
$comment
&&
''
!==
$comment
)
{
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
getName
(),
$comment
);
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
getName
(
$this
)
->
getQuotedName
(
$this
),
$column
->
getQuotedName
(
$this
),
$comment
);
}
}
...
...
@@ -523,8 +527,8 @@ class PostgreSqlPlatform extends AbstractPlatform
if
(
$columnDiff
->
hasChanged
(
'comment'
))
{
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
get
Name
(
),
$diff
->
getName
(
$this
)
->
getQuotedName
(
$this
)
,
$column
->
get
QuotedName
(
$this
),
$this
->
getColumnComment
(
$column
)
);
}
...
...
@@ -624,9 +628,12 @@ class PostgreSqlPlatform extends AbstractPlatform
*/
public
function
getCommentOnColumnSQL
(
$tableName
,
$columnName
,
$comment
)
{
$tableName
=
new
Identifier
(
$tableName
);
$columnName
=
new
Identifier
(
$columnName
);
$comment
=
$comment
===
null
?
'NULL'
:
$this
->
quoteStringLiteral
(
$comment
);
return
"COMMENT ON COLUMN
$tableName
.
$columnName
IS
$comment
"
;
return
"COMMENT ON COLUMN "
.
$tableName
->
getQuotedName
(
$this
)
.
"."
.
$columnName
->
getQuotedName
(
$this
)
.
" IS
$comment
"
;
}
/**
...
...
lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
View file @
4b8b6434
...
...
@@ -144,7 +144,11 @@ class SQLAnywherePlatform extends AbstractPlatform
$comment
=
$this
->
getColumnComment
(
$column
);
if
(
null
!==
$comment
&&
''
!==
$comment
)
{
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
getQuotedName
(
$this
),
$comment
);
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
getName
(
$this
)
->
getQuotedName
(
$this
),
$column
->
getQuotedName
(
$this
),
$comment
);
}
}
...
...
@@ -173,7 +177,7 @@ class SQLAnywherePlatform extends AbstractPlatform
$column
=
$columnDiff
->
column
;
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$diff
->
getName
(
$this
)
->
getQuotedName
(
$this
)
,
$column
->
getQuotedName
(
$this
),
$this
->
getColumnComment
(
$column
)
);
...
...
@@ -363,9 +367,12 @@ class SQLAnywherePlatform extends AbstractPlatform
*/
public
function
getCommentOnColumnSQL
(
$tableName
,
$columnName
,
$comment
)
{
$tableName
=
new
Identifier
(
$tableName
);
$columnName
=
new
Identifier
(
$columnName
);
$comment
=
$comment
===
null
?
'NULL'
:
$this
->
quoteStringLiteral
(
$comment
);
return
"COMMENT ON COLUMN
$tableName
.
$columnName
IS
$comment
"
;
return
"COMMENT ON COLUMN "
.
$tableName
->
getQuotedName
(
$this
)
.
'.'
.
$columnName
->
getQuotedName
(
$this
)
.
" IS
$comment
"
;
}
/**
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php
View file @
4b8b6434
...
...
@@ -629,4 +629,16 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
'ALTER TABLE `table` ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)'
,
);
}
/**
* {@inheritdoc}
*/
protected
function
getCommentOnColumnSQL
()
{
return
array
(
"COMMENT ON COLUMN foo.bar IS 'comment'"
,
"COMMENT ON COLUMN `Foo`.`BAR` IS 'comment'"
,
"COMMENT ON COLUMN `select`.`from` IS 'comment'"
,
);
}
}
tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
View file @
4b8b6434
...
...
@@ -916,6 +916,28 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
);
}
/**
* @return array
*
* @see testGetCommentOnColumnSQL
*/
abstract
protected
function
getCommentOnColumnSQL
();
/**
* @group DBAL-1004
*/
public
function
testGetCommentOnColumnSQL
()
{
$this
->
assertSame
(
$this
->
getCommentOnColumnSQL
(),
array
(
$this
->
_platform
->
getCommentOnColumnSQL
(
'foo'
,
'bar'
,
'comment'
),
// regular identifiers
$this
->
_platform
->
getCommentOnColumnSQL
(
'`Foo`'
,
'`BAR`'
,
'comment'
),
// explicitly quoted identifiers
$this
->
_platform
->
getCommentOnColumnSQL
(
'select'
,
'from'
,
'comment'
),
// reserved keyword identifiers
)
);
}
protected
function
getQuotedStringLiteralWithoutQuoteCharacter
()
{
return
"'No quote'"
;
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
View file @
4b8b6434
...
...
@@ -2,9 +2,11 @@
namespace
Doctrine\Tests\DBAL\Platforms
;
use
Doctrine\DBAL\Schema\Column
;
use
Doctrine\DBAL\Schema\Comparator
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\Types\Type
;
abstract
class
AbstractPostgreSqlPlatformTestCase
extends
AbstractPlatformTestCase
{
...
...
@@ -702,4 +704,37 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
'INITIALLY IMMEDIATE'
,
);
}
/**
* {@inheritdoc}
*/
protected
function
getCommentOnColumnSQL
()
{
return
array
(
'COMMENT ON COLUMN foo.bar IS \'comment\''
,
'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\''
,
'COMMENT ON COLUMN "select"."from" IS \'comment\''
,
);
}
/**
* @group DBAL-1004
*/
public
function
testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers
()
{
$table1
=
new
Table
(
'"foo"'
,
array
(
new
Column
(
'"bar"'
,
Type
::
getType
(
'integer'
))));
$table2
=
new
Table
(
'"foo"'
,
array
(
new
Column
(
'"bar"'
,
Type
::
getType
(
'integer'
),
array
(
'comment'
=>
'baz'
))));
$comparator
=
new
Comparator
();
$tableDiff
=
$comparator
->
diffTable
(
$table1
,
$table2
);
$this
->
assertInstanceOf
(
'Doctrine\DBAL\Schema\TableDiff'
,
$tableDiff
);
$this
->
assertSame
(
array
(
'COMMENT ON COLUMN "foo"."bar" IS \'baz\''
,
),
$this
->
_platform
->
getAlterTableSQL
(
$tableDiff
)
);
}
}
tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php
View file @
4b8b6434
...
...
@@ -1159,4 +1159,16 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
'ALTER TABLE [table] ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)'
,
);
}
/**
* {@inheritdoc}
*/
protected
function
getCommentOnColumnSQL
()
{
return
array
(
"COMMENT ON COLUMN foo.bar IS 'comment'"
,
"COMMENT ON COLUMN [Foo].[BAR] IS 'comment'"
,
"COMMENT ON COLUMN [select].[from] IS 'comment'"
,
);
}
}
tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php
View file @
4b8b6434
...
...
@@ -498,4 +498,16 @@ class DB2PlatformTest extends AbstractPlatformTestCase
'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)'
,
);
}
/**
* {@inheritdoc}
*/
protected
function
getCommentOnColumnSQL
()
{
return
array
(
'COMMENT ON COLUMN foo.bar IS \'comment\''
,
'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\''
,
'COMMENT ON COLUMN "select"."from" IS \'comment\''
,
);
}
}
tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
View file @
4b8b6434
...
...
@@ -3,8 +3,10 @@
namespace
Doctrine\Tests\DBAL\Platforms
;
use
Doctrine\DBAL\Platforms\OraclePlatform
;
use
Doctrine\DBAL\Schema\Column
;
use
Doctrine\DBAL\Schema\Comparator
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Types\Type
;
require_once
__DIR__
.
'/../../TestInit.php'
;
...
...
@@ -567,4 +569,37 @@ class OraclePlatformTest extends AbstractPlatformTestCase
'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)'
,
);
}
/**
* {@inheritdoc}
*/
protected
function
getCommentOnColumnSQL
()
{
return
array
(
'COMMENT ON COLUMN foo.bar IS \'comment\''
,
'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\''
,
'COMMENT ON COLUMN "select"."from" IS \'comment\''
,
);
}
/**
* @group DBAL-1004
*/
public
function
testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers
()
{
$table1
=
new
Table
(
'"foo"'
,
array
(
new
Column
(
'"bar"'
,
Type
::
getType
(
'integer'
))));
$table2
=
new
Table
(
'"foo"'
,
array
(
new
Column
(
'"bar"'
,
Type
::
getType
(
'integer'
),
array
(
'comment'
=>
'baz'
))));
$comparator
=
new
Comparator
();
$tableDiff
=
$comparator
->
diffTable
(
$table1
,
$table2
);
$this
->
assertInstanceOf
(
'Doctrine\DBAL\Schema\TableDiff'
,
$tableDiff
);
$this
->
assertSame
(
array
(
'COMMENT ON COLUMN "foo"."bar" IS \'baz\''
,
),
$this
->
_platform
->
getAlterTableSQL
(
$tableDiff
)
);
}
}
tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php
View file @
4b8b6434
...
...
@@ -8,6 +8,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use
Doctrine\DBAL\Platforms\SQLAnywherePlatform
;
use
Doctrine\DBAL\Schema\Column
;
use
Doctrine\DBAL\Schema\ColumnDiff
;
use
Doctrine\DBAL\Schema\Comparator
;
use
Doctrine\DBAL\Schema\ForeignKeyConstraint
;
use
Doctrine\DBAL\Schema\Index
;
use
Doctrine\DBAL\Schema\Table
;
...
...
@@ -889,4 +890,37 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)'
,
);
}
/**
* {@inheritdoc}
*/
protected
function
getCommentOnColumnSQL
()
{
return
array
(
'COMMENT ON COLUMN foo.bar IS \'comment\''
,
'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\''
,
'COMMENT ON COLUMN "select"."from" IS \'comment\''
,
);
}
/**
* @group DBAL-1004
*/
public
function
testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers
()
{
$table1
=
new
Table
(
'"foo"'
,
array
(
new
Column
(
'"bar"'
,
Type
::
getType
(
'integer'
))));
$table2
=
new
Table
(
'"foo"'
,
array
(
new
Column
(
'"bar"'
,
Type
::
getType
(
'integer'
),
array
(
'comment'
=>
'baz'
))));
$comparator
=
new
Comparator
();
$tableDiff
=
$comparator
->
diffTable
(
$table1
,
$table2
);
$this
->
assertInstanceOf
(
'Doctrine\DBAL\Schema\TableDiff'
,
$tableDiff
);
$this
->
assertSame
(
array
(
'COMMENT ON COLUMN "foo"."bar" IS \'baz\''
,
),
$this
->
_platform
->
getAlterTableSQL
(
$tableDiff
)
);
}
}
tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
View file @
4b8b6434
...
...
@@ -596,4 +596,16 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
'CREATE INDEX IDX_8C736521FDC58D6C ON "table" (fk2)'
,
);
}
/**
* {@inheritdoc}
*/
protected
function
getCommentOnColumnSQL
()
{
return
array
(
'COMMENT ON COLUMN foo.bar IS \'comment\''
,
'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\''
,
'COMMENT ON COLUMN "select"."from" IS \'comment\''
,
);
}
}
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