Skip to content

Commit

Permalink
Numerics should be treated the same as strings when compiling the sql
Browse files Browse the repository at this point in the history
  • Loading branch information
Walther Lalk committed Aug 11, 2014
1 parent fe536e0 commit 3b138e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Database/Expression/CaseExpression.php
Expand Up @@ -112,7 +112,7 @@ protected function _addExpressions($conditions, $trueValues) {

if ($trueValue === 'literal') {
$trueValue = $k;
} elseif (is_string($trueValue)) {
} elseif (is_string($trueValue) || is_numeric($trueValue)) {
$trueValue = [
'value' => $trueValue,
'type' => null
Expand Down Expand Up @@ -149,7 +149,7 @@ public function defaultValue($value = null) {
* @return array|string|ExpressionInterface
*/
protected function _parseValue($value) {
if (is_string($value)) {
if (is_string($value) || is_numeric($value)) {
$value = [
'value' => $value,
'type' => null
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Database/Expression/CaseExpressionTest.php
Expand Up @@ -33,13 +33,13 @@ public function testSqlOutput() {
$expr->eq('test', 'true');
$caseExpression = new CaseExpression($expr, 'foobar');

$expected = 'CASE WHEN test = :c0 THEN :c1 ELSE 0 END';
$expected = 'CASE WHEN test = :c0 THEN :c1 ELSE :c2 END';
$this->assertSame($expected, $caseExpression->sql(new ValueBinder()));

$expr2 = new QueryExpression();
$expr2->eq('test2', 'false');
$caseExpression->add($expr2);
$expected = 'CASE WHEN test = :c0 THEN :c1 WHEN test2 = :c2 THEN 1 ELSE 0 END';
$expected = 'CASE WHEN test = :c0 THEN :c1 WHEN test2 = :c2 THEN :c3 ELSE :c4 END';
$this->assertSame($expected, $caseExpression->sql(new ValueBinder()));
}

Expand Down

0 comments on commit 3b138e9

Please sign in to comment.