mirror of
https://github.com/nextcloud/server.git
synced 2026-04-21 06:08:46 -04:00
Revert "add case statement to sql function builder"
This reverts commit 2a68819a67.
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
9b52663a81
commit
6e0123a1d0
3 changed files with 0 additions and 40 deletions
|
|
@ -121,15 +121,4 @@ 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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -188,16 +188,4 @@ interface IFunctionBuilder {
|
|||
* @since 18.0.0
|
||||
*/
|
||||
public function least($x, $y): IQueryFunction;
|
||||
|
||||
/**
|
||||
* Takes the minimum of multiple values
|
||||
*
|
||||
* If you want to get the minimum value of all rows in a column, use `min` instead
|
||||
*
|
||||
* @param array<array{"when": string|ILiteral|IParameter|IQueryFunction, "then": string|ILiteral|IParameter|IQueryFunction}> $whens
|
||||
* @param string|ILiteral|IParameter|IQueryFunction $else
|
||||
* @return IQueryFunction
|
||||
* @since 18.0.0
|
||||
*/
|
||||
public function case(array $whens, $else): IQueryFunction;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -501,21 +501,4 @@ class FunctionBuilderTest extends TestCase {
|
|||
$result->closeCursor();
|
||||
$this->assertEquals(1, $row);
|
||||
}
|
||||
|
||||
public function testCase() {
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
|
||||
$query->select($query->func()->case([
|
||||
['when' => $query->expr()->gt($query->expr()->literal(1, IQueryBuilder::PARAM_INT), $query->expr()->literal(2, IQueryBuilder::PARAM_INT)), 'then' => $query->expr()->literal('first')],
|
||||
['when' => $query->expr()->lt($query->expr()->literal(1, IQueryBuilder::PARAM_INT), $query->expr()->literal(2, IQueryBuilder::PARAM_INT)), 'then' => $query->expr()->literal('second')],
|
||||
['when' => $query->expr()->eq($query->expr()->literal(1, IQueryBuilder::PARAM_INT), $query->expr()->literal(2, IQueryBuilder::PARAM_INT)), 'then' => $query->expr()->literal('third')],
|
||||
], $query->createNamedParameter('else')));
|
||||
$query->from('appconfig')
|
||||
->setMaxResults(1);
|
||||
|
||||
$result = $query->execute();
|
||||
$row = $result->fetchOne();
|
||||
$result->closeCursor();
|
||||
$this->assertEquals('second', $row);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue