aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/DB
diff options
context:
space:
mode:
Diffstat (limited to 'lib/public/DB')
-rw-r--r--lib/public/DB/Events/AddMissingColumnsEvent.php43
-rw-r--r--lib/public/DB/Events/AddMissingIndicesEvent.php100
-rw-r--r--lib/public/DB/Events/AddMissingPrimaryKeyEvent.php43
-rw-r--r--lib/public/DB/Exception.php138
-rw-r--r--lib/public/DB/IPreparedStatement.php118
-rw-r--r--lib/public/DB/IResult.php77
-rw-r--r--lib/public/DB/ISchemaWrapper.php93
-rw-r--r--lib/public/DB/QueryBuilder/ICompositeExpression.php50
-rw-r--r--lib/public/DB/QueryBuilder/IExpressionBuilder.php427
-rw-r--r--lib/public/DB/QueryBuilder/IFunctionBuilder.php173
-rw-r--r--lib/public/DB/QueryBuilder/ILiteral.php19
-rw-r--r--lib/public/DB/QueryBuilder/IParameter.php19
-rw-r--r--lib/public/DB/QueryBuilder/IQueryBuilder.php1111
-rw-r--r--lib/public/DB/QueryBuilder/IQueryFunction.php19
-rw-r--r--lib/public/DB/QueryBuilder/Sharded/IShardMapper.php25
-rw-r--r--lib/public/DB/Types.php179
16 files changed, 2634 insertions, 0 deletions
diff --git a/lib/public/DB/Events/AddMissingColumnsEvent.php b/lib/public/DB/Events/AddMissingColumnsEvent.php
new file mode 100644
index 00000000000..178a24c0c30
--- /dev/null
+++ b/lib/public/DB/Events/AddMissingColumnsEvent.php
@@ -0,0 +1,43 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCP\DB\Events;
+
+/**
+ * Event to allow apps to register information about missing database columns
+ *
+ * This event will be dispatched for checking on the admin settings and when running
+ * occ db:add-missing-columns which will then create those columns
+ *
+ * @since 28.0.0
+ */
+class AddMissingColumnsEvent extends \OCP\EventDispatcher\Event {
+ /** @var array<array-key, array{tableName: string, columnName: string, typeName: string, options: array{}}> */
+ private array $missingColumns = [];
+
+ /**
+ * @param mixed[] $options
+ * @since 28.0.0
+ */
+ public function addMissingColumn(string $tableName, string $columnName, string $typeName, array $options): void {
+ $this->missingColumns[] = [
+ 'tableName' => $tableName,
+ 'columnName' => $columnName,
+ 'typeName' => $typeName,
+ 'options' => $options,
+ ];
+ }
+
+ /**
+ * @since 28.0.0
+ * @return array<array-key, array{tableName: string, columnName: string, typeName: string, options: array{}}>
+ */
+ public function getMissingColumns(): array {
+ return $this->missingColumns;
+ }
+}
diff --git a/lib/public/DB/Events/AddMissingIndicesEvent.php b/lib/public/DB/Events/AddMissingIndicesEvent.php
new file mode 100644
index 00000000000..a8d4c5e6db5
--- /dev/null
+++ b/lib/public/DB/Events/AddMissingIndicesEvent.php
@@ -0,0 +1,100 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCP\DB\Events;
+
+/**
+ * Event to allow apps to register information about missing database indices
+ *
+ * This event will be dispatched for checking on the admin settings and when running
+ * occ db:add-missing-indices which will then create those indices
+ *
+ * @since 28.0.0
+ */
+class AddMissingIndicesEvent extends \OCP\EventDispatcher\Event {
+ /** @var array<array-key, array{tableName: string, indexName: string, columns: string[], options: array{}, dropUnnamedIndex: bool, uniqueIndex: bool}> */
+ private array $missingIndices = [];
+
+ /** @var array<array-key, array{tableName: string, oldIndexNames: array, newIndexName: string, columns: string[], uniqueIndex: bool, options: array{}}> */
+ private array $toReplaceIndices = [];
+
+ /**
+ * @param string[] $columns
+ * @since 28.0.0
+ */
+ public function addMissingIndex(string $tableName, string $indexName, array $columns, array $options = [], bool $dropUnnamedIndex = false): void {
+ $this->missingIndices[] = [
+ 'tableName' => $tableName,
+ 'indexName' => $indexName,
+ 'columns' => $columns,
+ 'options' => $options,
+ 'dropUnnamedIndex' => $dropUnnamedIndex,
+ 'uniqueIndex' => false,
+ ];
+ }
+ /**
+ * @param string[] $columns
+ * @since 28.0.0
+ */
+ public function addMissingUniqueIndex(string $tableName, string $indexName, array $columns, array $options = [], bool $dropUnnamedIndex = false): void {
+ $this->missingIndices[] = [
+ 'tableName' => $tableName,
+ 'indexName' => $indexName,
+ 'columns' => $columns,
+ 'options' => $options,
+ 'dropUnnamedIndex' => $dropUnnamedIndex,
+ 'uniqueIndex' => true,
+ ];
+ }
+
+ /**
+ * @since 28.0.0
+ * @return array<array-key, array{tableName: string, indexName: string, columns: string[], options: array{}, dropUnnamedIndex: bool, uniqueIndex: bool}>
+ */
+ public function getMissingIndices(): array {
+ return $this->missingIndices;
+ }
+
+ /**
+ * Replace one or more existing indices with a new one. Can be used to make an index unique afterwards or merge two indices into a multicolumn index.
+ *
+ * Note: Make sure to not use the same index name for the new index as for old indices.
+ *
+ * Example:
+ *
+ * <code>
+ * $event->replaceIndex(
+ * 'my_table',
+ * ['old_index_col_a', 'old_index_col_b'],
+ * 'new_index_col_a_b',
+ * ['column_a', 'column_b'],
+ * false
+ * );
+ * </code>
+ *
+ * @since 29.0.0
+ */
+ public function replaceIndex(string $tableName, array $oldIndexNames, string $newIndexName, array $columns, bool $unique, array $options = []): void {
+ $this->toReplaceIndices[] = [
+ 'tableName' => $tableName,
+ 'oldIndexNames' => $oldIndexNames,
+ 'newIndexName' => $newIndexName,
+ 'columns' => $columns,
+ 'uniqueIndex' => $unique,
+ 'options' => $options,
+ ];
+ }
+
+ /**
+ * @since 29.0.0
+ * @return array<array-key, array{tableName: string, oldIndexNames: array, newIndexName: string, columns: string[], uniqueIndex: bool, options: array{}}>
+ */
+ public function getIndicesToReplace(): array {
+ return $this->toReplaceIndices;
+ }
+}
diff --git a/lib/public/DB/Events/AddMissingPrimaryKeyEvent.php b/lib/public/DB/Events/AddMissingPrimaryKeyEvent.php
new file mode 100644
index 00000000000..66c638e66e0
--- /dev/null
+++ b/lib/public/DB/Events/AddMissingPrimaryKeyEvent.php
@@ -0,0 +1,43 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCP\DB\Events;
+
+/**
+ * Event to allow apps to register information about missing database primary keys
+ *
+ * This event will be dispatched for checking on the admin settings and when running
+ * occ db:add-missing-primary-keys which will then create those keys
+ *
+ * @since 28.0.0
+ */
+class AddMissingPrimaryKeyEvent extends \OCP\EventDispatcher\Event {
+ /** @var array<array-key, array{tableName: string, primaryKeyName: string, columns: string[], formerIndex: null|string}> */
+ private array $missingPrimaryKeys = [];
+
+ /**
+ * @param string[] $columns
+ * @since 28.0.0
+ */
+ public function addMissingPrimaryKey(string $tableName, string $primaryKeyName, array $columns, ?string $formerIndex = null): void {
+ $this->missingPrimaryKeys[] = [
+ 'tableName' => $tableName,
+ 'primaryKeyName' => $primaryKeyName,
+ 'columns' => $columns,
+ 'formerIndex' => $formerIndex,
+ ];
+ }
+
+ /**
+ * @since 28.0.0
+ * @return array<array-key, array{tableName: string, primaryKeyName: string, columns: string[], formerIndex: null|string}>
+ */
+ public function getMissingPrimaryKeys(): array {
+ return $this->missingPrimaryKeys;
+ }
+}
diff --git a/lib/public/DB/Exception.php b/lib/public/DB/Exception.php
new file mode 100644
index 00000000000..6b908382aea
--- /dev/null
+++ b/lib/public/DB/Exception.php
@@ -0,0 +1,138 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\DB;
+
+use Exception as BaseException;
+
+/**
+ * Database exception
+ *
+ * Thrown by Nextcloud's database abstraction layer. This is the base class that
+ * any specific exception will extend. Use this class in your try-catch to catch
+ * *any* error related to the database. Use any of the subclasses in the same
+ * namespace if you are only interested in specific errors.
+ *
+ * @psalm-immutable
+ * @since 21.0.0
+ */
+class Exception extends BaseException {
+ /**
+ * Nextcloud lost connection to the database
+ *
+ * @since 21.0.0
+ */
+ public const REASON_CONNECTION_LOST = 1;
+
+ /**
+ * A database constraint was violated
+ *
+ * @since 21.0.0
+ */
+ public const REASON_CONSTRAINT_VIOLATION = 2;
+
+ /**
+ * A database object (table, column, index) already exists
+ *
+ * @since 21.0.0
+ */
+ public const REASON_DATABASE_OBJECT_EXISTS = 3;
+
+ /**
+ * A database object (table, column, index) can't be found
+ *
+ * @since 21.0.0
+ */
+ public const REASON_DATABASE_OBJECT_NOT_FOUND = 4;
+
+ /**
+ * The database ran into a deadlock
+ *
+ * @since 21.0.0
+ */
+ public const REASON_DEADLOCK = 5;
+
+ /**
+ * The database driver encountered an issue
+ *
+ * @since 21.0.0
+ */
+ public const REASON_DRIVER = 6;
+
+ /**
+ * A foreign key constraint was violated
+ *
+ * @since 21.0.0
+ */
+ public const REASON_FOREIGN_KEY_VIOLATION = 7;
+
+ /**
+ * An invalid argument was passed to the database abstraction
+ *
+ * @since 21.0.0
+ */
+ public const REASON_INVALID_ARGUMENT = 8;
+
+ /**
+ * A field name was invalid
+ *
+ * @since 21.0.0
+ */
+ public const REASON_INVALID_FIELD_NAME = 9;
+
+ /**
+ * A name in the query was ambiguous
+ *
+ * @since 21.0.0
+ */
+ public const REASON_NON_UNIQUE_FIELD_NAME = 10;
+
+ /**
+ * A not null constraint was violated
+ *
+ * @since 21.0.0
+ */
+ public const REASON_NOT_NULL_CONSTRAINT_VIOLATION = 11;
+
+ /**
+ * A generic server error was encountered
+ *
+ * @since 21.0.0
+ */
+ public const REASON_SERVER = 12;
+
+ /**
+ * A syntax error was reported by the server
+ *
+ * @since 21.0.0
+ */
+ public const REASON_SYNTAX_ERROR = 13;
+
+ /**
+ * A unique constraint was violated
+ *
+ * @since 21.0.0
+ */
+ public const REASON_UNIQUE_CONSTRAINT_VIOLATION = 14;
+
+ /**
+ * The lock wait timeout was exceeded
+ *
+ * @since 30.0.0
+ */
+ public const REASON_LOCK_WAIT_TIMEOUT = 15;
+
+ /**
+ * @return int|null
+ * @psalm-return Exception::REASON_*
+ * @since 21.0.0
+ */
+ public function getReason(): ?int {
+ return null;
+ }
+}
diff --git a/lib/public/DB/IPreparedStatement.php b/lib/public/DB/IPreparedStatement.php
new file mode 100644
index 00000000000..887451a1caf
--- /dev/null
+++ b/lib/public/DB/IPreparedStatement.php
@@ -0,0 +1,118 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\DB;
+
+use Doctrine\DBAL\Exception;
+use Doctrine\DBAL\ParameterType;
+use PDO;
+
+/**
+ * This interface allows you to prepare a database query.
+ *
+ * This interface must not be implemented in your application but
+ * instead obtained from IDBConnection::prepare.
+ *
+ * ```php
+ * $prepare = $this->db->prepare($query->getSql());
+ * ```
+ *
+ * @since 21.0.0
+ */
+interface IPreparedStatement {
+ /**
+ * @return true
+ *
+ * @since 21.0.0
+ * @deprecated 21.0.0 use \OCP\DB\IResult::closeCursor on the \OCP\DB\IResult returned by \OCP\IDBConnection::prepare
+ */
+ public function closeCursor(): bool;
+
+ /**
+ * @param int $fetchMode
+ *
+ * @return mixed
+ *
+ * @since 21.0.0
+ * @deprecated 21.0.0 use \OCP\DB\IResult::fetch on the \OCP\DB\IResult returned by \OCP\IDBConnection::prepare
+ */
+ public function fetch(int $fetchMode = PDO::FETCH_ASSOC);
+
+ /**
+ * @param int $fetchMode
+ *
+ * @return mixed[]
+ *
+ * @since 21.0.0
+ * @deprecated 21.0.0 use \OCP\DB\IResult::fetchAll on the \OCP\DB\IResult returned by \OCP\IDBConnection::prepare
+ */
+ public function fetchAll(int $fetchMode = PDO::FETCH_ASSOC);
+
+ /**
+ * @return mixed
+ *
+ * @since 21.0.0
+ * @deprecated 21.0.0 use \OCP\DB\IResult::fetchColumn on the \OCP\DB\IResult returned by \OCP\IDBConnection::prepare
+ */
+ public function fetchColumn();
+
+ /**
+ * @return mixed
+ *
+ * @since 21.0.0
+ * @deprecated 21.0.0 use \OCP\DB\IResult::fetchOne on the \OCP\DB\IResult returned by \OCP\IDBConnection::prepare
+ */
+ public function fetchOne();
+
+ /**
+ * @param int|string $param
+ * @param mixed $value
+ * @param int $type
+ *
+ * @return bool
+ *
+ * @throws Exception
+ *
+ * @since 21.0.0
+ */
+ public function bindValue($param, $value, $type = ParameterType::STRING): bool;
+
+ /**
+ * @param int|string $param
+ * @param mixed $variable
+ * @param int $type
+ * @param int|null $length
+ *
+ * @return bool
+ *
+ * @throws Exception
+ *
+ * @since 21.0.0
+ */
+ public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool;
+
+ /**
+ * @param mixed[]|null $params
+ *
+ * @return IResult
+ *
+ * @since 21.0.0
+ * @throws Exception
+ */
+ public function execute($params = null): IResult;
+
+ /**
+ * @return int
+ *
+ * @since 21.0.0
+ *
+ * @throws Exception
+ * @deprecated 21.0.0 use \OCP\DB\IResult::rowCount on the \OCP\DB\IResult returned by \OCP\IDBConnection::prepare
+ */
+ public function rowCount(): int;
+}
diff --git a/lib/public/DB/IResult.php b/lib/public/DB/IResult.php
new file mode 100644
index 00000000000..347919ab336
--- /dev/null
+++ b/lib/public/DB/IResult.php
@@ -0,0 +1,77 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\DB;
+
+use PDO;
+
+/**
+ * This interface represents the result of a database query.
+ *
+ * Usage:
+ *
+ * ```php
+ * $qb = $this->db->getQueryBuilder();
+ * $qb->select(...);
+ * $result = $query->executeQuery();
+ * ```
+ *
+ * This interface must not be implemented in your application.
+ *
+ * @since 21.0.0
+ */
+interface IResult {
+ /**
+ * @return true
+ *
+ * @since 21.0.0
+ */
+ public function closeCursor(): bool;
+
+ /**
+ * @param int $fetchMode
+ *
+ * @return mixed
+ *
+ * @since 21.0.0
+ */
+ public function fetch(int $fetchMode = PDO::FETCH_ASSOC);
+
+ /**
+ * @param int $fetchMode (one of PDO::FETCH_ASSOC, PDO::FETCH_NUM or PDO::FETCH_COLUMN (2, 3 or 7)
+ *
+ * @return mixed[]
+ *
+ * @since 21.0.0
+ */
+ public function fetchAll(int $fetchMode = PDO::FETCH_ASSOC): array;
+
+ /**
+ * @return mixed
+ *
+ * @since 21.0.0
+ * @deprecated 21.0.0 use \OCP\DB\IResult::fetchOne
+ */
+ public function fetchColumn();
+
+ /**
+ * Returns the first value of the next row of the result or FALSE if there are no more rows.
+ *
+ * @return false|mixed
+ *
+ * @since 21.0.0
+ */
+ public function fetchOne();
+
+ /**
+ * @return int
+ *
+ * @since 21.0.0
+ */
+ public function rowCount(): int;
+}
diff --git a/lib/public/DB/ISchemaWrapper.php b/lib/public/DB/ISchemaWrapper.php
new file mode 100644
index 00000000000..dcf22b52d3d
--- /dev/null
+++ b/lib/public/DB/ISchemaWrapper.php
@@ -0,0 +1,93 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\DB;
+
+use Doctrine\DBAL\Exception;
+use Doctrine\DBAL\Platforms\AbstractPlatform;
+
+/**
+ * This interface allows to get information about the database schema.
+ * This is particularly helpful for database migration scripts.
+ *
+ * This interface must not be implemented in your application but
+ * instead can be obtained in your migration scripts with the
+ * `$schemaClosure` Closure.
+ *
+ * @since 13.0.0
+ */
+interface ISchemaWrapper {
+ /**
+ * @param string $tableName
+ *
+ * @return \Doctrine\DBAL\Schema\Table
+ * @throws \Doctrine\DBAL\Schema\SchemaException
+ * @since 13.0.0
+ */
+ public function getTable($tableName);
+
+ /**
+ * Does this schema have a table with the given name?
+ *
+ * @param string $tableName Prefix is automatically prepended
+ *
+ * @return boolean
+ * @since 13.0.0
+ */
+ public function hasTable($tableName);
+
+ /**
+ * Creates a new table.
+ *
+ * @param string $tableName Prefix is automatically prepended
+ * @return \Doctrine\DBAL\Schema\Table
+ * @since 13.0.0
+ */
+ public function createTable($tableName);
+
+ /**
+ * Drops a table from the schema.
+ *
+ * @param string $tableName Prefix is automatically prepended
+ * @return \Doctrine\DBAL\Schema\Schema
+ * @since 13.0.0
+ */
+ public function dropTable($tableName);
+
+ /**
+ * Gets all tables of this schema.
+ *
+ * @return \Doctrine\DBAL\Schema\Table[]
+ * @since 13.0.0
+ */
+ public function getTables();
+
+ /**
+ * Gets all table names, prefixed with table prefix
+ *
+ * @return array
+ * @since 13.0.0
+ */
+ public function getTableNames();
+
+ /**
+ * Gets all table names
+ *
+ * @return array
+ * @since 13.0.0
+ */
+ public function getTableNamesWithoutPrefix();
+
+ /**
+ * Gets the DatabasePlatform for the database.
+ *
+ * @return AbstractPlatform
+ *
+ * @throws Exception
+ * @since 23.0.0
+ */
+ public function getDatabasePlatform();
+}
diff --git a/lib/public/DB/QueryBuilder/ICompositeExpression.php b/lib/public/DB/QueryBuilder/ICompositeExpression.php
new file mode 100644
index 00000000000..12f321d9e54
--- /dev/null
+++ b/lib/public/DB/QueryBuilder/ICompositeExpression.php
@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+namespace OCP\DB\QueryBuilder;
+
+/**
+ * This class provides a wrapper around Doctrine's CompositeExpression
+ * @since 8.2.0
+ */
+interface ICompositeExpression {
+ /**
+ * Adds multiple parts to composite expression.
+ *
+ * @param array $parts
+ *
+ * @return ICompositeExpression
+ * @since 8.2.0
+ */
+ public function addMultiple(array $parts = []): ICompositeExpression;
+
+ /**
+ * Adds an expression to composite expression.
+ *
+ * @param mixed $part
+ *
+ * @return ICompositeExpression
+ * @since 8.2.0
+ */
+ public function add($part): ICompositeExpression;
+
+ /**
+ * Retrieves the amount of expressions on composite expression.
+ *
+ * @return integer
+ * @since 8.2.0
+ */
+ public function count(): int;
+
+ /**
+ * Returns the type of this composite expression (AND/OR).
+ *
+ * @return string
+ * @since 8.2.0
+ */
+ public function getType(): string;
+}
diff --git a/lib/public/DB/QueryBuilder/IExpressionBuilder.php b/lib/public/DB/QueryBuilder/IExpressionBuilder.php
new file mode 100644
index 00000000000..12e30a45071
--- /dev/null
+++ b/lib/public/DB/QueryBuilder/IExpressionBuilder.php
@@ -0,0 +1,427 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+namespace OCP\DB\QueryBuilder;
+
+use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
+
+/**
+ * This class provides a wrapper around Doctrine's ExpressionBuilder
+ * @since 8.2.0
+ *
+ * @psalm-taint-specialize
+ */
+interface IExpressionBuilder {
+ /**
+ * @since 9.0.0
+ */
+ public const EQ = ExpressionBuilder::EQ;
+ /**
+ * @since 9.0.0
+ */
+ public const NEQ = ExpressionBuilder::NEQ;
+ /**
+ * @since 9.0.0
+ */
+ public const LT = ExpressionBuilder::LT;
+ /**
+ * @since 9.0.0
+ */
+ public const LTE = ExpressionBuilder::LTE;
+ /**
+ * @since 9.0.0
+ */
+ public const GT = ExpressionBuilder::GT;
+ /**
+ * @since 9.0.0
+ */
+ public const GTE = ExpressionBuilder::GTE;
+
+ /**
+ * Creates a conjunction of the given boolean expressions.
+ *
+ * Example:
+ *
+ * [php]
+ * // (u.type = ?) AND (u.role = ?)
+ * $expr->andX('u.type = ?', 'u.role = ?'));
+ *
+ * @param mixed ...$x Optional clause. Defaults = null, but requires
+ * at least one defined when converting to string.
+ *
+ * @return \OCP\DB\QueryBuilder\ICompositeExpression
+ * @since 8.2.0
+ * @since 30.0.0 Calling the method without any arguments is deprecated and will throw with the next Doctrine/DBAL update
+ *
+ * @psalm-taint-sink sql $x
+ */
+ public function andX(...$x): ICompositeExpression;
+
+ /**
+ * Creates a disjunction of the given boolean expressions.
+ *
+ * Example:
+ *
+ * [php]
+ * // (u.type = ?) OR (u.role = ?)
+ * $qb->where($qb->expr()->orX('u.type = ?', 'u.role = ?'));
+ *
+ * @param mixed ...$x Optional clause. Defaults = null, but requires
+ * at least one defined when converting to string.
+ *
+ * @return \OCP\DB\QueryBuilder\ICompositeExpression
+ * @since 8.2.0
+ * @since 30.0.0 Calling the method without any arguments is deprecated and will throw with the next Doctrine/DBAL update
+ *
+ * @psalm-taint-sink sql $x
+ */
+ public function orX(...$x): ICompositeExpression;
+
+ /**
+ * Creates a comparison expression.
+ *
+ * @param mixed $x The left expression.
+ * @param string $operator One of the IExpressionBuilder::* constants.
+ * @param mixed $y The right expression.
+ * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
+ * required when comparing text fields for oci compatibility
+ *
+ * @return string
+ * @since 8.2.0 - Parameter $type was added in 9.0.0
+ *
+ * @psalm-taint-sink sql $x
+ * @psalm-taint-sink sql $operator
+ * @psalm-taint-sink sql $y
+ * @psalm-taint-sink sql $type
+ */
+ public function comparison($x, string $operator, $y, $type = null): string;
+
+ /**
+ * Creates an equality comparison expression with the given arguments.
+ *
+ * First argument is considered the left expression and the second is the right expression.
+ * When converted to string, it will generated a <left expr> = <right expr>. Example:
+ *
+ * [php]
+ * // u.id = ?
+ * $expr->eq('u.id', '?');
+ *
+ * @param mixed $x The left expression.
+ * @param mixed $y The right expression.
+ * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
+ * required when comparing text fields for oci compatibility
+ *
+ * @return string
+ * @since 8.2.0 - Parameter $type was added in 9.0.0
+ *
+ * @psalm-taint-sink sql $x
+ * @psalm-taint-sink sql $y
+ * @psalm-taint-sink sql $type
+ */
+ public function eq($x, $y, $type = null): string;
+
+ /**
+ * Creates a non equality comparison expression with the given arguments.
+ * First argument is considered the left expression and the second is the right expression.
+ * When converted to string, it will generated a <left expr> <> <right expr>. Example:
+ *
+ * [php]
+ * // u.id <> 1
+ * $q->where($q->expr()->neq('u.id', '1'));
+ *
+ * @param mixed $x The left expression.
+ * @param mixed $y The right expression.
+ * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
+ * required when comparing text fields for oci compatibility
+ *
+ * @return string
+ * @since 8.2.0 - Parameter $type was added in 9.0.0
+ *
+ * @psalm-taint-sink sql $x
+ * @psalm-taint-sink sql $y
+ * @psalm-taint-sink sql $type
+ */
+ public function neq($x, $y, $type = null): string;
+
+ /**
+ * Creates a lower-than comparison expression with the given arguments.
+ * First argument is considered the left expression and the second is the right expression.
+ * When converted to string, it will generated a <left expr> < <right expr>. Example:
+ *
+ * [php]
+ * // u.id < ?
+ * $q->where($q->expr()->lt('u.id', '?'));
+ *
+ * @param mixed $x The left expression.
+ * @param mixed $y The right expression.
+ * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
+ * required when comparing text fields for oci compatibility
+ *
+ * @return string
+ * @since 8.2.0 - Parameter $type was added in 9.0.0
+ *
+ * @psalm-taint-sink sql $x
+ * @psalm-taint-sink sql $y
+ * @psalm-taint-sink sql $type
+ */
+ public function lt($x, $y, $type = null): string;
+
+ /**
+ * Creates a lower-than-equal comparison expression with the given arguments.
+ * First argument is considered the left expression and the second is the right expression.
+ * When converted to string, it will generated a <left expr> <= <right expr>. Example:
+ *
+ * [php]
+ * // u.id <= ?
+ * $q->where($q->expr()->lte('u.id', '?'));
+ *
+ * @param mixed $x The left expression.
+ * @param mixed $y The right expression.
+ * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
+ * required when comparing text fields for oci compatibility
+ *
+ * @return string
+ * @since 8.2.0 - Parameter $type was added in 9.0.0
+ *
+ * @psalm-taint-sink sql $x
+ * @psalm-taint-sink sql $y
+ * @psalm-taint-sink sql $type
+ */
+ public function lte($x, $y, $type = null): string;
+
+ /**
+ * Creates a greater-than comparison expression with the given arguments.
+ * First argument is considered the left expression and the second is the right expression.
+ * When converted to string, it will generated a <left expr> > <right expr>. Example:
+ *
+ * [php]
+ * // u.id > ?
+ * $q->where($q->expr()->gt('u.id', '?'));
+ *
+ * @param mixed $x The left expression.
+ * @param mixed $y The right expression.
+ * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
+ * required when comparing text fields for oci compatibility
+ *
+ * @return string
+ * @since 8.2.0 - Parameter $type was added in 9.0.0
+ *
+ * @psalm-taint-sink sql $x
+ * @psalm-taint-sink sql $y
+ * @psalm-taint-sink sql $type
+ */
+ public function gt($x, $y, $type = null): string;
+
+ /**
+ * Creates a greater-than-equal comparison expression with the given arguments.
+ * First argument is considered the left expression and the second is the right expression.
+ * When converted to string, it will generated a <left expr> >= <right expr>. Example:
+ *
+ * [php]
+ * // u.id >= ?
+ * $q->where($q->expr()->gte('u.id', '?'));
+ *
+ * @param mixed $x The left expression.
+ * @param mixed $y The right expression.
+ * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
+ * required when comparing text fields for oci compatibility
+ *
+ * @return string
+ * @since 8.2.0 - Parameter $type was added in 9.0.0
+ *
+ * @psalm-taint-sink sql $x
+ * @psalm-taint-sink sql $y
+ * @psalm-taint-sink sql $type
+ */
+ public function gte($x, $y, $type = null): string;
+
+ /**
+ * Creates an IS NULL expression with the given arguments.
+ *
+ * @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be restricted by IS NULL.
+ *
+ * @return string
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $x
+ */
+ public function isNull($x): string;
+
+ /**
+ * Creates an IS NOT NULL expression with the given arguments.
+ *
+ * @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be restricted by IS NOT NULL.
+ *
+ * @return string
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $x
+ */
+ public function isNotNull($x): string;
+
+ /**
+ * Creates a LIKE() comparison expression with the given arguments.
+ *
+ * @param ILiteral|IParameter|IQueryFunction|string $x Field in string format to be inspected by LIKE() comparison.
+ * @param mixed $y Argument to be used in LIKE() comparison.
+ * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
+ * required when comparing text fields for oci compatibility
+ *
+ * @return string
+ * @since 8.2.0 - Parameter $type was added in 9.0.0
+ *
+ * @psalm-taint-sink sql $x
+ * @psalm-taint-sink sql $y
+ * @psalm-taint-sink sql $type
+ */
+ public function like($x, $y, $type = null): string;
+
+ /**
+ * Creates a NOT LIKE() comparison expression with the given arguments.
+ *
+ * @param ILiteral|IParameter|IQueryFunction|string $x Field in string format to be inspected by NOT LIKE() comparison.
+ * @param mixed $y Argument to be used in NOT LIKE() comparison.
+ * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
+ * required when comparing text fields for oci compatibility
+ *
+ * @return string
+ * @since 8.2.0 - Parameter $type was added in 9.0.0
+ *
+ * @psalm-taint-sink sql $x
+ * @psalm-taint-sink sql $y
+ * @psalm-taint-sink sql $type
+ */
+ public function notLike($x, $y, $type = null): string;
+
+ /**
+ * Creates a ILIKE() comparison expression with the given arguments.
+ *
+ * @param string $x Field in string format to be inspected by ILIKE() comparison.
+ * @param mixed $y Argument to be used in ILIKE() comparison.
+ * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
+ * required when comparing text fields for oci compatibility
+ *
+ * @return string
+ * @since 9.0.0
+ *
+ * @psalm-taint-sink sql $x
+ * @psalm-taint-sink sql $y
+ * @psalm-taint-sink sql $type
+ */
+ public function iLike($x, $y, $type = null): string;
+
+ /**
+ * Creates a IN () comparison expression with the given arguments.
+ *
+ * @param ILiteral|IParameter|IQueryFunction|string $x The field in string format to be inspected by IN() comparison.
+ * @param ILiteral|IParameter|IQueryFunction|string|array $y The placeholder or the array of values to be used by IN() comparison.
+ * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
+ * required when comparing text fields for oci compatibility
+ *
+ * @return string
+ * @since 8.2.0 - Parameter $type was added in 9.0.0
+ *
+ * @psalm-taint-sink sql $x
+ * @psalm-taint-sink sql $y
+ * @psalm-taint-sink sql $type
+ */
+ public function in($x, $y, $type = null): string;
+
+ /**
+ * Creates a NOT IN () comparison expression with the given arguments.
+ *
+ * @param ILiteral|IParameter|IQueryFunction|string $x The field in string format to be inspected by NOT IN() comparison.
+ * @param ILiteral|IParameter|IQueryFunction|string|array $y The placeholder or the array of values to be used by NOT IN() comparison.
+ * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants
+ * required when comparing text fields for oci compatibility
+ *
+ * @return string
+ * @since 8.2.0 - Parameter $type was added in 9.0.0
+ *
+ * @psalm-taint-sink sql $x
+ * @psalm-taint-sink sql $y
+ * @psalm-taint-sink sql $type
+ */
+ public function notIn($x, $y, $type = null): string;
+
+ /**
+ * Creates a $x = '' statement, because Oracle needs a different check
+ *
+ * @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be inspected by the comparison.
+ * @return string
+ * @since 13.0.0
+ *
+ * @psalm-taint-sink sql $x
+ */
+ public function emptyString($x): string;
+
+ /**
+ * Creates a `$x <> ''` statement, because Oracle needs a different check
+ *
+ * @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be inspected by the comparison.
+ * @return string
+ * @since 13.0.0
+ *
+ * @psalm-taint-sink sql $x
+ */
+ public function nonEmptyString($x): string;
+
+
+ /**
+ * Creates a bitwise AND comparison
+ *
+ * @param string|ILiteral $x The field or value to check
+ * @param int $y Bitmap that must be set
+ * @return IQueryFunction
+ * @since 12.0.0
+ *
+ * @psalm-taint-sink sql $x
+ * @psalm-taint-sink sql $y
+ */
+ public function bitwiseAnd($x, int $y): IQueryFunction;
+
+ /**
+ * Creates a bitwise OR comparison
+ *
+ * @param string|ILiteral $x The field or value to check
+ * @param int $y Bitmap that must be set
+ * @return IQueryFunction
+ * @since 12.0.0
+ *
+ * @psalm-taint-sink sql $x
+ * @psalm-taint-sink sql $y
+ */
+ public function bitwiseOr($x, int $y): IQueryFunction;
+
+ /**
+ * Quotes a given input parameter.
+ *
+ * @param mixed $input The parameter to be quoted.
+ * @param int $type One of the IQueryBuilder::PARAM_* constants
+ *
+ * @return ILiteral
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $input
+ * @psalm-taint-sink sql $type
+ */
+ public function literal($input, $type = IQueryBuilder::PARAM_STR): ILiteral;
+
+ /**
+ * Returns a IQueryFunction that casts the column to the given type
+ *
+ * @param string|IQueryFunction $column
+ * @param mixed $type One of IQueryBuilder::PARAM_*
+ * @psalm-param IQueryBuilder::PARAM_* $type
+ * @return IQueryFunction
+ * @since 9.0.0
+ *
+ * @psalm-taint-sink sql $column
+ * @psalm-taint-sink sql $type
+ */
+ public function castColumn($column, $type): IQueryFunction;
+}
diff --git a/lib/public/DB/QueryBuilder/IFunctionBuilder.php b/lib/public/DB/QueryBuilder/IFunctionBuilder.php
new file mode 100644
index 00000000000..480ec1cb1ac
--- /dev/null
+++ b/lib/public/DB/QueryBuilder/IFunctionBuilder.php
@@ -0,0 +1,173 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\DB\QueryBuilder;
+
+/**
+ * This class provides a builder for sql some functions
+ *
+ * @since 12.0.0
+ */
+interface IFunctionBuilder {
+ /**
+ * Calculates the MD5 hash of a given input
+ *
+ * @param string|ILiteral|IParameter|IQueryFunction $input The input to be hashed
+ *
+ * @return IQueryFunction
+ * @since 12.0.0
+ */
+ public function md5($input): IQueryFunction;
+
+ /**
+ * Combines two input strings
+ *
+ * @param string|ILiteral|IParameter|IQueryFunction $x Expressions or literal strings
+ * @param string|ILiteral|IParameter|IQueryFunction ...$exprs Expressions or literal strings
+ *
+ * @return IQueryFunction
+ * @since 12.0.0
+ */
+ public function concat($x, ...$expr): IQueryFunction;
+
+ /**
+ * Returns a string which is the concatenation of all non-NULL values of X
+ *
+ * Usage examples:
+ *
+ * groupConcat('column') -- with comma as separator (default separator)
+ *
+ * groupConcat('column', ';') -- with different separator
+ *
+ * @param string|IQueryFunction $expr The expression to group
+ * @param string|null $separator The separator
+ * @return IQueryFunction
+ * @since 24.0.0
+ */
+ public function groupConcat($expr, ?string $separator = ','): IQueryFunction;
+
+ /**
+ * Takes a substring from the input string
+ *
+ * @param string|ILiteral|IParameter|IQueryFunction $input The input string
+ * @param string|ILiteral|IParameter|IQueryFunction $start The start of the substring, note that counting starts at 1
+ * @param null|ILiteral|IParameter|IQueryFunction $length The length of the substring
+ *
+ * @return IQueryFunction
+ * @since 12.0.0
+ */
+ public function substring($input, $start, $length = null): IQueryFunction;
+
+ /**
+ * Takes the sum of all rows in a column
+ *
+ * @param string|ILiteral|IParameter|IQueryFunction $field the column to sum
+ *
+ * @return IQueryFunction
+ * @since 12.0.0
+ */
+ public function sum($field): IQueryFunction;
+
+ /**
+ * Transforms a string field or value to lower case
+ *
+ * @param string|ILiteral|IParameter|IQueryFunction $field
+ * @return IQueryFunction
+ * @since 14.0.0
+ */
+ public function lower($field): IQueryFunction;
+
+ /**
+ * @param string|ILiteral|IParameter|IQueryFunction $x The first input field or number
+ * @param string|ILiteral|IParameter|IQueryFunction $y The second input field or number
+ * @return IQueryFunction
+ * @since 14.0.0
+ */
+ public function add($x, $y): IQueryFunction;
+
+ /**
+ * @param string|ILiteral|IParameter|IQueryFunction $x The first input field or number
+ * @param string|ILiteral|IParameter|IQueryFunction $y The second input field or number
+ * @return IQueryFunction
+ * @since 14.0.0
+ */
+ public function subtract($x, $y): IQueryFunction;
+
+ /**
+ * @param string|ILiteral|IParameter|IQueryFunction $count The input to be counted
+ * @param string $alias Alias for the counter
+ *
+ * @return IQueryFunction
+ * @since 14.0.0
+ */
+ 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
+ *
+ * If you want to get the maximum value of multiple columns in the same row, use `greatest` instead
+ *
+ * @param string|ILiteral|IParameter|IQueryFunction $field the column to maximum
+ *
+ * @return IQueryFunction
+ * @since 18.0.0
+ */
+ public function max($field): IQueryFunction;
+
+ /**
+ * Takes the minimum of all rows in a column
+ *
+ * If you want to get the minimum value of multiple columns in the same row, use `least` instead
+ *
+ * @param string|ILiteral|IParameter|IQueryFunction $field the column to minimum
+ *
+ * @return IQueryFunction
+ * @since 18.0.0
+ */
+ public function min($field): IQueryFunction;
+
+ /**
+ * Takes the maximum of multiple values
+ *
+ * If you want to get the maximum value of all rows in a column, use `max` instead
+ *
+ * @param string|ILiteral|IParameter|IQueryFunction $x
+ * @param string|ILiteral|IParameter|IQueryFunction $y
+ * @return IQueryFunction
+ * @since 18.0.0
+ */
+ public function greatest($x, $y): IQueryFunction;
+
+ /**
+ * Takes the minimum of multiple values
+ *
+ * If you want to get the minimum value of all rows in a column, use `min` instead
+ *
+ * @param string|ILiteral|IParameter|IQueryFunction $x
+ * @param string|ILiteral|IParameter|IQueryFunction $y
+ * @return IQueryFunction
+ * @since 18.0.0
+ */
+ public function least($x, $y): IQueryFunction;
+}
diff --git a/lib/public/DB/QueryBuilder/ILiteral.php b/lib/public/DB/QueryBuilder/ILiteral.php
new file mode 100644
index 00000000000..574eb0894eb
--- /dev/null
+++ b/lib/public/DB/QueryBuilder/ILiteral.php
@@ -0,0 +1,19 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+namespace OCP\DB\QueryBuilder;
+
+/**
+ * @since 8.2.0
+ */
+interface ILiteral {
+ /**
+ * @return string
+ * @since 8.2.0
+ */
+ public function __toString();
+}
diff --git a/lib/public/DB/QueryBuilder/IParameter.php b/lib/public/DB/QueryBuilder/IParameter.php
new file mode 100644
index 00000000000..86ea9437e9c
--- /dev/null
+++ b/lib/public/DB/QueryBuilder/IParameter.php
@@ -0,0 +1,19 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+namespace OCP\DB\QueryBuilder;
+
+/**
+ * @since 8.2.0
+ */
+interface IParameter {
+ /**
+ * @return string
+ * @since 8.2.0
+ */
+ public function __toString();
+}
diff --git a/lib/public/DB/QueryBuilder/IQueryBuilder.php b/lib/public/DB/QueryBuilder/IQueryBuilder.php
new file mode 100644
index 00000000000..4794e7e8877
--- /dev/null
+++ b/lib/public/DB/QueryBuilder/IQueryBuilder.php
@@ -0,0 +1,1111 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+namespace OCP\DB\QueryBuilder;
+
+use Doctrine\DBAL\ArrayParameterType;
+use Doctrine\DBAL\Connection;
+use Doctrine\DBAL\ParameterType;
+use Doctrine\DBAL\Types\Types;
+use OCP\DB\Exception;
+use OCP\DB\IResult;
+use OCP\IDBConnection;
+
+/**
+ * This class provides a wrapper around Doctrine's QueryBuilder
+ * @since 8.2.0
+ *
+ * @psalm-taint-specialize
+ */
+interface IQueryBuilder {
+ /**
+ * @since 9.0.0
+ */
+ public const PARAM_NULL = ParameterType::NULL;
+ /**
+ * @since 9.0.0
+ */
+ public const PARAM_BOOL = Types::BOOLEAN;
+ /**
+ * @since 9.0.0
+ */
+ public const PARAM_INT = ParameterType::INTEGER;
+ /**
+ * @since 9.0.0
+ */
+ public const PARAM_STR = ParameterType::STRING;
+ /**
+ * @since 9.0.0
+ */
+ public const PARAM_LOB = ParameterType::LARGE_OBJECT;
+
+ /**
+ * @since 9.0.0
+ * @deprecated 31.0.0 - use PARAM_DATETIME_MUTABLE instead
+ */
+ public const PARAM_DATE = Types::DATETIME_MUTABLE;
+
+ /**
+ * For passing a \DateTime instance when only interested in the time part (without timezone support)
+ * @since 31.0.0
+ */
+ public const PARAM_TIME_MUTABLE = Types::TIME_MUTABLE;
+
+ /**
+ * For passing a \DateTime instance when only interested in the date part (without timezone support)
+ * @since 31.0.0
+ */
+ public const PARAM_DATE_MUTABLE = Types::DATE_MUTABLE;
+
+ /**
+ * For passing a \DateTime instance (without timezone support)
+ * @since 31.0.0
+ */
+ public const PARAM_DATETIME_MUTABLE = Types::DATETIME_MUTABLE;
+
+ /**
+ * For passing a \DateTime instance with timezone support
+ * @since 31.0.0
+ */
+ public const PARAM_DATETIME_TZ_MUTABLE = Types::DATETIMETZ_MUTABLE;
+
+ /**
+ * For passing a \DateTimeImmutable instance when only interested in the time part (without timezone support)
+ * @since 31.0.0
+ */
+ public const PARAM_TIME_IMMUTABLE = Types::TIME_MUTABLE;
+
+ /**
+ * For passing a \DateTime instance when only interested in the date part (without timezone support)
+ * @since 9.0.0
+ */
+ public const PARAM_DATE_IMMUTABLE = Types::DATE_IMMUTABLE;
+
+ /**
+ * For passing a \DateTime instance (without timezone support)
+ * @since 31.0.0
+ */
+ public const PARAM_DATETIME_IMMUTABLE = Types::DATETIME_IMMUTABLE;
+
+ /**
+ * For passing a \DateTime instance with timezone support
+ * @since 31.0.0
+ */
+ public const PARAM_DATETIME_TZ_IMMUTABLE = Types::DATETIMETZ_IMMUTABLE;
+
+ /**
+ * @since 24.0.0
+ */
+ public const PARAM_JSON = 'json';
+
+ /**
+ * @since 9.0.0
+ */
+ public const PARAM_INT_ARRAY = ArrayParameterType::INTEGER;
+ /**
+ * @since 9.0.0
+ */
+ public const PARAM_STR_ARRAY = ArrayParameterType::STRING;
+
+ /**
+ * @since 24.0.0 Indicates how many rows can be deleted at once with MySQL
+ * database server.
+ */
+ public const MAX_ROW_DELETION = 100000;
+
+ /**
+ * Enable/disable automatic prefixing of table names with the oc_ prefix
+ *
+ * @param bool $enabled If set to true table names will be prefixed with the
+ * owncloud database prefix automatically.
+ * @since 8.2.0
+ */
+ public function automaticTablePrefix($enabled);
+
+ /**
+ * Gets an ExpressionBuilder used for object-oriented construction of query expressions.
+ * This producer method is intended for convenient inline usage. Example:
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->select('u')
+ * ->from('users', 'u')
+ * ->where($qb->expr()->eq('u.id', 1));
+ * </code>
+ *
+ * For more complex expression construction, consider storing the expression
+ * builder object in a local variable.
+ *
+ * @return \OCP\DB\QueryBuilder\IExpressionBuilder
+ * @since 8.2.0
+ */
+ public function expr();
+
+ /**
+ * Gets an FunctionBuilder used for object-oriented construction of query functions.
+ * This producer method is intended for convenient inline usage. Example:
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->select('u')
+ * ->from('users', 'u')
+ * ->where($qb->fun()->md5('u.id'));
+ * </code>
+ *
+ * For more complex function construction, consider storing the function
+ * builder object in a local variable.
+ *
+ * @return \OCP\DB\QueryBuilder\IFunctionBuilder
+ * @since 12.0.0
+ */
+ public function func();
+
+ /**
+ * Gets the type of the currently built query.
+ *
+ * @return integer
+ * @since 8.2.0
+ */
+ public function getType();
+
+ /**
+ * Gets the associated DBAL Connection for this query builder.
+ *
+ * @return \OCP\IDBConnection
+ * @since 8.2.0
+ */
+ public function getConnection();
+
+ /**
+ * Gets the state of this query builder instance.
+ *
+ * @return integer Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.
+ * @since 8.2.0
+ * @deprecated 30.0.0 This function is going to be removed with the next Doctrine/DBAL update
+ * and we can not fix this in our wrapper.
+ */
+ public function getState();
+
+ /**
+ * Executes this query using the bound parameters and their types.
+ *
+ * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeStatement}
+ * for insert, update and delete statements.
+ *
+ * Warning: until Nextcloud 20, this method could return a \Doctrine\DBAL\Driver\Statement but since
+ * that interface changed in a breaking way the adapter \OCP\DB\QueryBuilder\IStatement is returned
+ * to bridge old code to the new API
+ *
+ * @param ?IDBConnection $connection (optional) the connection to run the query against. since 30.0
+ * @return IResult|int
+ * @throws Exception since 21.0.0
+ * @since 8.2.0
+ * @deprecated 22.0.0 Use executeQuery or executeStatement
+ */
+ public function execute(?IDBConnection $connection = null);
+
+ /**
+ * Execute for select statements
+ *
+ * @param ?IDBConnection $connection (optional) the connection to run the query against. since 30.0
+ * @return IResult
+ * @since 22.0.0
+ *
+ * @throws Exception
+ * @throws \RuntimeException in case of usage with non select query
+ */
+ public function executeQuery(?IDBConnection $connection = null): IResult;
+
+ /**
+ * Execute insert, update and delete statements
+ *
+ * @param ?IDBConnection $connection (optional) the connection to run the query against. since 30.0
+ * @return int the number of affected rows
+ * @since 22.0.0
+ *
+ * @throws Exception
+ * @throws \RuntimeException in case of usage with select query
+ */
+ public function executeStatement(?IDBConnection $connection = null): int;
+
+ /**
+ * Gets the complete SQL string formed by the current specifications of this QueryBuilder.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->select('u')
+ * ->from('User', 'u')
+ * echo $qb->getSQL(); // SELECT u FROM User u
+ * </code>
+ *
+ * @return string The SQL query string.
+ * @since 8.2.0
+ */
+ public function getSQL();
+
+ /**
+ * Sets a query parameter for the query being constructed.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->select('u')
+ * ->from('users', 'u')
+ * ->where('u.id = :user_id')
+ * ->setParameter(':user_id', 1);
+ * </code>
+ *
+ * @param string|integer $key The parameter position or name.
+ * @param mixed $value The parameter value.
+ * @param string|null|int $type One of the IQueryBuilder::PARAM_* constants.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ */
+ public function setParameter($key, $value, $type = null);
+
+ /**
+ * Sets a collection of query parameters for the query being constructed.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->select('u')
+ * ->from('users', 'u')
+ * ->where('u.id = :user_id1 OR u.id = :user_id2')
+ * ->setParameters(array(
+ * ':user_id1' => 1,
+ * ':user_id2' => 2
+ * ));
+ * </code>
+ *
+ * @param array $params The query parameters to set.
+ * @param array $types The query parameters types to set.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ */
+ public function setParameters(array $params, array $types = []);
+
+ /**
+ * Gets all defined query parameters for the query being constructed indexed by parameter index or name.
+ *
+ * @return array The currently defined query parameters indexed by parameter index or name.
+ * @since 8.2.0
+ */
+ public function getParameters();
+
+ /**
+ * Gets a (previously set) query parameter of the query being constructed.
+ *
+ * @param mixed $key The key (index or name) of the bound parameter.
+ *
+ * @return mixed The value of the bound parameter.
+ * @since 8.2.0
+ */
+ public function getParameter($key);
+
+ /**
+ * Gets all defined query parameter types for the query being constructed indexed by parameter index or name.
+ *
+ * @return array The currently defined query parameter types indexed by parameter index or name.
+ * @since 8.2.0
+ */
+ public function getParameterTypes();
+
+ /**
+ * Gets a (previously set) query parameter type of the query being constructed.
+ *
+ * @param mixed $key The key (index or name) of the bound parameter type.
+ *
+ * @return mixed The value of the bound parameter type.
+ * @since 8.2.0
+ */
+ public function getParameterType($key);
+
+ /**
+ * Sets the position of the first result to retrieve (the "offset").
+ *
+ * @param int $firstResult The first result to return.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ */
+ public function setFirstResult($firstResult);
+
+ /**
+ * Gets the position of the first result the query object was set to retrieve (the "offset").
+ * Returns 0 if {@link setFirstResult} was not applied to this QueryBuilder.
+ *
+ * @return int The position of the first result.
+ * @since 8.2.0
+ */
+ public function getFirstResult();
+
+ /**
+ * Sets the maximum number of results to retrieve (the "limit").
+ *
+ * @param int|null $maxResults The maximum number of results to retrieve.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ */
+ public function setMaxResults($maxResults);
+
+ /**
+ * Gets the maximum number of results the query object was set to retrieve (the "limit").
+ * Returns NULL if {@link setMaxResults} was not applied to this query builder.
+ *
+ * @return int|null The maximum number of results.
+ * @since 8.2.0
+ */
+ public function getMaxResults();
+
+ /**
+ * Specifies an item that is to be returned in the query result.
+ * Replaces any previously specified selections, if any.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->select('u.id', 'p.id')
+ * ->from('users', 'u')
+ * ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
+ * </code>
+ *
+ * @param mixed ...$selects The selection expressions.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $selects
+ */
+ public function select(...$selects);
+
+ /**
+ * Specifies an item that is to be returned with a different name in the query result.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->selectAlias('u.id', 'user_id')
+ * ->from('users', 'u')
+ * ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
+ * </code>
+ *
+ * @param mixed $select The selection expressions.
+ * @param string $alias The column alias used in the constructed query.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.1
+ *
+ * @psalm-taint-sink sql $select
+ * @psalm-taint-sink sql $alias
+ */
+ public function selectAlias($select, $alias);
+
+ /**
+ * Specifies an item that is to be returned uniquely in the query result.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->selectDistinct('type')
+ * ->from('users');
+ * </code>
+ *
+ * @param mixed $select The selection expressions.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 9.0.0
+ *
+ * @psalm-taint-sink sql $select
+ */
+ public function selectDistinct($select);
+
+ /**
+ * Adds an item that is to be returned in the query result.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->select('u.id')
+ * ->addSelect('p.id')
+ * ->from('users', 'u')
+ * ->leftJoin('u', 'phonenumbers', 'u.id = p.user_id');
+ * </code>
+ *
+ * @param mixed ...$select The selection expression.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $select
+ */
+ public function addSelect(...$select);
+
+ /**
+ * Turns the query being built into a bulk delete query that ranges over
+ * a certain table.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->delete('users')
+ * ->where('id = :user_id');
+ * ->setParameter(':user_id', 1);
+ * </code>
+ *
+ * @param string $delete The table whose rows are subject to the deletion.
+ * @param string $alias The table alias used in the constructed query.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ * @since 30.0.0 Alias is deprecated and will no longer be used with the next Doctrine/DBAL update
+ *
+ * @psalm-taint-sink sql $delete
+ */
+ public function delete($delete = null, $alias = null);
+
+ /**
+ * Turns the query being built into a bulk update query that ranges over
+ * a certain table
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->update('users')
+ * ->set('email', ':email')
+ * ->where('id = :user_id');
+ * ->setParameter(':user_id', 1);
+ * </code>
+ *
+ * @param string $update The table whose rows are subject to the update.
+ * @param string $alias The table alias used in the constructed query.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ * @since 30.0.0 Alias is deprecated and will no longer be used with the next Doctrine/DBAL update
+ *
+ * @psalm-taint-sink sql $update
+ */
+ public function update($update = null, $alias = null);
+
+ /**
+ * Turns the query being built into an insert query that inserts into
+ * a certain table
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->insert('users')
+ * ->values(
+ * array(
+ * 'name' => '?',
+ * 'password' => '?'
+ * )
+ * );
+ * </code>
+ *
+ * @param string $insert The table into which the rows should be inserted.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $insert
+ */
+ public function insert($insert = null);
+
+ /**
+ * Creates and adds a query root corresponding to the table identified by the
+ * given alias, forming a cartesian product with any existing query roots.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->select('u.id')
+ * ->from('users', 'u')
+ * </code>
+ *
+ * @param string|IQueryFunction $from The table.
+ * @param string|null $alias The alias of the table.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $from
+ */
+ public function from($from, $alias = null);
+
+ /**
+ * Creates and adds a join to the query.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->select('u.name')
+ * ->from('users', 'u')
+ * ->join('u', 'phonenumbers', 'p', 'p.is_primary = 1');
+ * </code>
+ *
+ * @param string $fromAlias The alias that points to a from clause.
+ * @param string $join The table name to join.
+ * @param string $alias The alias of the join table.
+ * @param string|ICompositeExpression|null $condition The condition for the join.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $fromAlias
+ * @psalm-taint-sink sql $join
+ * @psalm-taint-sink sql $alias
+ * @psalm-taint-sink sql $condition
+ */
+ public function join($fromAlias, $join, $alias, $condition = null);
+
+ /**
+ * Creates and adds a join to the query.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->select('u.name')
+ * ->from('users', 'u')
+ * ->innerJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
+ * </code>
+ *
+ * @param string $fromAlias The alias that points to a from clause.
+ * @param string $join The table name to join.
+ * @param string $alias The alias of the join table.
+ * @param string|ICompositeExpression|null $condition The condition for the join.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $fromAlias
+ * @psalm-taint-sink sql $join
+ * @psalm-taint-sink sql $alias
+ * @psalm-taint-sink sql $condition
+ */
+ public function innerJoin($fromAlias, $join, $alias, $condition = null);
+
+ /**
+ * Creates and adds a left join to the query.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->select('u.name')
+ * ->from('users', 'u')
+ * ->leftJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
+ * </code>
+ *
+ * @param string $fromAlias The alias that points to a from clause.
+ * @param string|IQueryFunction $join The table name to join.
+ * @param string $alias The alias of the join table.
+ * @param string|ICompositeExpression|null $condition The condition for the join.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ * @since 30.0.0 Allow passing IQueryFunction as parameter for `$join` to allow join with a sub-query.
+ *
+ * @psalm-taint-sink sql $fromAlias
+ * @psalm-taint-sink sql $join
+ * @psalm-taint-sink sql $alias
+ * @psalm-taint-sink sql $condition
+ */
+ public function leftJoin($fromAlias, $join, $alias, $condition = null);
+
+ /**
+ * Creates and adds a right join to the query.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->select('u.name')
+ * ->from('users', 'u')
+ * ->rightJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
+ * </code>
+ *
+ * @param string $fromAlias The alias that points to a from clause.
+ * @param string $join The table name to join.
+ * @param string $alias The alias of the join table.
+ * @param string|ICompositeExpression|null $condition The condition for the join.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $fromAlias
+ * @psalm-taint-sink sql $join
+ * @psalm-taint-sink sql $alias
+ * @psalm-taint-sink sql $condition
+ */
+ public function rightJoin($fromAlias, $join, $alias, $condition = null);
+
+ /**
+ * Sets a new value for a column in a bulk update query.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->update('users', 'u')
+ * ->set('u.password', md5('password'))
+ * ->where('u.id = ?');
+ * </code>
+ *
+ * @param string $key The column to set.
+ * @param ILiteral|IParameter|IQueryFunction|string $value The value, expression, placeholder, etc.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $key
+ * @psalm-taint-sink sql $value
+ */
+ public function set($key, $value);
+
+ /**
+ * Specifies one or more restrictions to the query result.
+ * Replaces any previously specified restrictions, if any.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->select('u.name')
+ * ->from('users', 'u')
+ * ->where('u.id = ?');
+ *
+ * // You can optionally programmatically build and/or expressions
+ * $qb = $conn->getQueryBuilder();
+ *
+ * $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'))
+ * ->where($or);
+ * </code>
+ *
+ * @param mixed $predicates The restriction predicates.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $predicates
+ */
+ public function where(...$predicates);
+
+ /**
+ * Adds one or more restrictions to the query results, forming a logical
+ * conjunction with any previously specified restrictions.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->select('u')
+ * ->from('users', 'u')
+ * ->where('u.username LIKE ?')
+ * ->andWhere('u.is_active = 1');
+ * </code>
+ *
+ * @param mixed ...$where The query restrictions.
+ *
+ * @return $this This QueryBuilder instance.
+ *
+ * @see where()
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $where
+ */
+ public function andWhere(...$where);
+
+ /**
+ * Adds one or more restrictions to the query results, forming a logical
+ * disjunction with any previously specified restrictions.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->select('u.name')
+ * ->from('users', 'u')
+ * ->where('u.id = 1')
+ * ->orWhere('u.id = 2');
+ * </code>
+ *
+ * @param mixed ...$where The WHERE statement.
+ *
+ * @return $this This QueryBuilder instance.
+ *
+ * @see where()
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $where
+ */
+ public function orWhere(...$where);
+
+ /**
+ * Specifies a grouping over the results of the query.
+ * Replaces any previously specified groupings, if any.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->select('u.name')
+ * ->from('users', 'u')
+ * ->groupBy('u.id');
+ * </code>
+ *
+ * @param mixed ...$groupBys The grouping expression.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $groupBys
+ */
+ public function groupBy(...$groupBys);
+
+ /**
+ * Adds a grouping expression to the query.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->select('u.name')
+ * ->from('users', 'u')
+ * ->groupBy('u.lastLogin');
+ * ->addGroupBy('u.createdAt')
+ * </code>
+ *
+ * @param mixed ...$groupBy The grouping expression.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $groupby
+ */
+ public function addGroupBy(...$groupBy);
+
+ /**
+ * Sets a value for a column in an insert query.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->insert('users')
+ * ->values(
+ * array(
+ * 'name' => '?'
+ * )
+ * )
+ * ->setValue('password', '?');
+ * </code>
+ *
+ * @param string $column The column into which the value should be inserted.
+ * @param IParameter|string $value The value that should be inserted into the column.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $column
+ * @psalm-taint-sink sql $value
+ */
+ public function setValue($column, $value);
+
+ /**
+ * Specifies values for an insert query indexed by column names.
+ * Replaces any previous values, if any.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->insert('users')
+ * ->values(
+ * array(
+ * 'name' => '?',
+ * 'password' => '?'
+ * )
+ * );
+ * </code>
+ *
+ * @param array $values The values to specify for the insert query indexed by column names.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $values
+ */
+ public function values(array $values);
+
+ /**
+ * Specifies a restriction over the groups of the query.
+ * Replaces any previous having restrictions, if any.
+ *
+ * @param mixed ...$having The restriction over the groups.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $having
+ */
+ public function having(...$having);
+
+ /**
+ * Adds a restriction over the groups of the query, forming a logical
+ * conjunction with any existing having restrictions.
+ *
+ * @param mixed ...$having The restriction to append.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $andHaving
+ */
+ public function andHaving(...$having);
+
+ /**
+ * Adds a restriction over the groups of the query, forming a logical
+ * disjunction with any existing having restrictions.
+ *
+ * @param mixed ...$having The restriction to add.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $having
+ */
+ public function orHaving(...$having);
+
+ /**
+ * Specifies an ordering for the query results.
+ * Replaces any previously specified orderings, if any.
+ *
+ * @param string|IQueryFunction|ILiteral|IParameter $sort The ordering expression.
+ * @param string $order The ordering direction.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $sort
+ * @psalm-taint-sink sql $order
+ */
+ public function orderBy($sort, $order = null);
+
+ /**
+ * Adds an ordering to the query results.
+ *
+ * @param string|ILiteral|IParameter|IQueryFunction $sort The ordering expression.
+ * @param string $order The ordering direction.
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $sort
+ * @psalm-taint-sink sql $order
+ */
+ public function addOrderBy($sort, $order = null);
+
+ /**
+ * Gets a query part by its name.
+ *
+ * @param string $queryPartName
+ *
+ * @return mixed
+ * @since 8.2.0
+ * @deprecated 30.0.0 This function is going to be removed with the next Doctrine/DBAL update
+ * and we can not fix this in our wrapper. Please track the details you need, outside the object.
+ */
+ public function getQueryPart($queryPartName);
+
+ /**
+ * Gets all query parts.
+ *
+ * @return array
+ * @since 8.2.0
+ * @deprecated 30.0.0 This function is going to be removed with the next Doctrine/DBAL update
+ * and we can not fix this in our wrapper. Please track the details you need, outside the object.
+ */
+ public function getQueryParts();
+
+ /**
+ * Resets SQL parts.
+ *
+ * @param array|null $queryPartNames
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ * @deprecated 30.0.0 This function is going to be removed with the next Doctrine/DBAL update
+ * and we can not fix this in our wrapper. Please create a new IQueryBuilder instead.
+ */
+ public function resetQueryParts($queryPartNames = null);
+
+ /**
+ * Resets a single SQL part.
+ *
+ * @param string $queryPartName
+ *
+ * @return $this This QueryBuilder instance.
+ * @since 8.2.0
+ * @deprecated 30.0.0 This function is going to be removed with the next Doctrine/DBAL update
+ * and we can not fix this in our wrapper. Please create a new IQueryBuilder instead.
+ */
+ public function resetQueryPart($queryPartName);
+
+ /**
+ * Creates a new named parameter and bind the value $value to it.
+ *
+ * This method provides a shortcut for PDOStatement::bindValue
+ * when using prepared statements.
+ *
+ * The parameter $value specifies the value that you want to bind. If
+ * $placeholder is not provided bindValue() will automatically create a
+ * placeholder for you. An automatic placeholder will be of the name
+ * ':dcValue1', ':dcValue2' etc.
+ *
+ * For more information see {@link https://www.php.net/pdostatement-bindparam}
+ *
+ * Example:
+ * <code>
+ * $value = 2;
+ * $q->eq( 'id', $q->bindValue( $value ) );
+ * $stmt = $q->executeQuery(); // executed with 'id = 2'
+ * </code>
+ *
+ * @license New BSD License
+ * @link http://www.zetacomponents.org
+ *
+ * @param mixed $value
+ * @param self::PARAM_* $type
+ * @param string $placeHolder The name to bind with. The string must start with a colon ':'.
+ *
+ * @return IParameter
+ * @since 8.2.0
+ *
+ * @psalm-taint-escape sql
+ */
+ public function createNamedParameter($value, $type = self::PARAM_STR, $placeHolder = null);
+
+ /**
+ * Creates a new positional parameter and bind the given value to it.
+ *
+ * Attention: If you are using positional parameters with the query builder you have
+ * to be very careful to bind all parameters in the order they appear in the SQL
+ * statement , otherwise they get bound in the wrong order which can lead to serious
+ * bugs in your code.
+ *
+ * Example:
+ * <code>
+ * $qb = $conn->getQueryBuilder();
+ * $qb->select('u.*')
+ * ->from('users', 'u')
+ * ->where('u.username = ' . $qb->createPositionalParameter('Foo', IQueryBuilder::PARAM_STR))
+ * ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', IQueryBuilder::PARAM_STR))
+ * </code>
+ *
+ * @param mixed $value
+ * @param self::PARAM_* $type
+ *
+ * @return IParameter
+ * @since 8.2.0
+ *
+ * @psalm-taint-escape sql
+ */
+ public function createPositionalParameter($value, $type = self::PARAM_STR);
+
+ /**
+ * Creates a new parameter
+ *
+ * Example:
+ * <code>
+ * $qb = $conn->getQueryBuilder();
+ * $qb->select('u.*')
+ * ->from('users', 'u')
+ * ->where('u.username = ' . $qb->createParameter('name'))
+ * ->setParameter('name', 'Bar', IQueryBuilder::PARAM_STR))
+ * </code>
+ *
+ * @param string $name
+ *
+ * @return IParameter
+ * @since 8.2.0
+ *
+ * @psalm-taint-escape sql
+ */
+ public function createParameter($name);
+
+ /**
+ * Creates a new function
+ *
+ * Attention: Column names inside the call have to be quoted before hand
+ *
+ * Example:
+ * <code>
+ * $qb = $conn->getQueryBuilder();
+ * $qb->select($qb->createFunction('COUNT(*)'))
+ * ->from('users', 'u')
+ * echo $qb->getSQL(); // SELECT COUNT(*) FROM `users` u
+ * </code>
+ * <code>
+ * $qb = $conn->getQueryBuilder();
+ * $qb->select($qb->createFunction('COUNT(`column`)'))
+ * ->from('users', 'u')
+ * echo $qb->getSQL(); // SELECT COUNT(`column`) FROM `users` u
+ * </code>
+ *
+ * @param string $call
+ *
+ * @return IQueryFunction
+ * @since 8.2.0
+ *
+ * @psalm-taint-sink sql $call
+ */
+ public function createFunction($call);
+
+ /**
+ * Used to get the id of the last inserted element
+ * @return int
+ * @throws \BadMethodCallException When being called before an insert query has been run.
+ * @since 9.0.0
+ */
+ public function getLastInsertId(): int;
+
+ /**
+ * Returns the table name quoted and with database prefix as needed by the implementation.
+ * If a query function is passed the function is casted to string,
+ * this allows passing functions as sub-queries for join expression.
+ *
+ * @param string|IQueryFunction $table
+ * @return string
+ * @since 9.0.0
+ * @since 24.0.0 accepts IQueryFunction as parameter
+ */
+ public function getTableName($table);
+
+ /**
+ * Returns the table name with database prefix as needed by the implementation
+ *
+ * @param string $table
+ * @return string
+ * @since 30.0.0
+ */
+ public function prefixTableName(string $table): string;
+
+ /**
+ * Returns the column name quoted and with table alias prefix as needed by the implementation
+ *
+ * @param string $column
+ * @param string $tableAlias
+ * @return string
+ * @since 9.0.0
+ */
+ public function getColumnName($column, $tableAlias = '');
+
+ /**
+ * Provide a hint for the shard key for queries where this can't be detected otherwise
+ *
+ * @param string $column
+ * @param mixed $value
+ * @return $this
+ * @since 30.0.0
+ */
+ public function hintShardKey(string $column, mixed $value, bool $overwrite = false): self;
+
+ /**
+ * Set the query to run across all shards if sharding is enabled.
+ *
+ * @return $this
+ * @since 30.0.0
+ */
+ public function runAcrossAllShards(): self;
+
+ /**
+ * Get a list of column names that are expected in the query output
+ *
+ * @return array
+ * @since 30.0.0
+ */
+ public function getOutputColumns(): array;
+}
diff --git a/lib/public/DB/QueryBuilder/IQueryFunction.php b/lib/public/DB/QueryBuilder/IQueryFunction.php
new file mode 100644
index 00000000000..e19fc2959db
--- /dev/null
+++ b/lib/public/DB/QueryBuilder/IQueryFunction.php
@@ -0,0 +1,19 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+namespace OCP\DB\QueryBuilder;
+
+/**
+ * @since 8.2.0
+ */
+interface IQueryFunction {
+ /**
+ * @return string
+ * @since 8.2.0
+ */
+ public function __toString();
+}
diff --git a/lib/public/DB/QueryBuilder/Sharded/IShardMapper.php b/lib/public/DB/QueryBuilder/Sharded/IShardMapper.php
new file mode 100644
index 00000000000..fa00fb68719
--- /dev/null
+++ b/lib/public/DB/QueryBuilder/Sharded/IShardMapper.php
@@ -0,0 +1,25 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2024 Robin Appelman <robin@icewind.nl>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCP\DB\QueryBuilder\Sharded;
+
+/**
+ * Implementation of logic of mapping shard keys to shards.
+ * @since 30.0.0
+ */
+interface IShardMapper {
+ /**
+ * Get the shard number for a given shard key and total shard count
+ *
+ * @param int $key
+ * @param int $count
+ * @return int
+ * @since 30.0.0
+ */
+ public function getShardForKey(int $key, int $count): int;
+}
diff --git a/lib/public/DB/Types.php b/lib/public/DB/Types.php
new file mode 100644
index 00000000000..969ec5e6611
--- /dev/null
+++ b/lib/public/DB/Types.php
@@ -0,0 +1,179 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\DB;
+
+/**
+ * Database types supported by Nextcloud's DBs
+ *
+ * Use these constants instead of \Doctrine\DBAL\Types\Type or \Doctrine\DBAL\Types\Types
+ *
+ * @since 21.0.0
+ */
+final class Types {
+ /**
+ * @var string
+ * @since 21.0.0
+ */
+ public const BIGINT = 'bigint';
+
+ /**
+ * @var string
+ * @since 21.0.0
+ */
+ public const BINARY = 'binary';
+
+ /**
+ * @var string
+ * @since 21.0.0
+ */
+ public const BLOB = 'blob';
+
+ /**
+ * @var string
+ * @since 21.0.0
+ */
+ public const BOOLEAN = 'boolean';
+
+ /**
+ * A datetime instance with only the date set.
+ * This will be (de)serialized into a \DateTime instance,
+ * it is recommended to instead use the `DATE_IMMUTABLE` instead.
+ *
+ * Warning: When deserialized the timezone will be set to UTC.
+ * @var string
+ * @since 21.0.0
+ */
+ public const DATE = 'date';
+
+ /**
+ * An immutable datetime instance with only the date set.
+ * This will be (de)serialized into a \DateTimeImmutable instance,
+ * It is recommended to use this over the `DATE` type because
+ * out `Entity` class works detecting changes through the setter,
+ * changes on mutable objects can not be detected.
+ *
+ * Warning: When deserialized the timezone will be set to UTC.
+ * @var string
+ * @since 31.0.0
+ */
+ public const DATE_IMMUTABLE = 'date_immutable';
+
+ /**
+ * A datetime instance with date and time support.
+ * This will be (de)serialized into a \DateTime instance,
+ * it is recommended to instead use the `DATETIME_IMMUTABLE` instead.
+ *
+ * Warning: When deserialized the timezone will be set to UTC.
+ * @var string
+ * @since 21.0.0
+ */
+ public const DATETIME = 'datetime';
+
+ /**
+ * An immutable datetime instance with date and time set.
+ * This will be (de)serialized into a \DateTimeImmutable instance,
+ * It is recommended to use this over the `DATETIME` type because
+ * out `Entity` class works detecting changes through the setter,
+ * changes on mutable objects can not be detected.
+ *
+ * Warning: When deserialized the timezone will be set to UTC.
+ * @var string
+ * @since 31.0.0
+ */
+ public const DATETIME_IMMUTABLE = 'datetime_immutable';
+
+
+ /**
+ * A datetime instance with timezone support
+ * This will be (de)serialized into a \DateTime instance,
+ * it is recommended to instead use the `DATETIME_TZ_IMMUTABLE` instead.
+ *
+ * @var string
+ * @since 31.0.0
+ */
+ public const DATETIME_TZ = 'datetimetz';
+
+ /**
+ * An immutable timezone aware datetime instance with date and time set.
+ * This will be (de)serialized into a \DateTimeImmutable instance,
+ * It is recommended to use this over the `DATETIME_TZ` type because
+ * out `Entity` class works detecting changes through the setter,
+ * changes on mutable objects can not be detected.
+ *
+ * @var string
+ * @since 31.0.0
+ */
+ public const DATETIME_TZ_IMMUTABLE = 'datetimetz_immutable';
+
+ /**
+ * @var string
+ * @since 21.0.0
+ */
+ public const DECIMAL = 'decimal';
+
+ /**
+ * @var string
+ * @since 21.0.0
+ */
+ public const FLOAT = 'float';
+
+ /**
+ * @var string
+ * @since 21.0.0
+ */
+ public const INTEGER = 'integer';
+
+ /**
+ * @var string
+ * @since 21.0.0
+ */
+ public const SMALLINT = 'smallint';
+
+ /**
+ * @var string
+ * @since 21.0.0
+ */
+ public const STRING = 'string';
+
+ /**
+ * @var string
+ * @since 21.0.0
+ */
+ public const TEXT = 'text';
+
+ /**
+ * A datetime instance with only the time set.
+ * This will be (de)serialized into a \DateTime instance,
+ * it is recommended to instead use the `TIME_IMMUTABLE` instead.
+ *
+ * Warning: When deserialized the timezone will be set to UTC.
+ * @var string
+ * @since 21.0.0
+ */
+ public const TIME = 'time';
+
+ /**
+ * A datetime instance with only the time set.
+ * This will be (de)serialized into a \DateTime instance.
+ *
+ * It is recommended to use this over the `DATETIME_TZ` type because
+ * out `Entity` class works detecting changes through the setter,
+ * changes on mutable objects can not be detected.
+ *
+ * @var string
+ * @since 31.0.0
+ */
+ public const TIME_IMMUTABLE = 'time_immutable';
+
+ /**
+ * @var string
+ * @since 24.0.0
+ */
+ public const JSON = 'json';
+}