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
4f77e750
Commit
4f77e750
authored
Dec 31, 2011
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DDC-1360 - Add support for quoting dot chained identifiers.
parent
5df86161
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
13 deletions
+57
-13
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+19
-2
MsSqlPlatform.php
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
+2
-10
AbstractPlatformTestCase.php
...octrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
+20
-0
MsSqlPlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/MsSqlPlatformTest.php
+16
-1
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
4f77e750
...
...
@@ -1276,7 +1276,8 @@ abstract class AbstractPlatform
/**
* Quotes a string so that it can be safely used as a table or column name,
* even if it is a reserved word of the platform.
* even if it is a reserved word of the platform. This also detects identifier
* chains seperated by dot and quotes them independently.
*
* NOTE: Just because you CAN use quoted identifiers doesn't mean
* you SHOULD use them. In general, they end up causing way more
...
...
@@ -1286,6 +1287,22 @@ abstract class AbstractPlatform
* @return string quoted identifier string
*/
public
function
quoteIdentifier
(
$str
)
{
if
(
strpos
(
$str
,
"."
)
!==
false
)
{
$parts
=
array_map
(
array
(
$this
,
"quoteIdentifier"
),
explode
(
"."
,
$str
));
return
implode
(
"."
,
$parts
);
}
return
$this
->
quoteSingleIdentifier
(
$str
);
}
/**
* Quote a single identifier (no dot chain seperation)
*
* @param string $str
* @return string
*/
public
function
quoteSingleIdentifier
(
$str
)
{
$c
=
$this
->
getIdentifierQuoteCharacter
();
...
...
@@ -2591,4 +2608,4 @@ abstract class AbstractPlatform
{
throw
DBALException
::
notSupported
(
__METHOD__
);
}
}
\ No newline at end of file
}
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
View file @
4f77e750
...
...
@@ -831,17 +831,9 @@ class MsSqlPlatform extends AbstractPlatform
}
/**
* Quotes a string so that it can be safely used as a table or column name,
* even if it is a reserved word of the platform.
*
* NOTE: Just because you CAN use quoted identifiers doesn't mean
* you SHOULD use them. In general, they end up causing way more
* problems than they solve.
*
* @param string $str identifier name to be quoted
* @return string quoted identifier string
* {@inheritDoc}
*/
public
function
quoteIdentifier
(
$str
)
public
function
quote
Single
Identifier
(
$str
)
{
return
"["
.
str_replace
(
"]"
,
"]["
,
$str
)
.
"]"
;
}
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
View file @
4f77e750
...
...
@@ -19,6 +19,9 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this
->
_platform
=
$this
->
createPlatform
();
}
/**
* @group DDC-1360
*/
public
function
testQuoteIdentifier
()
{
if
(
$this
->
_platform
->
getName
()
==
"mssql"
)
{
...
...
@@ -26,9 +29,26 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
}
$c
=
$this
->
_platform
->
getIdentifierQuoteCharacter
();
$this
->
assertEquals
(
$c
.
"test"
.
$c
,
$this
->
_platform
->
quoteIdentifier
(
"test"
));
$this
->
assertEquals
(
$c
.
"test"
.
$c
.
"."
.
$c
.
"test"
.
$c
,
$this
->
_platform
->
quoteIdentifier
(
"test.test"
));
$this
->
assertEquals
(
str_repeat
(
$c
,
4
),
$this
->
_platform
->
quoteIdentifier
(
$c
));
}
/**
* @group DDC-1360
*/
public
function
testQuoteSingleIdentifier
()
{
if
(
$this
->
_platform
->
getName
()
==
"mssql"
)
{
$this
->
markTestSkipped
(
'Not working this way on mssql.'
);
}
$c
=
$this
->
_platform
->
getIdentifierQuoteCharacter
();
$this
->
assertEquals
(
$c
.
"test"
.
$c
,
$this
->
_platform
->
quoteSingleIdentifier
(
"test"
));
$this
->
assertEquals
(
$c
.
"test.test"
.
$c
,
$this
->
_platform
->
quoteSingleIdentifier
(
"test.test"
));
$this
->
assertEquals
(
str_repeat
(
$c
,
4
),
$this
->
_platform
->
quoteSingleIdentifier
(
$c
));
}
public
function
testGetInvalidtForeignKeyReferentialActionSQL
()
{
$this
->
setExpectedException
(
'InvalidArgumentException'
);
...
...
tests/Doctrine/Tests/DBAL/Platforms/MsSqlPlatformTest.php
View file @
4f77e750
...
...
@@ -171,8 +171,23 @@ class MsSqlPlatformTest extends AbstractPlatformTestCase
$this
->
assertEquals
(
'SELECT TOP 10 * FROM user ORDER BY username DESC'
,
$sql
);
}
/**
* @group DDC-1360
*/
public
function
testQuoteIdentifier
()
{
$this
->
assertEquals
(
'[fo][o]'
,
$this
->
_platform
->
quoteIdentifier
(
'fo]o'
));
$this
->
assertEquals
(
'[test]'
,
$this
->
_platform
->
quoteIdentifier
(
'test'
));
$this
->
assertEquals
(
'[test].[test]'
,
$this
->
_platform
->
quoteIdentifier
(
'test.test'
));
}
}
\ No newline at end of file
/**
* @group DDC-1360
*/
public
function
testQuoteSingleIdentifier
()
{
$this
->
assertEquals
(
'[fo][o]'
,
$this
->
_platform
->
quoteSingleIdentifier
(
'fo]o'
));
$this
->
assertEquals
(
'[test]'
,
$this
->
_platform
->
quoteSingleIdentifier
(
'test'
));
$this
->
assertEquals
(
'[test.test]'
,
$this
->
_platform
->
quoteSingleIdentifier
(
'test.test'
));
}
}
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