aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/DB/QueryBuilder/ExtendedQueryBuilder.php
blob: c40cadfbdb5f63987bd9778dd37243dce0954cd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php

declare(strict_types=1);
/**
 * SPDX-FileCopyrightText: 2024 Robin Appelman <robin@icewind.nl>
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace OC\DB\QueryBuilder;

use OC\DB\Exceptions\DbalException;
use OCP\DB\IResult;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;

/**
 * Base class for creating classes that extend the builtin query builder
 */
abstract class ExtendedQueryBuilder implements IQueryBuilder {
	public function __construct(
		protected IQueryBuilder $builder,
	) {
	}

	public function automaticTablePrefix($enabled) {
		$this->builder->automaticTablePrefix($enabled);
		return $this;
	}

	public function expr() {
		return $this->builder->expr();
	}

	public function func() {
		return $this->builder->func();
	}

	public function getType() {
		return $this->builder->getType();
	}

	public function getConnection() {
		return $this->builder->getConnection();
	}

	public function getState() {
		return $this->builder->getState();
	}

	public function execute(?IDBConnection $connection = null) {
		try {
			if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::SELECT) {
				return $this->executeQuery($connection);
			} else {
				return $this->executeStatement($connection);
			}
		} catch (DBALException $e) {
			// `IQueryBuilder->execute` never wrapped the exception, but `executeQuery` and `executeStatement` do
			/** @var \Doctrine\DBAL\Exception $previous */
			$previous = $e->getPrevious();
			throw $previous;
		}
	}

	public function getSQL() {
		return $this->builder->getSQL();
	}

	public function setParameter($key, $value, $type = null) {
		$this->builder->setParameter($key, $value, $type);
		return $this;
	}

	public function setParameters(array $params, array $types = []) {
		$this->builder->setParameters($params, $types);
		return $this;
	}

	public function getParameters() {
		return $this->builder->getParameters();
	}

	public function getParameter($key) {
		return $this->builder->getParameter($key);
	}

	public function getParameterTypes() {
		return $this->builder->getParameterTypes();
	}

	public function getParameterType($key) {
		return $this->builder->getParameterType($key);
	}

	public function setFirstResult($firstResult) {
		$this->builder->setFirstResult($firstResult);
		return $this;
	}

	public function getFirstResult() {
		return $this->builder->getFirstResult();
	}

	public function setMaxResults($maxResults) {
		$this->builder->setMaxResults($maxResults);
		return $this;
	}

	public function getMaxResults() {
		return $this->builder->getMaxResults();
	}

	public function select(...$selects) {
		$this->builder->select(...$selects);
		return $this;
	}

	public function selectAlias($select, $alias) {
		$this->builder->selectAlias($select, $alias);
		return $this;
	}

	public function selectDistinct($select) {
		$this->builder->selectDistinct($select);
		return $this;
	}

	public function addSelect(...$select) {
		$this->builder->addSelect(...$select);
		return $this;
	}

	public function delete($delete = null, $alias = null) {
		$this->builder->delete($delete, $alias);
		return $this;
	}

	public function update($update = null, $alias = null) {
		$this->builder->update($update, $alias);
		return $this;
	}

	public function insert($insert = null) {
		$this->builder->insert($insert);
		return $this;
	}

	public function from($from, $alias = null) {
		$this->builder->from($from, $alias);
		return $this;
	}

	public function join($fromAlias, $join, $alias, $condition = null) {
		$this->builder->join($fromAlias, $join, $alias, $condition);
		return $this;
	}

	public function innerJoin($fromAlias, $join, $alias, $condition = null) {
		$this->builder->innerJoin($fromAlias, $join, $alias, $condition);
		return $this;
	}

	public function leftJoin($fromAlias, $join, $alias, $condition = null) {
		$this->builder->leftJoin($fromAlias, $join, $alias, $condition);
		return $this;
	}

	public function rightJoin($fromAlias, $join, $alias, $condition = null) {
		$this->builder->rightJoin($fromAlias, $join, $alias, $condition);
		return $this;
	}

	public function set($key, $value) {
		$this->builder->set($key, $value);
		return $this;
	}

	public function where(...$predicates) {
		$this->builder->where(...$predicates);
		return $this;
	}

	public function andWhere(...$where) {
		$this->builder->andWhere(...$where);
		return $this;
	}

	public function orWhere(...$where) {
		$this->builder->orWhere(...$where);
		return $this;
	}

	public function groupBy(...$groupBys) {
		$this->builder->groupBy(...$groupBys);
		return $this;
	}

	public function addGroupBy(...$groupBy) {
		$this->builder->addGroupBy(...$groupBy);
		return $this;
	}

	public function setValue($column, $value) {
		$this->builder->setValue($column, $value);
		return $this;
	}

	public function values(array $values) {
		$this->builder->values($values);
		return $this;
	}

	public function having(...$having) {
		$this->builder->having(...$having);
		return $this;
	}

	public function andHaving(...$having) {
		$this->builder->andHaving(...$having);
		return $this;
	}

	public function orHaving(...$having) {
		$this->builder->orHaving(...$having);
		return $this;
	}

	public function orderBy($sort, $order = null) {
		$this->builder->orderBy($sort, $order);
		return $this;
	}

	public function addOrderBy($sort, $order = null) {
		$this->builder->addOrderBy($sort, $order);
		return $this;
	}

	public function getQueryPart($queryPartName) {
		return $this->builder->getQueryPart($queryPartName);
	}

	public function getQueryParts() {
		return $this->builder->getQueryParts();
	}

	public function resetQueryParts($queryPartNames = null) {
		$this->builder->resetQueryParts($queryPartNames);
		return $this;
	}

	public function resetQueryPart($queryPartName) {
		$this->builder->resetQueryPart($queryPartName);
		return $this;
	}

	public function createNamedParameter($value, $type = self::PARAM_STR, $placeHolder = null) {
		return $this->builder->createNamedParameter($value, $type, $placeHolder);
	}

	public function createPositionalParameter($value, $type = self::PARAM_STR) {
		return $this->builder->createPositionalParameter($value, $type);
	}

	public function createParameter($name) {
		return $this->builder->createParameter($name);
	}

	public function createFunction($call) {
		return $this->builder->createFunction($call);
	}

	public function getLastInsertId(): int {
		return $this->builder->getLastInsertId();
	}

	public function getTableName($table) {
		return $this->builder->getTableName($table);
	}

	public function getColumnName($column, $tableAlias = '') {
		return $this->builder->getColumnName($column, $tableAlias);
	}

	public function executeQuery(?IDBConnection $connection = null): IResult {
		return $this->builder->executeQuery($connection);
	}

	public function executeStatement(?IDBConnection $connection = null): int {
		return $this->builder->executeStatement($connection);
	}

	public function hintShardKey(string $column, mixed $value, bool $overwrite = false) {
		$this->builder->hintShardKey($column, $value, $overwrite);
		return $this;
	}

	public function runAcrossAllShards() {
		$this->builder->runAcrossAllShards();
		return $this;
	}

	public function getOutputColumns(): array {
		return $this->builder->getOutputColumns();
	}

	public function prefixTableName(string $table): string {
		return $this->builder->prefixTableName($table);
	}
}