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

fix TRIM expression

parent 7c68e80f
......@@ -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 . ')';
}
/**
......
......@@ -1128,7 +1128,7 @@ class SQLAnywherePlatform extends AbstractPlatform
}
}
$pattern = "'%[^$char]%'";
$pattern = "'%[^' + $char + ']%'";
switch ($pos) {
case self::TRIM_LEADING:
......
......@@ -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')
);
}
......
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