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
43048d56
Commit
43048d56
authored
Nov 17, 2010
by
Juozas Kaziukenas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed trim expression with char
parent
91e15b7e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
10 deletions
+29
-10
MsSqlPlatform.php
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
+29
-10
No files found.
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
View file @
43048d56
...
...
@@ -439,19 +439,38 @@ class MsSqlPlatform extends AbstractPlatform
*/
public
function
getTrimExpression
(
$str
,
$pos
=
self
::
TRIM_UNSPECIFIED
,
$char
=
false
)
{
// @todo
$trimFn
=
''
;
$trimChar
=
(
$char
!=
false
)
?
(
', '
.
$char
)
:
''
;
if
(
$pos
==
self
::
TRIM_LEADING
)
{
$trimFn
=
'LTRIM'
;
}
else
if
(
$pos
==
self
::
TRIM_TRAILING
)
{
$trimFn
=
'RTRIM'
;
}
else
{
return
'LTRIM(RTRIM('
.
$str
.
'))'
;
}
if
(
!
$char
)
{
if
(
$pos
==
self
::
TRIM_LEADING
)
{
$trimFn
=
'LTRIM'
;
}
else
if
(
$pos
==
self
::
TRIM_TRAILING
)
{
$trimFn
=
'RTRIM'
;
}
else
{
return
'LTRIM(RTRIM('
.
$str
.
'))'
;
}
return
$trimFn
.
'('
.
$str
.
')'
;
return
$trimFn
.
'('
.
$str
.
')'
;
}
else
{
/** Original query used to get those expressions
declare @c varchar(100) = 'xxxBarxxx', @trim_char char(1) = 'x';
declare @pat varchar(10) = '%[^' + @trim_char + ']%';
select @c as string
, @trim_char as trim_char
, stuff(@c, 1, patindex(@pat, @c) - 1, null) as trim_leading
, reverse(stuff(reverse(@c), 1, patindex(@pat, reverse(@c)) - 1, null)) as trim_trailing
, reverse(stuff(reverse(stuff(@c, 1, patindex(@pat, @c) - 1, null)), 1, patindex(@pat, reverse(stuff(@c, 1, patindex(@pat, @c) - 1, null))) - 1, null)) as trim_both;
*/
$pattern
=
"'%[^' +
$char
+ ']%'"
;
if
(
$pos
==
self
::
TRIM_LEADING
)
{
return
'stuff('
.
$str
.
', 1, patindex('
.
$pattern
.
', '
.
$str
.
') - 1, null)'
;
}
else
if
(
$pos
==
self
::
TRIM_TRAILING
)
{
return
'reverse(stuff(reverse('
.
$str
.
'), 1, patindex('
.
$pattern
.
', reverse('
.
$str
.
')) - 1, null))'
;
}
else
{
return
'reverse(stuff(reverse(stuff('
.
$str
.
', 1, patindex('
.
$pattern
.
', '
.
$str
.
') - 1, null)), 1, patindex('
.
$pattern
.
', reverse(stuff('
.
$str
.
', 1, patindex('
.
$pattern
.
', '
.
$str
.
') - 1, null))) - 1, 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