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 /tests | |
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 'tests')
-rw-r--r-- | tests/lib/DB/QueryBuilder/FunctionBuilderTest.php | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php index 08392b09d8d..0ea6e69c956 100644 --- a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php @@ -501,4 +501,21 @@ 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); + } } |