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
3986daf9
Commit
3986daf9
authored
Mar 31, 2014
by
Guilherme Blanco
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #562 from deeky666/fix-sqlanywhere-trim-expression
Fix TRIM expression
parents
7c68e80f
eea57019
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
11 deletions
+78
-11
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+13
-6
SQLAnywherePlatform.php
lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
+1
-1
DataAccessTest.php
tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
+58
-0
SQLAnywherePlatformTest.php
...Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php
+6
-4
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
3986daf9
...
...
@@ -724,24 +724,31 @@ abstract class AbstractPlatform
*/
public
function
getTrimExpression
(
$str
,
$pos
=
self
::
TRIM_UNSPECIFIED
,
$char
=
false
)
{
$posStr
=
''
;
$trimChar
=
(
$char
!=
false
)
?
$char
.
' FROM '
:
''
;
$expression
=
''
;
switch
(
$pos
)
{
case
self
::
TRIM_LEADING
:
$
posStr
=
'LEADING '
.
$trimChar
;
$
expression
=
'LEADING '
;
break
;
case
self
::
TRIM_TRAILING
:
$
posStr
=
'TRAILING '
.
$trimChar
;
$
expression
=
'TRAILING '
;
break
;
case
self
::
TRIM_BOTH
:
$
posStr
=
'BOTH '
.
$trimChar
;
$
expression
=
'BOTH '
;
break
;
}
return
'TRIM('
.
$posStr
.
$str
.
')'
;
if
(
false
!==
$char
)
{
$expression
.=
$char
.
' '
;
}
if
(
$pos
||
false
!==
$char
)
{
$expression
.=
'FROM '
;
}
return
'TRIM('
.
$expression
.
$str
.
')'
;
}
/**
...
...
lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
View file @
3986daf9
...
...
@@ -1128,7 +1128,7 @@ class SQLAnywherePlatform extends AbstractPlatform
}
}
$pattern
=
"'%[^
$char
]%'"
;
$pattern
=
"'%[^
' +
$char
+ '
]%'"
;
switch
(
$pos
)
{
case
self
::
TRIM_LEADING
:
...
...
tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
View file @
3986daf9
...
...
@@ -2,6 +2,7 @@
namespace
Doctrine\Tests\DBAL\Functional
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Connection
;
use
PDO
;
...
...
@@ -435,6 +436,63 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this
->
assertEquals
(
array
(
array
(
100
),
array
(
101
),
array
(
102
),
array
(
103
),
array
(
104
)),
$data
);
}
/**
* @dataProvider getTrimExpressionData
*/
public
function
testTrimExpression
(
$value
,
$position
,
$char
,
$expectedResult
)
{
$sql
=
'SELECT '
.
$this
->
_conn
->
getDatabasePlatform
()
->
getTrimExpression
(
$value
,
$position
,
$char
)
.
' AS trimmed '
.
'FROM fetch_table'
;
$row
=
$this
->
_conn
->
fetchAssoc
(
$sql
);
$row
=
array_change_key_case
(
$row
,
CASE_LOWER
);
$this
->
assertEquals
(
$expectedResult
,
$row
[
'trimmed'
]);
}
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'
),
);
}
/**
* @group DDC-1014
*/
...
...
tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php
View file @
3986daf9
...
...
@@ -568,19 +568,21 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
$this
->
_platform
->
getTrimExpression
(
'column'
,
AbstractPlatform
::
TRIM_UNSPECIFIED
)
);
$this
->
assertEquals
(
"SUBSTR(column, PATINDEX('%[^
c
]%', column))"
,
"SUBSTR(column, PATINDEX('%[^
' + c + '
]%', column))"
,
$this
->
_platform
->
getTrimExpression
(
'column'
,
AbstractPlatform
::
TRIM_LEADING
,
'c'
)
);
$this
->
assertEquals
(
"REVERSE(SUBSTR(REVERSE(column), PATINDEX('%[^
c
]%', REVERSE(column))))"
,
"REVERSE(SUBSTR(REVERSE(column), PATINDEX('%[^
' + c + '
]%', REVERSE(column))))"
,
$this
->
_platform
->
getTrimExpression
(
'column'
,
AbstractPlatform
::
TRIM_TRAILING
,
'c'
)
);
$this
->
assertEquals
(
"REVERSE(SUBSTR(REVERSE(SUBSTR(column, PATINDEX('%[^c]%', column))), PATINDEX('%[^c]%', REVERSE(SUBSTR(column, PATINDEX('%[^c]%', column))))))"
,
"REVERSE(SUBSTR(REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))), PATINDEX('%[^' + c + ']%', "
.
"REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))))))"
,
$this
->
_platform
->
getTrimExpression
(
'column'
,
null
,
'c'
)
);
$this
->
assertEquals
(
"REVERSE(SUBSTR(REVERSE(SUBSTR(column, PATINDEX('%[^c]%', column))), PATINDEX('%[^c]%', REVERSE(SUBSTR(column, PATINDEX('%[^c]%', column))))))"
,
"REVERSE(SUBSTR(REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))), PATINDEX('%[^' + c + ']%', "
.
"REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))))))"
,
$this
->
_platform
->
getTrimExpression
(
'column'
,
AbstractPlatform
::
TRIM_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