protected function getSelectQuery(string $table): IQueryBuilder {
$qb = $this->dbc->getQueryBuilder();
- $lengthExpr = $this->dbc->getDatabasePlatform()->getLengthExpression('owncloud_name');
$qb->select('owncloud_name', 'directory_uuid')
->from($table)
- ->where($qb->expr()->gt($qb->createFunction($lengthExpr), '64', IQueryBuilder::PARAM_INT));
+ ->where($qb->expr()->gt($qb->func()->octetLength('owncloud_name'), '64', IQueryBuilder::PARAM_INT));
return $qb;
}
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) . ')');
}
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);
+ }
}
*/
public function count($count = '', $alias = ''): IQueryFunction;
+ /**
+ * @param string|ILiteral|IParameter|IQueryFunction $field The input to be measured
+ * @param string $alias Alias for the length
+ *
+ * @return IQueryFunction
+ * @since 24.0.0
+ */
+ public function octetLength($field, $alias = ''): IQueryFunction;
+
+ /**
+ * @param string|ILiteral|IParameter|IQueryFunction $field The input to be measured
+ * @param string $alias Alias for the length
+ *
+ * @return IQueryFunction
+ * @since 24.0.0
+ */
+ public function charLength($field, $alias = ''): IQueryFunction;
+
/**
* Takes the maximum of all rows in a column
*
$this->assertGreaterThan(1, $column);
}
+ public function octetLengthProvider() {
+ return [
+ ['', 0],
+ ['foobar', 6],
+ ['fé', 3],
+ ['šđčćž', 10],
+ ];
+ }
+
+ /**
+ * @dataProvider octetLengthProvider
+ */
+ public function testOctetLength(string $str, int $bytes) {
+ $query = $this->connection->getQueryBuilder();
+
+ $query->select($query->func()->octetLength($query->createNamedParameter($str, IQueryBuilder::PARAM_STR)));
+
+ $result = $query->execute();
+ $column = $result->fetchOne();
+ $result->closeCursor();
+ $this->assertEquals($bytes, $column);
+ }
+
+ public function charLengthProvider() {
+ return [
+ ['', 0],
+ ['foobar', 6],
+ ['fé', 2],
+ ['šđčćž', 5],
+ ];
+ }
+
+ /**
+ * @dataProvider charLengthProvider
+ */
+ public function testCharLength(string $str, int $bytes) {
+ $query = $this->connection->getQueryBuilder();
+
+ $query->select($query->func()->charLength($query->createNamedParameter($str, IQueryBuilder::PARAM_STR)));
+
+ $result = $query->execute();
+ $column = $result->fetchOne();
+ $result->closeCursor();
+ $this->assertEquals($bytes, $column);
+ }
+
private function setUpMinMax($value) {
$query = $this->connection->getQueryBuilder();