Commit db36902a authored by Steve Müller's avatar Steve Müller

fix TRIM expression

parent 7c68e80f
...@@ -724,24 +724,31 @@ abstract class AbstractPlatform ...@@ -724,24 +724,31 @@ abstract class AbstractPlatform
*/ */
public function getTrimExpression($str, $pos = self::TRIM_UNSPECIFIED, $char = false) public function getTrimExpression($str, $pos = self::TRIM_UNSPECIFIED, $char = false)
{ {
$posStr = ''; $expression = '';
$trimChar = ($char != false) ? $char . ' FROM ' : '';
switch ($pos) { switch ($pos) {
case self::TRIM_LEADING: case self::TRIM_LEADING:
$posStr = 'LEADING '.$trimChar; $expression = 'LEADING ';
break; break;
case self::TRIM_TRAILING: case self::TRIM_TRAILING:
$posStr = 'TRAILING '.$trimChar; $expression = 'TRAILING ';
break; break;
case self::TRIM_BOTH: case self::TRIM_BOTH:
$posStr = 'BOTH '.$trimChar; $expression = 'BOTH ';
break; break;
} }
return 'TRIM(' . $posStr . $str . ')'; if (false !== $char) {
$expression .= $char . ' ';
}
if ($pos || false !== $char) {
$expression .= 'FROM ';
}
return 'TRIM(' . $expression . $str . ')';
} }
/** /**
......
...@@ -1128,7 +1128,7 @@ class SQLAnywherePlatform extends AbstractPlatform ...@@ -1128,7 +1128,7 @@ class SQLAnywherePlatform extends AbstractPlatform
} }
} }
$pattern = "'%[^$char]%'"; $pattern = "'%[^' + $char + ']%'";
switch ($pos) { switch ($pos) {
case self::TRIM_LEADING: case self::TRIM_LEADING:
......
...@@ -568,19 +568,21 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase ...@@ -568,19 +568,21 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
$this->_platform->getTrimExpression('column', AbstractPlatform::TRIM_UNSPECIFIED) $this->_platform->getTrimExpression('column', AbstractPlatform::TRIM_UNSPECIFIED)
); );
$this->assertEquals( $this->assertEquals(
"SUBSTR(column, PATINDEX('%[^c]%', column))", "SUBSTR(column, PATINDEX('%[^' + c + ']%', column))",
$this->_platform->getTrimExpression('column', AbstractPlatform::TRIM_LEADING, 'c') $this->_platform->getTrimExpression('column', AbstractPlatform::TRIM_LEADING, 'c')
); );
$this->assertEquals( $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->_platform->getTrimExpression('column', AbstractPlatform::TRIM_TRAILING, 'c')
); );
$this->assertEquals( $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->_platform->getTrimExpression('column', null, 'c')
); );
$this->assertEquals( $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') $this->_platform->getTrimExpression('column', AbstractPlatform::TRIM_UNSPECIFIED, 'c')
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment