summaryrefslogtreecommitdiffstats
path: root/lib/private/DB/QueryBuilder
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2022-03-24 16:17:37 +0100
committerVincent Petry (Rebase PR Action) <PVince81@users.noreply.github.com>2022-03-24 20:35:02 +0000
commitefebbacca4d5a5045271eeecd209c8a0b4253598 (patch)
treee9e7d33b8ca9ec8f9fb5c287e31f317d2c94435e /lib/private/DB/QueryBuilder
parent7dc3eb1e9e9a2cf6b52dc17986b4bbca395f0998 (diff)
downloadnextcloud-server-efebbacca4d5a5045271eeecd209c8a0b4253598.tar.gz
nextcloud-server-efebbacca4d5a5045271eeecd209c8a0b4253598.zip
Add octetLength and charLength to function builder, and tests
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib/private/DB/QueryBuilder')
-rw-r--r--lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php12
-rw-r--r--lib/private/DB/QueryBuilder/FunctionBuilder/SqliteFunctionBuilder.php6
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php
index 03630ea14a3..c0f07d37406 100644
--- a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php
+++ b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php
@@ -94,6 +94,18 @@ class FunctionBuilder implements IFunctionBuilder {
return new QueryFunction('COUNT(' . $quotedName . ')' . $alias);
}
+ public function octetLength($field, $alias = ''): IQueryFunction {
+ $alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
+ $quotedName = $this->helper->quoteColumnName($field);
+ return new QueryFunction('LENGTHB(' . $quotedName . ')' . $alias);
+ }
+
+ public function charLength($field, $alias = ''): IQueryFunction {
+ $alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
+ $quotedName = $this->helper->quoteColumnName($field);
+ return new QueryFunction('LENGTH(' . $quotedName . ')' . $alias);
+ }
+
public function max($field): IQueryFunction {
return new QueryFunction('MAX(' . $this->helper->quoteColumnName($field) . ')');
}
diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/SqliteFunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/SqliteFunctionBuilder.php
index fe700075a82..4e9e83a49d2 100644
--- a/lib/private/DB/QueryBuilder/FunctionBuilder/SqliteFunctionBuilder.php
+++ b/lib/private/DB/QueryBuilder/FunctionBuilder/SqliteFunctionBuilder.php
@@ -48,4 +48,10 @@ class SqliteFunctionBuilder extends FunctionBuilder {
public function least($x, $y): IQueryFunction {
return new QueryFunction('MIN(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
}
+
+ public function octetLength($field, $alias = ''): IQueryFunction {
+ $alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
+ $quotedName = $this->helper->quoteColumnName($field);
+ return new QueryFunction('LENGTH(CAST(' . $quotedName . ' as BLOB))' . $alias);
+ }
}