From 0aab014af1e18e9cd2eb0f146dbc548b676c7271 Mon Sep 17 00:00:00 2001 From: yuri Date: Fri, 15 Feb 2019 12:20:23 +0200 Subject: [PATCH] COALESCE function, null, true, false --- application/Espo/ORM/DB/Query/Base.php | 4 ++++ tests/unit/Espo/ORM/DB/QueryTest.php | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/application/Espo/ORM/DB/Query/Base.php b/application/Espo/ORM/DB/Query/Base.php index 0351407f62..0cd45b2436 100644 --- a/application/Espo/ORM/DB/Query/Base.php +++ b/application/Espo/ORM/DB/Query/Base.php @@ -136,12 +136,14 @@ abstract class Base 'FLOOR', 'CEIL', 'ROUND', + 'COALESCE', ]; protected $multipleArgumentsFunctionList = [ 'CONCAT', 'TZ', 'ROUND', + 'COALESCE', ]; protected $matchFunctionList = ['MATCH_BOOLEAN', 'MATCH_NATURAL_LANGUAGE', 'MATCH_QUERY_EXPANSION']; @@ -582,6 +584,8 @@ abstract class Base } else if (is_numeric($argument)) { $string = $this->quote($argument); return $string; + } else if (in_array(strtoupper($argument), ['NULL', 'TRUE', 'FALSE'])) { + return strtoupper($argument); } if (strpos($argument, ':')) { diff --git a/tests/unit/Espo/ORM/DB/QueryTest.php b/tests/unit/Espo/ORM/DB/QueryTest.php index b2641fba13..db8c6952c4 100644 --- a/tests/unit/Espo/ORM/DB/QueryTest.php +++ b/tests/unit/Espo/ORM/DB/QueryTest.php @@ -593,6 +593,17 @@ class QueryTest extends \PHPUnit\Framework\TestCase $this->assertEquals($expectedSql, $sql); } + public function testFunction9() + { + $sql = $this->query->createSelectQuery('Comment', [ + 'select' => ['id', ["COALESCE:(name,FALSE,true,null)", 'value']] + ]); + $expectedSql = + "SELECT comment.id AS `id`, COALESCE(comment.name, FALSE, TRUE, NULL) AS `value` FROM `comment` " . + "WHERE comment.deleted = '0'"; + $this->assertEquals($expectedSql, $sql); + } + public function testFunctionTZ1() { $sql = $this->query->createSelectQuery('Comment', [