diff options
author | Robin Appelman <robin@icewind.nl> | 2022-04-28 15:16:07 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2022-06-02 15:52:12 +0200 |
commit | 2a68819a67045d87a369a8a6413f153b3b2bea5f (patch) | |
tree | 13978f741bb54c603b9085318612c9ea021aaa6c /lib/private/DB | |
parent | 813b50ed428a8bc36817d19c84444e96dbe3b668 (diff) | |
download | nextcloud-server-2a68819a67045d87a369a8a6413f153b3b2bea5f.tar.gz nextcloud-server-2a68819a67045d87a369a8a6413f153b3b2bea5f.zip |
add case statement to sql function builder
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/DB')
-rw-r--r-- | lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php index e0a7549a0ad..408a879d624 100644 --- a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php +++ b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php @@ -121,4 +121,15 @@ class FunctionBuilder implements IFunctionBuilder { public function least($x, $y): IQueryFunction { return new QueryFunction('LEAST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); } + + public function case(array $whens, $else): IQueryFunction { + if (count($whens) < 1) { + return new QueryFunction($this->helper->quoteColumnName($else)); + } + + $whenParts = array_map(function (array $when) { + return 'WHEN ' . $this->helper->quoteColumnName($when['when']) . ' THEN ' . $this->helper->quoteColumnName($when['then']); + }, $whens); + return new QueryFunction('CASE ' . implode(' ', $whenParts) . ' ELSE ' . $this->helper->quoteColumnName($else) . ' END'); + } } |