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
e6260dc6
Unverified
Commit
e6260dc6
authored
Jan 27, 2018
by
Michael Moravec
Committed by
Marco Pivetta
Jan 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract AbstractPlatform::TRIM_* constants into TrimMode class
parent
45b57743
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
103 additions
and
69 deletions
+103
-69
UPGRADE.md
UPGRADE.md
+4
-0
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+22
-14
SQLAnywherePlatform.php
lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
+5
-5
SQLServerPlatform.php
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
+5
-5
SqlitePlatform.php
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
+3
-3
TrimMode.php
lib/Doctrine/DBAL/Platforms/TrimMode.php
+20
-0
DataAccessTest.php
tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
+37
-36
SQLAnywherePlatformTest.php
...Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php
+7
-6
No files found.
UPGRADE.md
View file @
e6260dc6
# Upgrade to 2.7
## Doctrine\DBAL\Platforms\AbstractPlatform::TRIM_* constants deprecated
``Doctrine\DBAL\Platforms\AbstractPlatform::TRIM_*``
constants were moved into
``Doctrine\DBAL\Platforms\TrimMode``
class without the
``TRIM_``
prefix.
## Doctrine\DBAL\Connection::TRANSACTION_* constants deprecated
``Doctrine\DBAL\Connection::TRANSACTION_*``
were moved into
``Doctrine\DBAL\TransactionIsolationLevel``
class without the
``TRANSACTION_``
prefix.
...
...
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
e6260dc6
...
...
@@ -111,23 +111,31 @@ abstract class AbstractPlatform
/**
* @var int
*
* @deprecated Use TrimMode::UNSPECIFIED.
*/
const
TRIM_UNSPECIFIED
=
0
;
public
const
TRIM_UNSPECIFIED
=
TrimMode
::
UNSPECIFIED
;
/**
* @var int
*
* @deprecated Use TrimMode::LEADING.
*/
const
TRIM_LEADING
=
1
;
public
const
TRIM_LEADING
=
TrimMode
::
LEADING
;
/**
* @var int
*
* @deprecated Use TrimMode::TRAILING.
*/
const
TRIM_TRAILING
=
2
;
public
const
TRIM_TRAILING
=
TrimMode
::
TRAILING
;
/**
* @var int
*
* @deprecated Use TrimMode::BOTH.
*/
const
TRIM_BOTH
=
3
;
public
const
TRIM_BOTH
=
TrimMode
::
BOTH
;
/**
* @var array|null
...
...
@@ -766,34 +774,34 @@ abstract class AbstractPlatform
* Returns the SQL snippet to trim a string.
*
* @param string $str The expression to apply the trim to.
* @param int
$pos
The position of the trim (leading/trailing/both).
* @param string|bool
ean
$char The char to trim, has to be quoted already. Defaults to space.
* @param int
$mode
The position of the trim (leading/trailing/both).
* @param string|bool $char The char to trim, has to be quoted already. Defaults to space.
*
* @return string
*/
public
function
getTrimExpression
(
$str
,
$
pos
=
self
::
TRIM_
UNSPECIFIED
,
$char
=
false
)
public
function
getTrimExpression
(
$str
,
$
mode
=
TrimMode
::
UNSPECIFIED
,
$char
=
false
)
{
$expression
=
''
;
switch
(
$
pos
)
{
case
self
::
TRIM_
LEADING
:
switch
(
$
mode
)
{
case
TrimMode
::
LEADING
:
$expression
=
'LEADING '
;
break
;
case
self
::
TRIM_
TRAILING
:
case
TrimMode
::
TRAILING
:
$expression
=
'TRAILING '
;
break
;
case
self
::
TRIM_
BOTH
:
case
TrimMode
::
BOTH
:
$expression
=
'BOTH '
;
break
;
}
if
(
false
!==
$char
)
{
if
(
$char
!==
false
)
{
$expression
.=
$char
.
' '
;
}
if
(
$
pos
||
false
!==
$char
)
{
if
(
$
mode
||
$char
!==
false
)
{
$expression
.=
'FROM '
;
}
...
...
lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
View file @
e6260dc6
...
...
@@ -1103,13 +1103,13 @@ class SQLAnywherePlatform extends AbstractPlatform
/**
* {@inheritdoc}
*/
public
function
getTrimExpression
(
$str
,
$pos
=
self
::
TRIM_
UNSPECIFIED
,
$char
=
false
)
public
function
getTrimExpression
(
$str
,
$pos
=
TrimMode
::
UNSPECIFIED
,
$char
=
false
)
{
if
(
!
$char
)
{
switch
(
$pos
)
{
case
self
::
TRIM_
LEADING
:
case
TrimMode
::
LEADING
:
return
$this
->
getLtrimExpression
(
$str
);
case
self
::
TRIM_
TRAILING
:
case
TrimMode
::
TRAILING
:
return
$this
->
getRtrimExpression
(
$str
);
default
:
return
'TRIM('
.
$str
.
')'
;
...
...
@@ -1119,9 +1119,9 @@ class SQLAnywherePlatform extends AbstractPlatform
$pattern
=
"'%[^' +
$char
+ ']%'"
;
switch
(
$pos
)
{
case
self
::
TRIM_
LEADING
:
case
TrimMode
::
LEADING
:
return
'SUBSTR('
.
$str
.
', PATINDEX('
.
$pattern
.
', '
.
$str
.
'))'
;
case
self
::
TRIM_
TRAILING
:
case
TrimMode
::
TRAILING
:
return
'REVERSE(SUBSTR(REVERSE('
.
$str
.
'), PATINDEX('
.
$pattern
.
', REVERSE('
.
$str
.
'))))'
;
default
:
return
...
...
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
View file @
e6260dc6
...
...
@@ -1003,15 +1003,15 @@ class SQLServerPlatform extends AbstractPlatform
/**
* {@inheritDoc}
*/
public
function
getTrimExpression
(
$str
,
$pos
=
self
::
TRIM_
UNSPECIFIED
,
$char
=
false
)
public
function
getTrimExpression
(
$str
,
$pos
=
TrimMode
::
UNSPECIFIED
,
$char
=
false
)
{
if
(
!
$char
)
{
switch
(
$pos
)
{
case
self
::
TRIM_
LEADING
:
case
TrimMode
::
LEADING
:
$trimFn
=
'LTRIM'
;
break
;
case
self
::
TRIM_
TRAILING
:
case
TrimMode
::
TRAILING
:
$trimFn
=
'RTRIM'
;
break
;
...
...
@@ -1033,11 +1033,11 @@ class SQLServerPlatform extends AbstractPlatform
*/
$pattern
=
"'%[^' +
$char
+ ']%'"
;
if
(
$pos
==
self
::
TRIM_
LEADING
)
{
if
(
$pos
==
=
TrimMode
::
LEADING
)
{
return
'stuff('
.
$str
.
', 1, patindex('
.
$pattern
.
', '
.
$str
.
') - 1, null)'
;
}
if
(
$pos
==
self
::
TRIM_
TRAILING
)
{
if
(
$pos
==
=
TrimMode
::
TRAILING
)
{
return
'reverse(stuff(reverse('
.
$str
.
'), 1, patindex('
.
$pattern
.
', reverse('
.
$str
.
')) - 1, null))'
;
}
...
...
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
View file @
e6260dc6
...
...
@@ -80,16 +80,16 @@ class SqlitePlatform extends AbstractPlatform
/**
* {@inheritDoc}
*/
public
function
getTrimExpression
(
$str
,
$pos
=
self
::
TRIM_
UNSPECIFIED
,
$char
=
false
)
public
function
getTrimExpression
(
$str
,
$pos
=
TrimMode
::
UNSPECIFIED
,
$char
=
false
)
{
$trimChar
=
(
$char
!=
false
)
?
(
', '
.
$char
)
:
''
;
switch
(
$pos
)
{
case
self
::
TRIM_
LEADING
:
case
TrimMode
::
LEADING
:
$trimFn
=
'LTRIM'
;
break
;
case
self
::
TRIM_
TRAILING
:
case
TrimMode
::
TRAILING
:
$trimFn
=
'RTRIM'
;
break
;
...
...
lib/Doctrine/DBAL/Platforms/TrimMode.php
0 → 100644
View file @
e6260dc6
<?php
declare
(
strict_types
=
1
);
namespace
Doctrine\DBAL\Platforms
;
final
class
TrimMode
{
public
const
UNSPECIFIED
=
0
;
public
const
LEADING
=
1
;
public
const
TRAILING
=
2
;
public
const
BOTH
=
3
;
private
function
__construct
()
{
}
}
tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
View file @
e6260dc6
...
...
@@ -4,6 +4,7 @@ namespace Doctrine\Tests\DBAL\Functional;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Platforms\TrimMode
;
use
Doctrine\DBAL\Types\Type
;
use
PDO
;
...
...
@@ -459,42 +460,42 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
public
function
getTrimExpressionData
()
{
return
array
(
array
(
'test_string'
,
AbstractPlatform
::
TRIM_UNSPECIFIED
,
false
,
'foo'
)
,
array
(
'test_string'
,
AbstractPlatform
::
TRIM_LEADING
,
false
,
'foo'
)
,
array
(
'test_string'
,
AbstractPlatform
::
TRIM_TRAILING
,
false
,
'foo'
)
,
array
(
'test_string'
,
AbstractPlatform
::
TRIM_BOTH
,
false
,
'foo'
)
,
array
(
'test_string'
,
AbstractPlatform
::
TRIM_UNSPECIFIED
,
"'f'"
,
'oo'
)
,
array
(
'test_string'
,
AbstractPlatform
::
TRIM_UNSPECIFIED
,
"'o'"
,
'f'
)
,
array
(
'test_string'
,
AbstractPlatform
::
TRIM_UNSPECIFIED
,
"'.'"
,
'foo'
)
,
array
(
'test_string'
,
AbstractPlatform
::
TRIM_LEADING
,
"'f'"
,
'oo'
)
,
array
(
'test_string'
,
AbstractPlatform
::
TRIM_LEADING
,
"'o'"
,
'foo'
)
,
array
(
'test_string'
,
AbstractPlatform
::
TRIM_LEADING
,
"'.'"
,
'foo'
)
,
array
(
'test_string'
,
AbstractPlatform
::
TRIM_TRAILING
,
"'f'"
,
'foo'
)
,
array
(
'test_string'
,
AbstractPlatform
::
TRIM_TRAILING
,
"'o'"
,
'f'
)
,
array
(
'test_string'
,
AbstractPlatform
::
TRIM_TRAILING
,
"'.'"
,
'foo'
)
,
array
(
'test_string'
,
AbstractPlatform
::
TRIM_BOTH
,
"'f'"
,
'oo'
)
,
array
(
'test_string'
,
AbstractPlatform
::
TRIM_BOTH
,
"'o'"
,
'f'
)
,
array
(
'test_string'
,
AbstractPlatform
::
TRIM_BOTH
,
"'.'"
,
'foo'
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_UNSPECIFIED
,
false
,
'foo'
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_LEADING
,
false
,
'foo '
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_TRAILING
,
false
,
' foo'
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_BOTH
,
false
,
'foo'
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_UNSPECIFIED
,
"'f'"
,
' foo '
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_UNSPECIFIED
,
"'o'"
,
' foo '
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_UNSPECIFIED
,
"'.'"
,
' foo '
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_UNSPECIFIED
,
"' '"
,
'foo'
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_LEADING
,
"'f'"
,
' foo '
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_LEADING
,
"'o'"
,
' foo '
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_LEADING
,
"'.'"
,
' foo '
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_LEADING
,
"' '"
,
'foo '
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_TRAILING
,
"'f'"
,
' foo '
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_TRAILING
,
"'o'"
,
' foo '
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_TRAILING
,
"'.'"
,
' foo '
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_TRAILING
,
"' '"
,
' foo'
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_BOTH
,
"'f'"
,
' foo '
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_BOTH
,
"'o'"
,
' foo '
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_BOTH
,
"'.'"
,
' foo '
)
,
array
(
"' foo '"
,
AbstractPlatform
::
TRIM_BOTH
,
"' '"
,
'foo'
)
,
[
'test_string'
,
TrimMode
::
UNSPECIFIED
,
false
,
'foo'
]
,
[
'test_string'
,
TrimMode
::
LEADING
,
false
,
'foo'
]
,
[
'test_string'
,
TrimMode
::
TRAILING
,
false
,
'foo'
]
,
[
'test_string'
,
TrimMode
::
BOTH
,
false
,
'foo'
]
,
[
'test_string'
,
TrimMode
::
UNSPECIFIED
,
"'f'"
,
'oo'
]
,
[
'test_string'
,
TrimMode
::
UNSPECIFIED
,
"'o'"
,
'f'
]
,
[
'test_string'
,
TrimMode
::
UNSPECIFIED
,
"'.'"
,
'foo'
]
,
[
'test_string'
,
TrimMode
::
LEADING
,
"'f'"
,
'oo'
]
,
[
'test_string'
,
TrimMode
::
LEADING
,
"'o'"
,
'foo'
]
,
[
'test_string'
,
TrimMode
::
LEADING
,
"'.'"
,
'foo'
]
,
[
'test_string'
,
TrimMode
::
TRAILING
,
"'f'"
,
'foo'
]
,
[
'test_string'
,
TrimMode
::
TRAILING
,
"'o'"
,
'f'
]
,
[
'test_string'
,
TrimMode
::
TRAILING
,
"'.'"
,
'foo'
]
,
[
'test_string'
,
TrimMode
::
BOTH
,
"'f'"
,
'oo'
]
,
[
'test_string'
,
TrimMode
::
BOTH
,
"'o'"
,
'f'
]
,
[
'test_string'
,
TrimMode
::
BOTH
,
"'.'"
,
'foo'
]
,
[
"' foo '"
,
TrimMode
::
UNSPECIFIED
,
false
,
'foo'
]
,
[
"' foo '"
,
TrimMode
::
LEADING
,
false
,
'foo '
]
,
[
"' foo '"
,
TrimMode
::
TRAILING
,
false
,
' foo'
]
,
[
"' foo '"
,
TrimMode
::
BOTH
,
false
,
'foo'
]
,
[
"' foo '"
,
TrimMode
::
UNSPECIFIED
,
"'f'"
,
' foo '
]
,
[
"' foo '"
,
TrimMode
::
UNSPECIFIED
,
"'o'"
,
' foo '
]
,
[
"' foo '"
,
TrimMode
::
UNSPECIFIED
,
"'.'"
,
' foo '
]
,
[
"' foo '"
,
TrimMode
::
UNSPECIFIED
,
"' '"
,
'foo'
]
,
[
"' foo '"
,
TrimMode
::
LEADING
,
"'f'"
,
' foo '
]
,
[
"' foo '"
,
TrimMode
::
LEADING
,
"'o'"
,
' foo '
]
,
[
"' foo '"
,
TrimMode
::
LEADING
,
"'.'"
,
' foo '
]
,
[
"' foo '"
,
TrimMode
::
LEADING
,
"' '"
,
'foo '
]
,
[
"' foo '"
,
TrimMode
::
TRAILING
,
"'f'"
,
' foo '
]
,
[
"' foo '"
,
TrimMode
::
TRAILING
,
"'o'"
,
' foo '
]
,
[
"' foo '"
,
TrimMode
::
TRAILING
,
"'.'"
,
' foo '
]
,
[
"' foo '"
,
TrimMode
::
TRAILING
,
"' '"
,
' foo'
]
,
[
"' foo '"
,
TrimMode
::
BOTH
,
"'f'"
,
' foo '
]
,
[
"' foo '"
,
TrimMode
::
BOTH
,
"'o'"
,
' foo '
]
,
[
"' foo '"
,
TrimMode
::
BOTH
,
"'.'"
,
' foo '
]
,
[
"' foo '"
,
TrimMode
::
BOTH
,
"' '"
,
'foo'
]
,
);
}
...
...
tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php
View file @
e6260dc6
...
...
@@ -6,6 +6,7 @@ use Doctrine\DBAL\Connection;
use
Doctrine\DBAL\LockMode
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Platforms\SQLAnywherePlatform
;
use
Doctrine\DBAL\Platforms\TrimMode
;
use
Doctrine\DBAL\Schema\Column
;
use
Doctrine\DBAL\Schema\ColumnDiff
;
use
Doctrine\DBAL\Schema\Comparator
;
...
...
@@ -550,11 +551,11 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
self
::
assertEquals
(
'GLOBAL TEMPORARY'
,
$this
->
_platform
->
getTemporaryTableSQL
());
self
::
assertEquals
(
'LTRIM(column)'
,
$this
->
_platform
->
getTrimExpression
(
'column'
,
AbstractPlatform
::
TRIM_
LEADING
)
$this
->
_platform
->
getTrimExpression
(
'column'
,
TrimMode
::
LEADING
)
);
self
::
assertEquals
(
'RTRIM(column)'
,
$this
->
_platform
->
getTrimExpression
(
'column'
,
AbstractPlatform
::
TRIM_
TRAILING
)
$this
->
_platform
->
getTrimExpression
(
'column'
,
TrimMode
::
TRAILING
)
);
self
::
assertEquals
(
'TRIM(column)'
,
...
...
@@ -562,15 +563,15 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
);
self
::
assertEquals
(
'TRIM(column)'
,
$this
->
_platform
->
getTrimExpression
(
'column'
,
AbstractPlatform
::
TRIM_
UNSPECIFIED
)
$this
->
_platform
->
getTrimExpression
(
'column'
,
TrimMode
::
UNSPECIFIED
)
);
self
::
assertEquals
(
"SUBSTR(column, PATINDEX('%[^' + c + ']%', column))"
,
$this
->
_platform
->
getTrimExpression
(
'column'
,
AbstractPlatform
::
TRIM_
LEADING
,
'c'
)
$this
->
_platform
->
getTrimExpression
(
'column'
,
TrimMode
::
LEADING
,
'c'
)
);
self
::
assertEquals
(
"REVERSE(SUBSTR(REVERSE(column), PATINDEX('%[^' + c + ']%', REVERSE(column))))"
,
$this
->
_platform
->
getTrimExpression
(
'column'
,
AbstractPlatform
::
TRIM_
TRAILING
,
'c'
)
$this
->
_platform
->
getTrimExpression
(
'column'
,
TrimMode
::
TRAILING
,
'c'
)
);
self
::
assertEquals
(
"REVERSE(SUBSTR(REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))), PATINDEX('%[^' + c + ']%', "
.
...
...
@@ -580,7 +581,7 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
self
::
assertEquals
(
"REVERSE(SUBSTR(REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))), PATINDEX('%[^' + c + ']%', "
.
"REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))))))"
,
$this
->
_platform
->
getTrimExpression
(
'column'
,
AbstractPlatform
::
TRIM_
UNSPECIFIED
,
'c'
)
$this
->
_platform
->
getTrimExpression
(
'column'
,
TrimMode
::
UNSPECIFIED
,
'c'
)
);
}
...
...
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