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
439f6743
Commit
439f6743
authored
Aug 21, 2014
by
Steve Müller
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'jibriss-fix-postgresql-comment'
Close #657
parents
3eebba76
2b01d9ab
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
132 additions
and
6 deletions
+132
-6
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+31
-2
DrizzlePlatform.php
lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php
+1
-1
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+1
-1
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+1
-1
SQLAnywherePlatform.php
lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
+1
-1
SchemaManagerFunctionalTestCase.php
...BAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
+18
-0
AbstractPlatformTestCase.php
...octrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
+71
-0
AbstractPostgreSqlPlatformTestCase.php
...sts/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
+8
-0
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
439f6743
...
...
@@ -1589,7 +1589,9 @@ abstract class AbstractPlatform
*/
public
function
getCommentOnColumnSQL
(
$tableName
,
$columnName
,
$comment
)
{
return
"COMMENT ON COLUMN "
.
$tableName
.
"."
.
$columnName
.
" IS '"
.
$comment
.
"'"
;
$comment
=
$this
->
quoteStringLiteral
(
$comment
);
return
"COMMENT ON COLUMN "
.
$tableName
.
"."
.
$columnName
.
" IS "
.
$comment
;
}
/**
...
...
@@ -2201,7 +2203,7 @@ abstract class AbstractPlatform
}
if
(
$this
->
supportsInlineColumnComments
()
&&
isset
(
$field
[
'comment'
])
&&
$field
[
'comment'
])
{
$columnDef
.=
" COMMENT
'"
.
$field
[
'comment'
]
.
"'"
;
$columnDef
.=
" COMMENT
"
.
$this
->
quoteStringLiteral
(
$field
[
'comment'
])
;
}
return
$name
.
' '
.
$columnDef
;
...
...
@@ -3484,4 +3486,31 @@ abstract class AbstractPlatform
{
throw
DBALException
::
notSupported
(
__METHOD__
);
}
/**
* Quotes a literal string.
* This method is NOT meant to fix SQL injections!
* It is only meant to escape this platform's string literal
* quote character inside the given literal string.
*
* @param string $str The literal string to be quoted.
*
* @return string The quoted literal string.
*/
public
function
quoteStringLiteral
(
$str
)
{
$c
=
$this
->
getStringLiteralQuoteCharacter
();
return
$c
.
str_replace
(
$c
,
$c
.
$c
,
$str
)
.
$c
;
}
/**
* Gets the character used for string literal quoting.
*
* @return string
*/
public
function
getStringLiteralQuoteCharacter
()
{
return
"'"
;
}
}
lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php
View file @
439f6743
...
...
@@ -275,7 +275,7 @@ class DrizzlePlatform extends AbstractPlatform
if
(
isset
(
$options
[
'comment'
]))
{
$comment
=
trim
(
$options
[
'comment'
],
" '"
);
$tableOptions
[]
=
sprintf
(
"COMMENT =
'%s' "
,
str_replace
(
"'"
,
"''"
,
$comment
));
$tableOptions
[]
=
sprintf
(
"COMMENT =
%s "
,
$this
->
quoteStringLiteral
(
$comment
));
}
// Row format
...
...
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
439f6743
...
...
@@ -494,7 +494,7 @@ class MySqlPlatform extends AbstractPlatform
if
(
isset
(
$options
[
'comment'
]))
{
$comment
=
trim
(
$options
[
'comment'
],
" '"
);
$tableOptions
[]
=
sprintf
(
"COMMENT =
'%s' "
,
str_replace
(
"'"
,
"''"
,
$comment
));
$tableOptions
[]
=
sprintf
(
"COMMENT =
%s "
,
$this
->
quoteStringLiteral
(
$comment
));
}
// Row format
...
...
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
439f6743
...
...
@@ -615,7 +615,7 @@ class PostgreSqlPlatform extends AbstractPlatform
*/
public
function
getCommentOnColumnSQL
(
$tableName
,
$columnName
,
$comment
)
{
$comment
=
$comment
===
null
?
'NULL'
:
"'
$comment
'"
;
$comment
=
$comment
===
null
?
'NULL'
:
$this
->
quoteStringLiteral
(
$comment
)
;
return
"COMMENT ON COLUMN
$tableName
.
$columnName
IS
$comment
"
;
}
...
...
lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
View file @
439f6743
...
...
@@ -357,7 +357,7 @@ class SQLAnywherePlatform extends AbstractPlatform
*/
public
function
getCommentOnColumnSQL
(
$tableName
,
$columnName
,
$comment
)
{
$comment
=
$comment
===
null
?
'NULL'
:
"'
$comment
'"
;
$comment
=
$comment
===
null
?
'NULL'
:
$this
->
quoteStringLiteral
(
$comment
)
;
return
"COMMENT ON COLUMN
$tableName
.
$columnName
IS
$comment
"
;
}
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
View file @
439f6743
...
...
@@ -869,4 +869,22 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this
->
_sm
->
listTableForeignKeys
(
$defaultSchemaName
.
'.'
.
$primaryTableName
)
);
}
public
function
testCommentStringsAreQuoted
()
{
if
(
!
$this
->
_conn
->
getDatabasePlatform
()
->
supportsInlineColumnComments
()
&&
!
$this
->
_conn
->
getDatabasePlatform
()
->
supportsCommentOnStatement
()
&&
$this
->
_conn
->
getDatabasePlatform
()
->
getName
()
!=
'mssql'
)
{
$this
->
markTestSkipped
(
'Database does not support column comments.'
);
}
$table
=
new
Table
(
'my_table'
);
$table
->
addColumn
(
'id'
,
'integer'
,
array
(
'comment'
=>
"It's a comment with a quote"
));
$table
->
setPrimaryKey
(
array
(
'id'
));
$this
->
_sm
->
createTable
(
$table
);
$columns
=
$this
->
_sm
->
listTableColumns
(
"my_table"
);
$this
->
assertEquals
(
"It's a comment with a quote"
,
$columns
[
'id'
]
->
getComment
());
}
}
tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
View file @
439f6743
...
...
@@ -860,4 +860,75 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
'CREATE INDEX "bar" ON "schema"."table" (id)'
,
);
}
protected
function
getStringLiteralQuoteCharacter
()
{
return
"'"
;
}
public
function
testGetStringLiteralQuoteCharacter
()
{
$this
->
assertSame
(
$this
->
getStringLiteralQuoteCharacter
(),
$this
->
_platform
->
getStringLiteralQuoteCharacter
());
}
protected
function
getQuotedCommentOnColumnSQLWithoutQuoteCharacter
()
{
return
"COMMENT ON COLUMN mytable.id IS 'This is a comment'"
;
}
public
function
testGetCommentOnColumnSQLWithoutQuoteCharacter
()
{
$this
->
assertEquals
(
$this
->
getQuotedCommentOnColumnSQLWithoutQuoteCharacter
(),
$this
->
_platform
->
getCommentOnColumnSQL
(
'mytable'
,
'id'
,
'This is a comment'
)
);
}
protected
function
getQuotedCommentOnColumnSQLWithQuoteCharacter
()
{
return
"COMMENT ON COLUMN mytable.id IS 'It''s a quote !'"
;
}
public
function
testGetCommentOnColumnSQLWithQuoteCharacter
()
{
$c
=
$this
->
getStringLiteralQuoteCharacter
();
$this
->
assertEquals
(
$this
->
getQuotedCommentOnColumnSQLWithQuoteCharacter
(),
$this
->
_platform
->
getCommentOnColumnSQL
(
'mytable'
,
'id'
,
"It"
.
$c
.
"s a quote !"
)
);
}
protected
function
getQuotedStringLiteralWithoutQuoteCharacter
()
{
return
"'No quote'"
;
}
protected
function
getQuotedStringLiteralWithQuoteCharacter
()
{
return
"'It''s a quote'"
;
}
protected
function
getQuotedStringLiteralQuoteCharacter
()
{
return
"''''"
;
}
public
function
testQuoteStringLiteral
()
{
$c
=
$this
->
getStringLiteralQuoteCharacter
();
$this
->
assertEquals
(
$this
->
getQuotedStringLiteralWithoutQuoteCharacter
(),
$this
->
_platform
->
quoteStringLiteral
(
'No quote'
)
);
$this
->
assertEquals
(
$this
->
getQuotedStringLiteralWithQuoteCharacter
(),
$this
->
_platform
->
quoteStringLiteral
(
'It'
.
$c
.
's a quote'
)
);
$this
->
assertEquals
(
$this
->
getQuotedStringLiteralQuoteCharacter
(),
$this
->
_platform
->
quoteStringLiteral
(
$c
)
);
}
}
tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
View file @
439f6743
...
...
@@ -656,4 +656,12 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
'ALTER INDEX "schema"."foo" RENAME TO "bar"'
,
);
}
public
function
testGetNullCommentOnColumnSQL
()
{
$this
->
assertEquals
(
"COMMENT ON COLUMN mytable.id IS NULL"
,
$this
->
_platform
->
getCommentOnColumnSQL
(
'mytable'
,
'id'
,
null
)
);
}
}
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