Add a method to compare empty strings with an expression

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2017-07-25 15:34:59 +02:00
parent 100fe07f5d
commit 78412fda9c
No known key found for this signature in database
GPG key ID: E166FD8976B3BAC8
4 changed files with 64 additions and 1 deletions

View file

@ -31,6 +31,7 @@ use OC\DB\QueryBuilder\QueryFunction;
use OC\DB\QueryBuilder\QuoteHelper; use OC\DB\QueryBuilder\QuoteHelper;
use OCP\DB\QueryBuilder\IExpressionBuilder; use OCP\DB\QueryBuilder\IExpressionBuilder;
use OCP\DB\QueryBuilder\ILiteral; use OCP\DB\QueryBuilder\ILiteral;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction; use OCP\DB\QueryBuilder\IQueryFunction;
use OCP\IDBConnection; use OCP\IDBConnection;
@ -350,6 +351,28 @@ class ExpressionBuilder implements IExpressionBuilder {
return $this->expressionBuilder->notIn($x, $y); return $this->expressionBuilder->notIn($x, $y);
} }
/**
* Creates a $x = '' statement, because Oracle needs a different check
*
* @param string $x The field in string format to be inspected by the comparison.
* @return string
* @since 13.0.0
*/
public function emptyString($x) {
return $this->eq($x, $this->literal('', IQueryBuilder::PARAM_STR));
}
/**
* Creates a `$x <> ''` statement, because Oracle needs a different check
*
* @param string $x The field in string format to be inspected by the comparison.
* @return string
* @since 13.0.0
*/
public function nonEmptyString($x) {
return $this->neq($x, $this->literal('', IQueryBuilder::PARAM_STR));
}
/** /**
* Binary AND Operator copies a bit to the result if it exists in both operands. * Binary AND Operator copies a bit to the result if it exists in both operands.
* *

View file

@ -137,6 +137,28 @@ class OCIExpressionBuilder extends ExpressionBuilder {
return $this->expressionBuilder->notIn($x, $y); return $this->expressionBuilder->notIn($x, $y);
} }
/**
* Creates a $x = '' statement, because Oracle needs a different check
*
* @param string $x The field in string format to be inspected by the comparison.
* @return string
* @since 13.0.0
*/
public function emptyString($x) {
return $this->isNull($x);
}
/**
* Creates a `$x <> ''` statement, because Oracle needs a different check
*
* @param string $x The field in string format to be inspected by the comparison.
* @return string
* @since 13.0.0
*/
public function nonEmptyString($x) {
return $this->isNotNull($x);
}
/** /**
* Returns a IQueryFunction that casts the column to the given type * Returns a IQueryFunction that casts the column to the given type
* *

View file

@ -70,7 +70,7 @@ class RepairInvalidPaths implements IRepairStep {
->from('filecache', 'f') ->from('filecache', 'f')
->innerJoin('f', 'filecache', 'p', $builder->expr()->andX( ->innerJoin('f', 'filecache', 'p', $builder->expr()->andX(
$builder->expr()->eq('f.parent', 'p.fileid'), $builder->expr()->eq('f.parent', 'p.fileid'),
$builder->expr()->isNotNull('p.name') $builder->expr()->nonEmptyString('p.name')
)) ))
->where($builder->expr()->neq('f.path', $computedPath)) ->where($builder->expr()->neq('f.path', $computedPath))
->setMaxResults(self::MAX_ROWS); ->setMaxResults(self::MAX_ROWS);

View file

@ -305,6 +305,24 @@ interface IExpressionBuilder {
*/ */
public function notIn($x, $y, $type = null); public function notIn($x, $y, $type = null);
/**
* Creates a $x = '' statement, because Oracle needs a different check
*
* @param string $x The field in string format to be inspected by the comparison.
* @return string
* @since 13.0.0
*/
public function emptyString($x);
/**
* Creates a `$x <> ''` statement, because Oracle needs a different check
*
* @param string $x The field in string format to be inspected by the comparison.
* @return string
* @since 13.0.0
*/
public function nonEmptyString($x);
/** /**
* Creates a bitwise AND comparison * Creates a bitwise AND comparison