aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/DB/QueryBuilder
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2024-07-04 11:26:17 +0200
committerJoas Schilling <coding@schilljs.com>2024-07-19 11:21:16 +0200
commiteeb6ddb176adc7488b74d004dceafee960603ebc (patch)
tree50c3bf5d7d1df99c9ea661f68eaded03b6dac3f4 /lib/private/DB/QueryBuilder
parente45465781f1d9d6d64501dee46c8f4b4704e5918 (diff)
downloadnextcloud-server-eeb6ddb176adc7488b74d004dceafee960603ebc.tar.gz
nextcloud-server-eeb6ddb176adc7488b74d004dceafee960603ebc.zip
fix(db): Deprecate `IExpressionBuilder::or()` and `IExpressionBuilder::and()` without parameters
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/DB/QueryBuilder')
-rw-r--r--lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php19
-rw-r--r--lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php12
-rw-r--r--lib/private/DB/QueryBuilder/QueryBuilder.php15
3 files changed, 24 insertions, 22 deletions
diff --git a/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php b/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php
index c4ac350dee5..b70e20e4d0d 100644
--- a/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php
+++ b/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php
@@ -21,6 +21,7 @@ use OCP\DB\QueryBuilder\IParameter;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
use OCP\IDBConnection;
+use Psr\Log\LoggerInterface;
class ExpressionBuilder implements IExpressionBuilder {
/** @var \Doctrine\DBAL\Query\Expression\ExpressionBuilder */
@@ -32,17 +33,15 @@ class ExpressionBuilder implements IExpressionBuilder {
/** @var IDBConnection */
protected $connection;
+ /** @var LoggerInterface */
+ protected $logger;
+
/** @var FunctionBuilder */
protected $functionBuilder;
- /**
- * Initializes a new <tt>ExpressionBuilder</tt>.
- *
- * @param ConnectionAdapter $connection
- * @param IQueryBuilder $queryBuilder
- */
- public function __construct(ConnectionAdapter $connection, IQueryBuilder $queryBuilder) {
+ public function __construct(ConnectionAdapter $connection, IQueryBuilder $queryBuilder, LoggerInterface $logger) {
$this->connection = $connection;
+ $this->logger = $logger;
$this->helper = new QuoteHelper();
$this->expressionBuilder = new DoctrineExpressionBuilder($connection->getInner());
$this->functionBuilder = $queryBuilder->func();
@@ -63,6 +62,9 @@ class ExpressionBuilder implements IExpressionBuilder {
* @return \OCP\DB\QueryBuilder\ICompositeExpression
*/
public function andX(...$x): ICompositeExpression {
+ if (empty($x)) {
+ $this->logger->debug('Calling ' . IQueryBuilder::class . '::' . __FUNCTION__ . ' without parameters is deprecated and will throw soon.', ['exception' => new \Exception('No parameters in call to ' . __METHOD__)]);
+ }
return new CompositeExpression(CompositeExpression::TYPE_AND, $x);
}
@@ -81,6 +83,9 @@ class ExpressionBuilder implements IExpressionBuilder {
* @return \OCP\DB\QueryBuilder\ICompositeExpression
*/
public function orX(...$x): ICompositeExpression {
+ if (empty($x)) {
+ $this->logger->debug('Calling ' . IQueryBuilder::class . '::' . __FUNCTION__ . ' without parameters is deprecated and will throw soon.', ['exception' => new \Exception('No parameters in call to ' . __METHOD__)]);
+ }
return new CompositeExpression(CompositeExpression::TYPE_OR, $x);
}
diff --git a/lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php b/lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php
index cd2fb5a5cc3..7216fd8807b 100644
--- a/lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php
+++ b/lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php
@@ -11,17 +11,13 @@ use OC\DB\ConnectionAdapter;
use OC\DB\QueryBuilder\QueryFunction;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
+use Psr\Log\LoggerInterface;
class MySqlExpressionBuilder extends ExpressionBuilder {
- /** @var string */
- protected $collation;
+ protected string $collation;
- /**
- * @param ConnectionAdapter $connection
- * @param IQueryBuilder $queryBuilder
- */
- public function __construct(ConnectionAdapter $connection, IQueryBuilder $queryBuilder) {
- parent::__construct($connection, $queryBuilder);
+ public function __construct(ConnectionAdapter $connection, IQueryBuilder $queryBuilder, LoggerInterface $logger) {
+ parent::__construct($connection, $queryBuilder, $logger);
$params = $connection->getInner()->getParams();
$this->collation = $params['collation'] ?? (($params['charset'] ?? 'utf8') . '_general_ci');
diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php
index 76ca8d1a3c6..cb9356c5d06 100644
--- a/lib/private/DB/QueryBuilder/QueryBuilder.php
+++ b/lib/private/DB/QueryBuilder/QueryBuilder.php
@@ -92,10 +92,10 @@ class QueryBuilder implements IQueryBuilder {
*/
public function expr() {
return match($this->connection->getDatabaseProvider()) {
- IDBConnection::PLATFORM_ORACLE => new OCIExpressionBuilder($this->connection, $this),
- IDBConnection::PLATFORM_POSTGRES => new PgSqlExpressionBuilder($this->connection, $this),
- IDBConnection::PLATFORM_MYSQL => new MySqlExpressionBuilder($this->connection, $this),
- IDBConnection::PLATFORM_SQLITE => new SqliteExpressionBuilder($this->connection, $this),
+ IDBConnection::PLATFORM_ORACLE => new OCIExpressionBuilder($this->connection, $this, $this->logger),
+ IDBConnection::PLATFORM_POSTGRES => new PgSqlExpressionBuilder($this->connection, $this, $this->logger),
+ IDBConnection::PLATFORM_MYSQL => new MySqlExpressionBuilder($this->connection, $this, $this->logger),
+ IDBConnection::PLATFORM_SQLITE => new SqliteExpressionBuilder($this->connection, $this, $this->logger),
};
}
@@ -815,9 +815,10 @@ class QueryBuilder implements IQueryBuilder {
* // You can optionally programmatically build and/or expressions
* $qb = $conn->getQueryBuilder();
*
- * $or = $qb->expr()->orx();
- * $or->add($qb->expr()->eq('u.id', 1));
- * $or->add($qb->expr()->eq('u.id', 2));
+ * $or = $qb->expr()->orx(
+ * $qb->expr()->eq('u.id', 1),
+ * $qb->expr()->eq('u.id', 2),
+ * );
*
* $qb->update('users', 'u')
* ->set('u.password', md5('password'))