Passed
Push — master ( 6e8e34...fb4e98 )
by Morris
12:15 queued 12s
created
lib/private/DB/QueryBuilder/QueryBuilder.php 1 patch
Indentation   +1171 added lines, -1171 removed lines patch added patch discarded remove patch
@@ -49,1175 +49,1175 @@
 block discarded – undo
49 49
 
50 50
 class QueryBuilder implements IQueryBuilder {
51 51
 
52
-	/** @var \OCP\IDBConnection */
53
-	private $connection;
54
-
55
-	/** @var SystemConfig */
56
-	private $systemConfig;
57
-
58
-	/** @var ILogger */
59
-	private $logger;
60
-
61
-	/** @var \Doctrine\DBAL\Query\QueryBuilder */
62
-	private $queryBuilder;
63
-
64
-	/** @var QuoteHelper */
65
-	private $helper;
66
-
67
-	/** @var bool */
68
-	private $automaticTablePrefix = true;
69
-
70
-	/** @var string */
71
-	protected $lastInsertedTable;
72
-
73
-	/**
74
-	 * Initializes a new QueryBuilder.
75
-	 *
76
-	 * @param IDBConnection $connection
77
-	 * @param SystemConfig $systemConfig
78
-	 * @param ILogger $logger
79
-	 */
80
-	public function __construct(IDBConnection $connection, SystemConfig $systemConfig, ILogger $logger) {
81
-		$this->connection = $connection;
82
-		$this->systemConfig = $systemConfig;
83
-		$this->logger = $logger;
84
-		$this->queryBuilder = new \Doctrine\DBAL\Query\QueryBuilder($this->connection);
85
-		$this->helper = new QuoteHelper();
86
-	}
87
-
88
-	/**
89
-	 * Enable/disable automatic prefixing of table names with the oc_ prefix
90
-	 *
91
-	 * @param bool $enabled If set to true table names will be prefixed with the
92
-	 * owncloud database prefix automatically.
93
-	 * @since 8.2.0
94
-	 */
95
-	public function automaticTablePrefix($enabled) {
96
-		$this->automaticTablePrefix = (bool) $enabled;
97
-	}
98
-
99
-	/**
100
-	 * Gets an ExpressionBuilder used for object-oriented construction of query expressions.
101
-	 * This producer method is intended for convenient inline usage. Example:
102
-	 *
103
-	 * <code>
104
-	 *     $qb = $conn->getQueryBuilder()
105
-	 *         ->select('u')
106
-	 *         ->from('users', 'u')
107
-	 *         ->where($qb->expr()->eq('u.id', 1));
108
-	 * </code>
109
-	 *
110
-	 * For more complex expression construction, consider storing the expression
111
-	 * builder object in a local variable.
112
-	 *
113
-	 * @return \OCP\DB\QueryBuilder\IExpressionBuilder
114
-	 */
115
-	public function expr() {
116
-		if ($this->connection instanceof OracleConnection) {
117
-			return new OCIExpressionBuilder($this->connection, $this);
118
-		} elseif ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
119
-			return new PgSqlExpressionBuilder($this->connection, $this);
120
-		} elseif ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
121
-			return new MySqlExpressionBuilder($this->connection, $this);
122
-		} elseif ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
123
-			return new SqliteExpressionBuilder($this->connection, $this);
124
-		} else {
125
-			return new ExpressionBuilder($this->connection, $this);
126
-		}
127
-	}
128
-
129
-	/**
130
-	 * Gets an FunctionBuilder used for object-oriented construction of query functions.
131
-	 * This producer method is intended for convenient inline usage. Example:
132
-	 *
133
-	 * <code>
134
-	 *     $qb = $conn->getQueryBuilder()
135
-	 *         ->select('u')
136
-	 *         ->from('users', 'u')
137
-	 *         ->where($qb->fun()->md5('u.id'));
138
-	 * </code>
139
-	 *
140
-	 * For more complex function construction, consider storing the function
141
-	 * builder object in a local variable.
142
-	 *
143
-	 * @return \OCP\DB\QueryBuilder\IFunctionBuilder
144
-	 */
145
-	public function func() {
146
-		if ($this->connection instanceof OracleConnection) {
147
-			return new OCIFunctionBuilder($this->helper);
148
-		} elseif ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
149
-			return new SqliteFunctionBuilder($this->helper);
150
-		} elseif ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
151
-			return new PgSqlFunctionBuilder($this->helper);
152
-		} else {
153
-			return new FunctionBuilder($this->helper);
154
-		}
155
-	}
156
-
157
-	/**
158
-	 * Gets the type of the currently built query.
159
-	 *
160
-	 * @return integer
161
-	 */
162
-	public function getType() {
163
-		return $this->queryBuilder->getType();
164
-	}
165
-
166
-	/**
167
-	 * Gets the associated DBAL Connection for this query builder.
168
-	 *
169
-	 * @return \OCP\IDBConnection
170
-	 */
171
-	public function getConnection() {
172
-		return $this->connection;
173
-	}
174
-
175
-	/**
176
-	 * Gets the state of this query builder instance.
177
-	 *
178
-	 * @return integer Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.
179
-	 */
180
-	public function getState() {
181
-		return $this->queryBuilder->getState();
182
-	}
183
-
184
-	/**
185
-	 * Executes this query using the bound parameters and their types.
186
-	 *
187
-	 * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate}
188
-	 * for insert, update and delete statements.
189
-	 *
190
-	 * @return \Doctrine\DBAL\Driver\Statement|int
191
-	 */
192
-	public function execute() {
193
-		if ($this->systemConfig->getValue('log_query', false)) {
194
-			$params = [];
195
-			foreach ($this->getParameters() as $placeholder => $value) {
196
-				if (is_array($value)) {
197
-					$params[] = $placeholder . ' => (\'' . implode('\', \'', $value) . '\')';
198
-				} else {
199
-					$params[] = $placeholder . ' => \'' . $value . '\'';
200
-				}
201
-			}
202
-			if (empty($params)) {
203
-				$this->logger->debug('DB QueryBuilder: \'{query}\'', [
204
-					'query' => $this->getSQL(),
205
-					'app' => 'core',
206
-				]);
207
-			} else {
208
-				$this->logger->debug('DB QueryBuilder: \'{query}\' with parameters: {params}', [
209
-					'query' => $this->getSQL(),
210
-					'params' => implode(', ', $params),
211
-					'app' => 'core',
212
-				]);
213
-			}
214
-		}
215
-
216
-		return $this->queryBuilder->execute();
217
-	}
218
-
219
-	/**
220
-	 * Gets the complete SQL string formed by the current specifications of this QueryBuilder.
221
-	 *
222
-	 * <code>
223
-	 *     $qb = $conn->getQueryBuilder()
224
-	 *         ->select('u')
225
-	 *         ->from('User', 'u')
226
-	 *     echo $qb->getSQL(); // SELECT u FROM User u
227
-	 * </code>
228
-	 *
229
-	 * @return string The SQL query string.
230
-	 */
231
-	public function getSQL() {
232
-		return $this->queryBuilder->getSQL();
233
-	}
234
-
235
-	/**
236
-	 * Sets a query parameter for the query being constructed.
237
-	 *
238
-	 * <code>
239
-	 *     $qb = $conn->getQueryBuilder()
240
-	 *         ->select('u')
241
-	 *         ->from('users', 'u')
242
-	 *         ->where('u.id = :user_id')
243
-	 *         ->setParameter(':user_id', 1);
244
-	 * </code>
245
-	 *
246
-	 * @param string|integer $key The parameter position or name.
247
-	 * @param mixed $value The parameter value.
248
-	 * @param string|null|int $type One of the IQueryBuilder::PARAM_* constants.
249
-	 *
250
-	 * @return $this This QueryBuilder instance.
251
-	 */
252
-	public function setParameter($key, $value, $type = null) {
253
-		$this->queryBuilder->setParameter($key, $value, $type);
254
-
255
-		return $this;
256
-	}
257
-
258
-	/**
259
-	 * Sets a collection of query parameters for the query being constructed.
260
-	 *
261
-	 * <code>
262
-	 *     $qb = $conn->getQueryBuilder()
263
-	 *         ->select('u')
264
-	 *         ->from('users', 'u')
265
-	 *         ->where('u.id = :user_id1 OR u.id = :user_id2')
266
-	 *         ->setParameters(array(
267
-	 *             ':user_id1' => 1,
268
-	 *             ':user_id2' => 2
269
-	 *         ));
270
-	 * </code>
271
-	 *
272
-	 * @param array $params The query parameters to set.
273
-	 * @param array $types The query parameters types to set.
274
-	 *
275
-	 * @return $this This QueryBuilder instance.
276
-	 */
277
-	public function setParameters(array $params, array $types = []) {
278
-		$this->queryBuilder->setParameters($params, $types);
279
-
280
-		return $this;
281
-	}
282
-
283
-	/**
284
-	 * Gets all defined query parameters for the query being constructed indexed by parameter index or name.
285
-	 *
286
-	 * @return array The currently defined query parameters indexed by parameter index or name.
287
-	 */
288
-	public function getParameters() {
289
-		return $this->queryBuilder->getParameters();
290
-	}
291
-
292
-	/**
293
-	 * Gets a (previously set) query parameter of the query being constructed.
294
-	 *
295
-	 * @param mixed $key The key (index or name) of the bound parameter.
296
-	 *
297
-	 * @return mixed The value of the bound parameter.
298
-	 */
299
-	public function getParameter($key) {
300
-		return $this->queryBuilder->getParameter($key);
301
-	}
302
-
303
-	/**
304
-	 * Gets all defined query parameter types for the query being constructed indexed by parameter index or name.
305
-	 *
306
-	 * @return array The currently defined query parameter types indexed by parameter index or name.
307
-	 */
308
-	public function getParameterTypes() {
309
-		return $this->queryBuilder->getParameterTypes();
310
-	}
311
-
312
-	/**
313
-	 * Gets a (previously set) query parameter type of the query being constructed.
314
-	 *
315
-	 * @param mixed $key The key (index or name) of the bound parameter type.
316
-	 *
317
-	 * @return mixed The value of the bound parameter type.
318
-	 */
319
-	public function getParameterType($key) {
320
-		return $this->queryBuilder->getParameterType($key);
321
-	}
322
-
323
-	/**
324
-	 * Sets the position of the first result to retrieve (the "offset").
325
-	 *
326
-	 * @param integer $firstResult The first result to return.
327
-	 *
328
-	 * @return $this This QueryBuilder instance.
329
-	 */
330
-	public function setFirstResult($firstResult) {
331
-		$this->queryBuilder->setFirstResult($firstResult);
332
-
333
-		return $this;
334
-	}
335
-
336
-	/**
337
-	 * Gets the position of the first result the query object was set to retrieve (the "offset").
338
-	 * Returns NULL if {@link setFirstResult} was not applied to this QueryBuilder.
339
-	 *
340
-	 * @return integer The position of the first result.
341
-	 */
342
-	public function getFirstResult() {
343
-		return $this->queryBuilder->getFirstResult();
344
-	}
345
-
346
-	/**
347
-	 * Sets the maximum number of results to retrieve (the "limit").
348
-	 *
349
-	 * NOTE: Setting max results to "0" will cause mixed behaviour. While most
350
-	 * of the databases will just return an empty result set, Oracle will return
351
-	 * all entries.
352
-	 *
353
-	 * @param integer $maxResults The maximum number of results to retrieve.
354
-	 *
355
-	 * @return $this This QueryBuilder instance.
356
-	 */
357
-	public function setMaxResults($maxResults) {
358
-		$this->queryBuilder->setMaxResults($maxResults);
359
-
360
-		return $this;
361
-	}
362
-
363
-	/**
364
-	 * Gets the maximum number of results the query object was set to retrieve (the "limit").
365
-	 * Returns NULL if {@link setMaxResults} was not applied to this query builder.
366
-	 *
367
-	 * @return integer The maximum number of results.
368
-	 */
369
-	public function getMaxResults() {
370
-		return $this->queryBuilder->getMaxResults();
371
-	}
372
-
373
-	/**
374
-	 * Specifies an item that is to be returned in the query result.
375
-	 * Replaces any previously specified selections, if any.
376
-	 *
377
-	 * <code>
378
-	 *     $qb = $conn->getQueryBuilder()
379
-	 *         ->select('u.id', 'p.id')
380
-	 *         ->from('users', 'u')
381
-	 *         ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
382
-	 * </code>
383
-	 *
384
-	 * @param mixed ...$selects The selection expressions.
385
-	 *
386
-	 * '@return $this This QueryBuilder instance.
387
-	 */
388
-	public function select(...$selects) {
389
-		if (count($selects) === 1 && is_array($selects[0])) {
390
-			$selects = $selects[0];
391
-		}
392
-
393
-		$this->queryBuilder->select(
394
-			$this->helper->quoteColumnNames($selects)
395
-		);
396
-
397
-		return $this;
398
-	}
399
-
400
-	/**
401
-	 * Specifies an item that is to be returned with a different name in the query result.
402
-	 *
403
-	 * <code>
404
-	 *     $qb = $conn->getQueryBuilder()
405
-	 *         ->selectAlias('u.id', 'user_id')
406
-	 *         ->from('users', 'u')
407
-	 *         ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
408
-	 * </code>
409
-	 *
410
-	 * @param mixed $select The selection expressions.
411
-	 * @param string $alias The column alias used in the constructed query.
412
-	 *
413
-	 * @return $this This QueryBuilder instance.
414
-	 */
415
-	public function selectAlias($select, $alias) {
416
-		$this->queryBuilder->addSelect(
417
-			$this->helper->quoteColumnName($select) . ' AS ' . $this->helper->quoteColumnName($alias)
418
-		);
419
-
420
-		return $this;
421
-	}
422
-
423
-	/**
424
-	 * Specifies an item that is to be returned uniquely in the query result.
425
-	 *
426
-	 * <code>
427
-	 *     $qb = $conn->getQueryBuilder()
428
-	 *         ->selectDistinct('type')
429
-	 *         ->from('users');
430
-	 * </code>
431
-	 *
432
-	 * @param mixed $select The selection expressions.
433
-	 *
434
-	 * @return $this This QueryBuilder instance.
435
-	 */
436
-	public function selectDistinct($select) {
437
-		$this->queryBuilder->addSelect(
438
-			'DISTINCT ' . $this->helper->quoteColumnName($select)
439
-		);
440
-
441
-		return $this;
442
-	}
443
-
444
-	/**
445
-	 * Adds an item that is to be returned in the query result.
446
-	 *
447
-	 * <code>
448
-	 *     $qb = $conn->getQueryBuilder()
449
-	 *         ->select('u.id')
450
-	 *         ->addSelect('p.id')
451
-	 *         ->from('users', 'u')
452
-	 *         ->leftJoin('u', 'phonenumbers', 'u.id = p.user_id');
453
-	 * </code>
454
-	 *
455
-	 * @param mixed ...$selects The selection expression.
456
-	 *
457
-	 * @return $this This QueryBuilder instance.
458
-	 */
459
-	public function addSelect(...$selects) {
460
-		if (count($selects) === 1 && is_array($selects[0])) {
461
-			$selects = $selects[0];
462
-		}
463
-
464
-		$this->queryBuilder->addSelect(
465
-			$this->helper->quoteColumnNames($selects)
466
-		);
467
-
468
-		return $this;
469
-	}
470
-
471
-	/**
472
-	 * Turns the query being built into a bulk delete query that ranges over
473
-	 * a certain table.
474
-	 *
475
-	 * <code>
476
-	 *     $qb = $conn->getQueryBuilder()
477
-	 *         ->delete('users', 'u')
478
-	 *         ->where('u.id = :user_id');
479
-	 *         ->setParameter(':user_id', 1);
480
-	 * </code>
481
-	 *
482
-	 * @param string $delete The table whose rows are subject to the deletion.
483
-	 * @param string $alias The table alias used in the constructed query.
484
-	 *
485
-	 * @return $this This QueryBuilder instance.
486
-	 */
487
-	public function delete($delete = null, $alias = null) {
488
-		$this->queryBuilder->delete(
489
-			$this->getTableName($delete),
490
-			$alias
491
-		);
492
-
493
-		return $this;
494
-	}
495
-
496
-	/**
497
-	 * Turns the query being built into a bulk update query that ranges over
498
-	 * a certain table
499
-	 *
500
-	 * <code>
501
-	 *     $qb = $conn->getQueryBuilder()
502
-	 *         ->update('users', 'u')
503
-	 *         ->set('u.password', md5('password'))
504
-	 *         ->where('u.id = ?');
505
-	 * </code>
506
-	 *
507
-	 * @param string $update The table whose rows are subject to the update.
508
-	 * @param string $alias The table alias used in the constructed query.
509
-	 *
510
-	 * @return $this This QueryBuilder instance.
511
-	 */
512
-	public function update($update = null, $alias = null) {
513
-		$this->queryBuilder->update(
514
-			$this->getTableName($update),
515
-			$alias
516
-		);
517
-
518
-		return $this;
519
-	}
520
-
521
-	/**
522
-	 * Turns the query being built into an insert query that inserts into
523
-	 * a certain table
524
-	 *
525
-	 * <code>
526
-	 *     $qb = $conn->getQueryBuilder()
527
-	 *         ->insert('users')
528
-	 *         ->values(
529
-	 *             array(
530
-	 *                 'name' => '?',
531
-	 *                 'password' => '?'
532
-	 *             )
533
-	 *         );
534
-	 * </code>
535
-	 *
536
-	 * @param string $insert The table into which the rows should be inserted.
537
-	 *
538
-	 * @return $this This QueryBuilder instance.
539
-	 */
540
-	public function insert($insert = null) {
541
-		$this->queryBuilder->insert(
542
-			$this->getTableName($insert)
543
-		);
544
-
545
-		$this->lastInsertedTable = $insert;
546
-
547
-		return $this;
548
-	}
549
-
550
-	/**
551
-	 * Creates and adds a query root corresponding to the table identified by the
552
-	 * given alias, forming a cartesian product with any existing query roots.
553
-	 *
554
-	 * <code>
555
-	 *     $qb = $conn->getQueryBuilder()
556
-	 *         ->select('u.id')
557
-	 *         ->from('users', 'u')
558
-	 * </code>
559
-	 *
560
-	 * @param string $from The table.
561
-	 * @param string|null $alias The alias of the table.
562
-	 *
563
-	 * @return $this This QueryBuilder instance.
564
-	 */
565
-	public function from($from, $alias = null) {
566
-		$this->queryBuilder->from(
567
-			$this->getTableName($from),
568
-			$this->quoteAlias($alias)
569
-		);
570
-
571
-		return $this;
572
-	}
573
-
574
-	/**
575
-	 * Creates and adds a join to the query.
576
-	 *
577
-	 * <code>
578
-	 *     $qb = $conn->getQueryBuilder()
579
-	 *         ->select('u.name')
580
-	 *         ->from('users', 'u')
581
-	 *         ->join('u', 'phonenumbers', 'p', 'p.is_primary = 1');
582
-	 * </code>
583
-	 *
584
-	 * @param string $fromAlias The alias that points to a from clause.
585
-	 * @param string $join The table name to join.
586
-	 * @param string $alias The alias of the join table.
587
-	 * @param string $condition The condition for the join.
588
-	 *
589
-	 * @return $this This QueryBuilder instance.
590
-	 */
591
-	public function join($fromAlias, $join, $alias, $condition = null) {
592
-		$this->queryBuilder->join(
593
-			$this->quoteAlias($fromAlias),
594
-			$this->getTableName($join),
595
-			$this->quoteAlias($alias),
596
-			$condition
597
-		);
598
-
599
-		return $this;
600
-	}
601
-
602
-	/**
603
-	 * Creates and adds a join to the query.
604
-	 *
605
-	 * <code>
606
-	 *     $qb = $conn->getQueryBuilder()
607
-	 *         ->select('u.name')
608
-	 *         ->from('users', 'u')
609
-	 *         ->innerJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
610
-	 * </code>
611
-	 *
612
-	 * @param string $fromAlias The alias that points to a from clause.
613
-	 * @param string $join The table name to join.
614
-	 * @param string $alias The alias of the join table.
615
-	 * @param string $condition The condition for the join.
616
-	 *
617
-	 * @return $this This QueryBuilder instance.
618
-	 */
619
-	public function innerJoin($fromAlias, $join, $alias, $condition = null) {
620
-		$this->queryBuilder->innerJoin(
621
-			$this->quoteAlias($fromAlias),
622
-			$this->getTableName($join),
623
-			$this->quoteAlias($alias),
624
-			$condition
625
-		);
626
-
627
-		return $this;
628
-	}
629
-
630
-	/**
631
-	 * Creates and adds a left join to the query.
632
-	 *
633
-	 * <code>
634
-	 *     $qb = $conn->getQueryBuilder()
635
-	 *         ->select('u.name')
636
-	 *         ->from('users', 'u')
637
-	 *         ->leftJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
638
-	 * </code>
639
-	 *
640
-	 * @param string $fromAlias The alias that points to a from clause.
641
-	 * @param string $join The table name to join.
642
-	 * @param string $alias The alias of the join table.
643
-	 * @param string $condition The condition for the join.
644
-	 *
645
-	 * @return $this This QueryBuilder instance.
646
-	 */
647
-	public function leftJoin($fromAlias, $join, $alias, $condition = null) {
648
-		$this->queryBuilder->leftJoin(
649
-			$this->quoteAlias($fromAlias),
650
-			$this->getTableName($join),
651
-			$this->quoteAlias($alias),
652
-			$condition
653
-		);
654
-
655
-		return $this;
656
-	}
657
-
658
-	/**
659
-	 * Creates and adds a right join to the query.
660
-	 *
661
-	 * <code>
662
-	 *     $qb = $conn->getQueryBuilder()
663
-	 *         ->select('u.name')
664
-	 *         ->from('users', 'u')
665
-	 *         ->rightJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
666
-	 * </code>
667
-	 *
668
-	 * @param string $fromAlias The alias that points to a from clause.
669
-	 * @param string $join The table name to join.
670
-	 * @param string $alias The alias of the join table.
671
-	 * @param string $condition The condition for the join.
672
-	 *
673
-	 * @return $this This QueryBuilder instance.
674
-	 */
675
-	public function rightJoin($fromAlias, $join, $alias, $condition = null) {
676
-		$this->queryBuilder->rightJoin(
677
-			$this->quoteAlias($fromAlias),
678
-			$this->getTableName($join),
679
-			$this->quoteAlias($alias),
680
-			$condition
681
-		);
682
-
683
-		return $this;
684
-	}
685
-
686
-	/**
687
-	 * Sets a new value for a column in a bulk update query.
688
-	 *
689
-	 * <code>
690
-	 *     $qb = $conn->getQueryBuilder()
691
-	 *         ->update('users', 'u')
692
-	 *         ->set('u.password', md5('password'))
693
-	 *         ->where('u.id = ?');
694
-	 * </code>
695
-	 *
696
-	 * @param string $key The column to set.
697
-	 * @param IParameter|string $value The value, expression, placeholder, etc.
698
-	 *
699
-	 * @return $this This QueryBuilder instance.
700
-	 */
701
-	public function set($key, $value) {
702
-		$this->queryBuilder->set(
703
-			$this->helper->quoteColumnName($key),
704
-			$this->helper->quoteColumnName($value)
705
-		);
706
-
707
-		return $this;
708
-	}
709
-
710
-	/**
711
-	 * Specifies one or more restrictions to the query result.
712
-	 * Replaces any previously specified restrictions, if any.
713
-	 *
714
-	 * <code>
715
-	 *     $qb = $conn->getQueryBuilder()
716
-	 *         ->select('u.name')
717
-	 *         ->from('users', 'u')
718
-	 *         ->where('u.id = ?');
719
-	 *
720
-	 *     // You can optionally programatically build and/or expressions
721
-	 *     $qb = $conn->getQueryBuilder();
722
-	 *
723
-	 *     $or = $qb->expr()->orx();
724
-	 *     $or->add($qb->expr()->eq('u.id', 1));
725
-	 *     $or->add($qb->expr()->eq('u.id', 2));
726
-	 *
727
-	 *     $qb->update('users', 'u')
728
-	 *         ->set('u.password', md5('password'))
729
-	 *         ->where($or);
730
-	 * </code>
731
-	 *
732
-	 * @param mixed ...$predicates The restriction predicates.
733
-	 *
734
-	 * @return $this This QueryBuilder instance.
735
-	 */
736
-	public function where(...$predicates) {
737
-		call_user_func_array(
738
-			[$this->queryBuilder, 'where'],
739
-			$predicates
740
-		);
741
-
742
-		return $this;
743
-	}
744
-
745
-	/**
746
-	 * Adds one or more restrictions to the query results, forming a logical
747
-	 * conjunction with any previously specified restrictions.
748
-	 *
749
-	 * <code>
750
-	 *     $qb = $conn->getQueryBuilder()
751
-	 *         ->select('u')
752
-	 *         ->from('users', 'u')
753
-	 *         ->where('u.username LIKE ?')
754
-	 *         ->andWhere('u.is_active = 1');
755
-	 * </code>
756
-	 *
757
-	 * @param mixed ...$where The query restrictions.
758
-	 *
759
-	 * @return $this This QueryBuilder instance.
760
-	 *
761
-	 * @see where()
762
-	 */
763
-	public function andWhere(...$where) {
764
-		call_user_func_array(
765
-			[$this->queryBuilder, 'andWhere'],
766
-			$where
767
-		);
768
-
769
-		return $this;
770
-	}
771
-
772
-	/**
773
-	 * Adds one or more restrictions to the query results, forming a logical
774
-	 * disjunction with any previously specified restrictions.
775
-	 *
776
-	 * <code>
777
-	 *     $qb = $conn->getQueryBuilder()
778
-	 *         ->select('u.name')
779
-	 *         ->from('users', 'u')
780
-	 *         ->where('u.id = 1')
781
-	 *         ->orWhere('u.id = 2');
782
-	 * </code>
783
-	 *
784
-	 * @param mixed ...$where The WHERE statement.
785
-	 *
786
-	 * @return $this This QueryBuilder instance.
787
-	 *
788
-	 * @see where()
789
-	 */
790
-	public function orWhere(...$where) {
791
-		call_user_func_array(
792
-			[$this->queryBuilder, 'orWhere'],
793
-			$where
794
-		);
795
-
796
-		return $this;
797
-	}
798
-
799
-	/**
800
-	 * Specifies a grouping over the results of the query.
801
-	 * Replaces any previously specified groupings, if any.
802
-	 *
803
-	 * <code>
804
-	 *     $qb = $conn->getQueryBuilder()
805
-	 *         ->select('u.name')
806
-	 *         ->from('users', 'u')
807
-	 *         ->groupBy('u.id');
808
-	 * </code>
809
-	 *
810
-	 * @param mixed ...$groupBys The grouping expression.
811
-	 *
812
-	 * @return $this This QueryBuilder instance.
813
-	 */
814
-	public function groupBy(...$groupBys) {
815
-		if (count($groupBys) === 1 && is_array($groupBys[0])) {
816
-			$groupBys = $groupBys[0];
817
-		}
818
-
819
-		call_user_func_array(
820
-			[$this->queryBuilder, 'groupBy'],
821
-			$this->helper->quoteColumnNames($groupBys)
822
-		);
823
-
824
-		return $this;
825
-	}
826
-
827
-	/**
828
-	 * Adds a grouping expression to the query.
829
-	 *
830
-	 * <code>
831
-	 *     $qb = $conn->getQueryBuilder()
832
-	 *         ->select('u.name')
833
-	 *         ->from('users', 'u')
834
-	 *         ->groupBy('u.lastLogin');
835
-	 *         ->addGroupBy('u.createdAt')
836
-	 * </code>
837
-	 *
838
-	 * @param mixed ...$groupBy The grouping expression.
839
-	 *
840
-	 * @return $this This QueryBuilder instance.
841
-	 */
842
-	public function addGroupBy(...$groupBys) {
843
-		if (count($groupBys) === 1 && is_array($groupBys[0])) {
844
-			$$groupBys = $groupBys[0];
845
-		}
846
-
847
-		call_user_func_array(
848
-			[$this->queryBuilder, 'addGroupBy'],
849
-			$this->helper->quoteColumnNames($groupBys)
850
-		);
851
-
852
-		return $this;
853
-	}
854
-
855
-	/**
856
-	 * Sets a value for a column in an insert query.
857
-	 *
858
-	 * <code>
859
-	 *     $qb = $conn->getQueryBuilder()
860
-	 *         ->insert('users')
861
-	 *         ->values(
862
-	 *             array(
863
-	 *                 'name' => '?'
864
-	 *             )
865
-	 *         )
866
-	 *         ->setValue('password', '?');
867
-	 * </code>
868
-	 *
869
-	 * @param string $column The column into which the value should be inserted.
870
-	 * @param string $value The value that should be inserted into the column.
871
-	 *
872
-	 * @return $this This QueryBuilder instance.
873
-	 */
874
-	public function setValue($column, $value) {
875
-		$this->queryBuilder->setValue(
876
-			$this->helper->quoteColumnName($column),
877
-			$value
878
-		);
879
-
880
-		return $this;
881
-	}
882
-
883
-	/**
884
-	 * Specifies values for an insert query indexed by column names.
885
-	 * Replaces any previous values, if any.
886
-	 *
887
-	 * <code>
888
-	 *     $qb = $conn->getQueryBuilder()
889
-	 *         ->insert('users')
890
-	 *         ->values(
891
-	 *             array(
892
-	 *                 'name' => '?',
893
-	 *                 'password' => '?'
894
-	 *             )
895
-	 *         );
896
-	 * </code>
897
-	 *
898
-	 * @param array $values The values to specify for the insert query indexed by column names.
899
-	 *
900
-	 * @return $this This QueryBuilder instance.
901
-	 */
902
-	public function values(array $values) {
903
-		$quotedValues = [];
904
-		foreach ($values as $key => $value) {
905
-			$quotedValues[$this->helper->quoteColumnName($key)] = $value;
906
-		}
907
-
908
-		$this->queryBuilder->values($quotedValues);
909
-
910
-		return $this;
911
-	}
912
-
913
-	/**
914
-	 * Specifies a restriction over the groups of the query.
915
-	 * Replaces any previous having restrictions, if any.
916
-	 *
917
-	 * @param mixed ...$having The restriction over the groups.
918
-	 *
919
-	 * @return $this This QueryBuilder instance.
920
-	 */
921
-	public function having(...$having) {
922
-		call_user_func_array(
923
-			[$this->queryBuilder, 'having'],
924
-			$having
925
-		);
926
-
927
-		return $this;
928
-	}
929
-
930
-	/**
931
-	 * Adds a restriction over the groups of the query, forming a logical
932
-	 * conjunction with any existing having restrictions.
933
-	 *
934
-	 * @param mixed ...$having The restriction to append.
935
-	 *
936
-	 * @return $this This QueryBuilder instance.
937
-	 */
938
-	public function andHaving(...$having) {
939
-		call_user_func_array(
940
-			[$this->queryBuilder, 'andHaving'],
941
-			$having
942
-		);
943
-
944
-		return $this;
945
-	}
946
-
947
-	/**
948
-	 * Adds a restriction over the groups of the query, forming a logical
949
-	 * disjunction with any existing having restrictions.
950
-	 *
951
-	 * @param mixed ...$having The restriction to add.
952
-	 *
953
-	 * @return $this This QueryBuilder instance.
954
-	 */
955
-	public function orHaving(...$having) {
956
-		call_user_func_array(
957
-			[$this->queryBuilder, 'orHaving'],
958
-			$having
959
-		);
960
-
961
-		return $this;
962
-	}
963
-
964
-	/**
965
-	 * Specifies an ordering for the query results.
966
-	 * Replaces any previously specified orderings, if any.
967
-	 *
968
-	 * @param string $sort The ordering expression.
969
-	 * @param string $order The ordering direction.
970
-	 *
971
-	 * @return $this This QueryBuilder instance.
972
-	 */
973
-	public function orderBy($sort, $order = null) {
974
-		$this->queryBuilder->orderBy(
975
-			$this->helper->quoteColumnName($sort),
976
-			$order
977
-		);
978
-
979
-		return $this;
980
-	}
981
-
982
-	/**
983
-	 * Adds an ordering to the query results.
984
-	 *
985
-	 * @param string $sort The ordering expression.
986
-	 * @param string $order The ordering direction.
987
-	 *
988
-	 * @return $this This QueryBuilder instance.
989
-	 */
990
-	public function addOrderBy($sort, $order = null) {
991
-		$this->queryBuilder->addOrderBy(
992
-			$this->helper->quoteColumnName($sort),
993
-			$order
994
-		);
995
-
996
-		return $this;
997
-	}
998
-
999
-	/**
1000
-	 * Gets a query part by its name.
1001
-	 *
1002
-	 * @param string $queryPartName
1003
-	 *
1004
-	 * @return mixed
1005
-	 */
1006
-	public function getQueryPart($queryPartName) {
1007
-		return $this->queryBuilder->getQueryPart($queryPartName);
1008
-	}
1009
-
1010
-	/**
1011
-	 * Gets all query parts.
1012
-	 *
1013
-	 * @return array
1014
-	 */
1015
-	public function getQueryParts() {
1016
-		return $this->queryBuilder->getQueryParts();
1017
-	}
1018
-
1019
-	/**
1020
-	 * Resets SQL parts.
1021
-	 *
1022
-	 * @param array|null $queryPartNames
1023
-	 *
1024
-	 * @return $this This QueryBuilder instance.
1025
-	 */
1026
-	public function resetQueryParts($queryPartNames = null) {
1027
-		$this->queryBuilder->resetQueryParts($queryPartNames);
1028
-
1029
-		return $this;
1030
-	}
1031
-
1032
-	/**
1033
-	 * Resets a single SQL part.
1034
-	 *
1035
-	 * @param string $queryPartName
1036
-	 *
1037
-	 * @return $this This QueryBuilder instance.
1038
-	 */
1039
-	public function resetQueryPart($queryPartName) {
1040
-		$this->queryBuilder->resetQueryPart($queryPartName);
1041
-
1042
-		return $this;
1043
-	}
1044
-
1045
-	/**
1046
-	 * Creates a new named parameter and bind the value $value to it.
1047
-	 *
1048
-	 * This method provides a shortcut for PDOStatement::bindValue
1049
-	 * when using prepared statements.
1050
-	 *
1051
-	 * The parameter $value specifies the value that you want to bind. If
1052
-	 * $placeholder is not provided bindValue() will automatically create a
1053
-	 * placeholder for you. An automatic placeholder will be of the name
1054
-	 * ':dcValue1', ':dcValue2' etc.
1055
-	 *
1056
-	 * For more information see {@link http://php.net/pdostatement-bindparam}
1057
-	 *
1058
-	 * Example:
1059
-	 * <code>
1060
-	 * $value = 2;
1061
-	 * $q->eq( 'id', $q->bindValue( $value ) );
1062
-	 * $stmt = $q->executeQuery(); // executed with 'id = 2'
1063
-	 * </code>
1064
-	 *
1065
-	 * @license New BSD License
1066
-	 * @link http://www.zetacomponents.org
1067
-	 *
1068
-	 * @param mixed $value
1069
-	 * @param mixed $type
1070
-	 * @param string $placeHolder The name to bind with. The string must start with a colon ':'.
1071
-	 *
1072
-	 * @return IParameter the placeholder name used.
1073
-	 */
1074
-	public function createNamedParameter($value, $type = IQueryBuilder::PARAM_STR, $placeHolder = null) {
1075
-		return new Parameter($this->queryBuilder->createNamedParameter($value, $type, $placeHolder));
1076
-	}
1077
-
1078
-	/**
1079
-	 * Creates a new positional parameter and bind the given value to it.
1080
-	 *
1081
-	 * Attention: If you are using positional parameters with the query builder you have
1082
-	 * to be very careful to bind all parameters in the order they appear in the SQL
1083
-	 * statement , otherwise they get bound in the wrong order which can lead to serious
1084
-	 * bugs in your code.
1085
-	 *
1086
-	 * Example:
1087
-	 * <code>
1088
-	 *  $qb = $conn->getQueryBuilder();
1089
-	 *  $qb->select('u.*')
1090
-	 *     ->from('users', 'u')
1091
-	 *     ->where('u.username = ' . $qb->createPositionalParameter('Foo', IQueryBuilder::PARAM_STR))
1092
-	 *     ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', IQueryBuilder::PARAM_STR))
1093
-	 * </code>
1094
-	 *
1095
-	 * @param mixed $value
1096
-	 * @param integer $type
1097
-	 *
1098
-	 * @return IParameter
1099
-	 */
1100
-	public function createPositionalParameter($value, $type = IQueryBuilder::PARAM_STR) {
1101
-		return new Parameter($this->queryBuilder->createPositionalParameter($value, $type));
1102
-	}
1103
-
1104
-	/**
1105
-	 * Creates a new parameter
1106
-	 *
1107
-	 * Example:
1108
-	 * <code>
1109
-	 *  $qb = $conn->getQueryBuilder();
1110
-	 *  $qb->select('u.*')
1111
-	 *     ->from('users', 'u')
1112
-	 *     ->where('u.username = ' . $qb->createParameter('name'))
1113
-	 *     ->setParameter('name', 'Bar', IQueryBuilder::PARAM_STR))
1114
-	 * </code>
1115
-	 *
1116
-	 * @param string $name
1117
-	 *
1118
-	 * @return IParameter
1119
-	 */
1120
-	public function createParameter($name) {
1121
-		return new Parameter(':' . $name);
1122
-	}
1123
-
1124
-	/**
1125
-	 * Creates a new function
1126
-	 *
1127
-	 * Attention: Column names inside the call have to be quoted before hand
1128
-	 *
1129
-	 * Example:
1130
-	 * <code>
1131
-	 *  $qb = $conn->getQueryBuilder();
1132
-	 *  $qb->select($qb->createFunction('COUNT(*)'))
1133
-	 *     ->from('users', 'u')
1134
-	 *  echo $qb->getSQL(); // SELECT COUNT(*) FROM `users` u
1135
-	 * </code>
1136
-	 * <code>
1137
-	 *  $qb = $conn->getQueryBuilder();
1138
-	 *  $qb->select($qb->createFunction('COUNT(`column`)'))
1139
-	 *     ->from('users', 'u')
1140
-	 *  echo $qb->getSQL(); // SELECT COUNT(`column`) FROM `users` u
1141
-	 * </code>
1142
-	 *
1143
-	 * @param string $call
1144
-	 *
1145
-	 * @return IQueryFunction
1146
-	 */
1147
-	public function createFunction($call) {
1148
-		return new QueryFunction($call);
1149
-	}
1150
-
1151
-	/**
1152
-	 * Used to get the id of the last inserted element
1153
-	 * @return int
1154
-	 * @throws \BadMethodCallException When being called before an insert query has been run.
1155
-	 */
1156
-	public function getLastInsertId() {
1157
-		if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::INSERT && $this->lastInsertedTable) {
1158
-			// lastInsertId() needs the prefix but no quotes
1159
-			$table = $this->prefixTableName($this->lastInsertedTable);
1160
-			return (int) $this->connection->lastInsertId($table);
1161
-		}
1162
-
1163
-		throw new \BadMethodCallException('Invalid call to getLastInsertId without using insert() before.');
1164
-	}
1165
-
1166
-	/**
1167
-	 * Returns the table name quoted and with database prefix as needed by the implementation
1168
-	 *
1169
-	 * @param string $table
1170
-	 * @return string
1171
-	 */
1172
-	public function getTableName($table) {
1173
-		if ($table instanceof IQueryFunction) {
1174
-			return (string) $table;
1175
-		}
1176
-
1177
-		$table = $this->prefixTableName($table);
1178
-		return $this->helper->quoteColumnName($table);
1179
-	}
1180
-
1181
-	/**
1182
-	 * Returns the table name with database prefix as needed by the implementation
1183
-	 *
1184
-	 * @param string $table
1185
-	 * @return string
1186
-	 */
1187
-	protected function prefixTableName($table) {
1188
-		if ($this->automaticTablePrefix === false || strpos($table, '*PREFIX*') === 0) {
1189
-			return $table;
1190
-		}
1191
-
1192
-		return '*PREFIX*' . $table;
1193
-	}
1194
-
1195
-	/**
1196
-	 * Returns the column name quoted and with table alias prefix as needed by the implementation
1197
-	 *
1198
-	 * @param string $column
1199
-	 * @param string $tableAlias
1200
-	 * @return string
1201
-	 */
1202
-	public function getColumnName($column, $tableAlias = '') {
1203
-		if ($tableAlias !== '') {
1204
-			$tableAlias .= '.';
1205
-		}
1206
-
1207
-		return $this->helper->quoteColumnName($tableAlias . $column);
1208
-	}
1209
-
1210
-	/**
1211
-	 * Returns the column name quoted and with table alias prefix as needed by the implementation
1212
-	 *
1213
-	 * @param string $alias
1214
-	 * @return string
1215
-	 */
1216
-	public function quoteAlias($alias) {
1217
-		if ($alias === '' || $alias === null) {
1218
-			return $alias;
1219
-		}
1220
-
1221
-		return $this->helper->quoteColumnName($alias);
1222
-	}
52
+    /** @var \OCP\IDBConnection */
53
+    private $connection;
54
+
55
+    /** @var SystemConfig */
56
+    private $systemConfig;
57
+
58
+    /** @var ILogger */
59
+    private $logger;
60
+
61
+    /** @var \Doctrine\DBAL\Query\QueryBuilder */
62
+    private $queryBuilder;
63
+
64
+    /** @var QuoteHelper */
65
+    private $helper;
66
+
67
+    /** @var bool */
68
+    private $automaticTablePrefix = true;
69
+
70
+    /** @var string */
71
+    protected $lastInsertedTable;
72
+
73
+    /**
74
+     * Initializes a new QueryBuilder.
75
+     *
76
+     * @param IDBConnection $connection
77
+     * @param SystemConfig $systemConfig
78
+     * @param ILogger $logger
79
+     */
80
+    public function __construct(IDBConnection $connection, SystemConfig $systemConfig, ILogger $logger) {
81
+        $this->connection = $connection;
82
+        $this->systemConfig = $systemConfig;
83
+        $this->logger = $logger;
84
+        $this->queryBuilder = new \Doctrine\DBAL\Query\QueryBuilder($this->connection);
85
+        $this->helper = new QuoteHelper();
86
+    }
87
+
88
+    /**
89
+     * Enable/disable automatic prefixing of table names with the oc_ prefix
90
+     *
91
+     * @param bool $enabled If set to true table names will be prefixed with the
92
+     * owncloud database prefix automatically.
93
+     * @since 8.2.0
94
+     */
95
+    public function automaticTablePrefix($enabled) {
96
+        $this->automaticTablePrefix = (bool) $enabled;
97
+    }
98
+
99
+    /**
100
+     * Gets an ExpressionBuilder used for object-oriented construction of query expressions.
101
+     * This producer method is intended for convenient inline usage. Example:
102
+     *
103
+     * <code>
104
+     *     $qb = $conn->getQueryBuilder()
105
+     *         ->select('u')
106
+     *         ->from('users', 'u')
107
+     *         ->where($qb->expr()->eq('u.id', 1));
108
+     * </code>
109
+     *
110
+     * For more complex expression construction, consider storing the expression
111
+     * builder object in a local variable.
112
+     *
113
+     * @return \OCP\DB\QueryBuilder\IExpressionBuilder
114
+     */
115
+    public function expr() {
116
+        if ($this->connection instanceof OracleConnection) {
117
+            return new OCIExpressionBuilder($this->connection, $this);
118
+        } elseif ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
119
+            return new PgSqlExpressionBuilder($this->connection, $this);
120
+        } elseif ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
121
+            return new MySqlExpressionBuilder($this->connection, $this);
122
+        } elseif ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
123
+            return new SqliteExpressionBuilder($this->connection, $this);
124
+        } else {
125
+            return new ExpressionBuilder($this->connection, $this);
126
+        }
127
+    }
128
+
129
+    /**
130
+     * Gets an FunctionBuilder used for object-oriented construction of query functions.
131
+     * This producer method is intended for convenient inline usage. Example:
132
+     *
133
+     * <code>
134
+     *     $qb = $conn->getQueryBuilder()
135
+     *         ->select('u')
136
+     *         ->from('users', 'u')
137
+     *         ->where($qb->fun()->md5('u.id'));
138
+     * </code>
139
+     *
140
+     * For more complex function construction, consider storing the function
141
+     * builder object in a local variable.
142
+     *
143
+     * @return \OCP\DB\QueryBuilder\IFunctionBuilder
144
+     */
145
+    public function func() {
146
+        if ($this->connection instanceof OracleConnection) {
147
+            return new OCIFunctionBuilder($this->helper);
148
+        } elseif ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
149
+            return new SqliteFunctionBuilder($this->helper);
150
+        } elseif ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
151
+            return new PgSqlFunctionBuilder($this->helper);
152
+        } else {
153
+            return new FunctionBuilder($this->helper);
154
+        }
155
+    }
156
+
157
+    /**
158
+     * Gets the type of the currently built query.
159
+     *
160
+     * @return integer
161
+     */
162
+    public function getType() {
163
+        return $this->queryBuilder->getType();
164
+    }
165
+
166
+    /**
167
+     * Gets the associated DBAL Connection for this query builder.
168
+     *
169
+     * @return \OCP\IDBConnection
170
+     */
171
+    public function getConnection() {
172
+        return $this->connection;
173
+    }
174
+
175
+    /**
176
+     * Gets the state of this query builder instance.
177
+     *
178
+     * @return integer Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.
179
+     */
180
+    public function getState() {
181
+        return $this->queryBuilder->getState();
182
+    }
183
+
184
+    /**
185
+     * Executes this query using the bound parameters and their types.
186
+     *
187
+     * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate}
188
+     * for insert, update and delete statements.
189
+     *
190
+     * @return \Doctrine\DBAL\Driver\Statement|int
191
+     */
192
+    public function execute() {
193
+        if ($this->systemConfig->getValue('log_query', false)) {
194
+            $params = [];
195
+            foreach ($this->getParameters() as $placeholder => $value) {
196
+                if (is_array($value)) {
197
+                    $params[] = $placeholder . ' => (\'' . implode('\', \'', $value) . '\')';
198
+                } else {
199
+                    $params[] = $placeholder . ' => \'' . $value . '\'';
200
+                }
201
+            }
202
+            if (empty($params)) {
203
+                $this->logger->debug('DB QueryBuilder: \'{query}\'', [
204
+                    'query' => $this->getSQL(),
205
+                    'app' => 'core',
206
+                ]);
207
+            } else {
208
+                $this->logger->debug('DB QueryBuilder: \'{query}\' with parameters: {params}', [
209
+                    'query' => $this->getSQL(),
210
+                    'params' => implode(', ', $params),
211
+                    'app' => 'core',
212
+                ]);
213
+            }
214
+        }
215
+
216
+        return $this->queryBuilder->execute();
217
+    }
218
+
219
+    /**
220
+     * Gets the complete SQL string formed by the current specifications of this QueryBuilder.
221
+     *
222
+     * <code>
223
+     *     $qb = $conn->getQueryBuilder()
224
+     *         ->select('u')
225
+     *         ->from('User', 'u')
226
+     *     echo $qb->getSQL(); // SELECT u FROM User u
227
+     * </code>
228
+     *
229
+     * @return string The SQL query string.
230
+     */
231
+    public function getSQL() {
232
+        return $this->queryBuilder->getSQL();
233
+    }
234
+
235
+    /**
236
+     * Sets a query parameter for the query being constructed.
237
+     *
238
+     * <code>
239
+     *     $qb = $conn->getQueryBuilder()
240
+     *         ->select('u')
241
+     *         ->from('users', 'u')
242
+     *         ->where('u.id = :user_id')
243
+     *         ->setParameter(':user_id', 1);
244
+     * </code>
245
+     *
246
+     * @param string|integer $key The parameter position or name.
247
+     * @param mixed $value The parameter value.
248
+     * @param string|null|int $type One of the IQueryBuilder::PARAM_* constants.
249
+     *
250
+     * @return $this This QueryBuilder instance.
251
+     */
252
+    public function setParameter($key, $value, $type = null) {
253
+        $this->queryBuilder->setParameter($key, $value, $type);
254
+
255
+        return $this;
256
+    }
257
+
258
+    /**
259
+     * Sets a collection of query parameters for the query being constructed.
260
+     *
261
+     * <code>
262
+     *     $qb = $conn->getQueryBuilder()
263
+     *         ->select('u')
264
+     *         ->from('users', 'u')
265
+     *         ->where('u.id = :user_id1 OR u.id = :user_id2')
266
+     *         ->setParameters(array(
267
+     *             ':user_id1' => 1,
268
+     *             ':user_id2' => 2
269
+     *         ));
270
+     * </code>
271
+     *
272
+     * @param array $params The query parameters to set.
273
+     * @param array $types The query parameters types to set.
274
+     *
275
+     * @return $this This QueryBuilder instance.
276
+     */
277
+    public function setParameters(array $params, array $types = []) {
278
+        $this->queryBuilder->setParameters($params, $types);
279
+
280
+        return $this;
281
+    }
282
+
283
+    /**
284
+     * Gets all defined query parameters for the query being constructed indexed by parameter index or name.
285
+     *
286
+     * @return array The currently defined query parameters indexed by parameter index or name.
287
+     */
288
+    public function getParameters() {
289
+        return $this->queryBuilder->getParameters();
290
+    }
291
+
292
+    /**
293
+     * Gets a (previously set) query parameter of the query being constructed.
294
+     *
295
+     * @param mixed $key The key (index or name) of the bound parameter.
296
+     *
297
+     * @return mixed The value of the bound parameter.
298
+     */
299
+    public function getParameter($key) {
300
+        return $this->queryBuilder->getParameter($key);
301
+    }
302
+
303
+    /**
304
+     * Gets all defined query parameter types for the query being constructed indexed by parameter index or name.
305
+     *
306
+     * @return array The currently defined query parameter types indexed by parameter index or name.
307
+     */
308
+    public function getParameterTypes() {
309
+        return $this->queryBuilder->getParameterTypes();
310
+    }
311
+
312
+    /**
313
+     * Gets a (previously set) query parameter type of the query being constructed.
314
+     *
315
+     * @param mixed $key The key (index or name) of the bound parameter type.
316
+     *
317
+     * @return mixed The value of the bound parameter type.
318
+     */
319
+    public function getParameterType($key) {
320
+        return $this->queryBuilder->getParameterType($key);
321
+    }
322
+
323
+    /**
324
+     * Sets the position of the first result to retrieve (the "offset").
325
+     *
326
+     * @param integer $firstResult The first result to return.
327
+     *
328
+     * @return $this This QueryBuilder instance.
329
+     */
330
+    public function setFirstResult($firstResult) {
331
+        $this->queryBuilder->setFirstResult($firstResult);
332
+
333
+        return $this;
334
+    }
335
+
336
+    /**
337
+     * Gets the position of the first result the query object was set to retrieve (the "offset").
338
+     * Returns NULL if {@link setFirstResult} was not applied to this QueryBuilder.
339
+     *
340
+     * @return integer The position of the first result.
341
+     */
342
+    public function getFirstResult() {
343
+        return $this->queryBuilder->getFirstResult();
344
+    }
345
+
346
+    /**
347
+     * Sets the maximum number of results to retrieve (the "limit").
348
+     *
349
+     * NOTE: Setting max results to "0" will cause mixed behaviour. While most
350
+     * of the databases will just return an empty result set, Oracle will return
351
+     * all entries.
352
+     *
353
+     * @param integer $maxResults The maximum number of results to retrieve.
354
+     *
355
+     * @return $this This QueryBuilder instance.
356
+     */
357
+    public function setMaxResults($maxResults) {
358
+        $this->queryBuilder->setMaxResults($maxResults);
359
+
360
+        return $this;
361
+    }
362
+
363
+    /**
364
+     * Gets the maximum number of results the query object was set to retrieve (the "limit").
365
+     * Returns NULL if {@link setMaxResults} was not applied to this query builder.
366
+     *
367
+     * @return integer The maximum number of results.
368
+     */
369
+    public function getMaxResults() {
370
+        return $this->queryBuilder->getMaxResults();
371
+    }
372
+
373
+    /**
374
+     * Specifies an item that is to be returned in the query result.
375
+     * Replaces any previously specified selections, if any.
376
+     *
377
+     * <code>
378
+     *     $qb = $conn->getQueryBuilder()
379
+     *         ->select('u.id', 'p.id')
380
+     *         ->from('users', 'u')
381
+     *         ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
382
+     * </code>
383
+     *
384
+     * @param mixed ...$selects The selection expressions.
385
+     *
386
+     * '@return $this This QueryBuilder instance.
387
+     */
388
+    public function select(...$selects) {
389
+        if (count($selects) === 1 && is_array($selects[0])) {
390
+            $selects = $selects[0];
391
+        }
392
+
393
+        $this->queryBuilder->select(
394
+            $this->helper->quoteColumnNames($selects)
395
+        );
396
+
397
+        return $this;
398
+    }
399
+
400
+    /**
401
+     * Specifies an item that is to be returned with a different name in the query result.
402
+     *
403
+     * <code>
404
+     *     $qb = $conn->getQueryBuilder()
405
+     *         ->selectAlias('u.id', 'user_id')
406
+     *         ->from('users', 'u')
407
+     *         ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
408
+     * </code>
409
+     *
410
+     * @param mixed $select The selection expressions.
411
+     * @param string $alias The column alias used in the constructed query.
412
+     *
413
+     * @return $this This QueryBuilder instance.
414
+     */
415
+    public function selectAlias($select, $alias) {
416
+        $this->queryBuilder->addSelect(
417
+            $this->helper->quoteColumnName($select) . ' AS ' . $this->helper->quoteColumnName($alias)
418
+        );
419
+
420
+        return $this;
421
+    }
422
+
423
+    /**
424
+     * Specifies an item that is to be returned uniquely in the query result.
425
+     *
426
+     * <code>
427
+     *     $qb = $conn->getQueryBuilder()
428
+     *         ->selectDistinct('type')
429
+     *         ->from('users');
430
+     * </code>
431
+     *
432
+     * @param mixed $select The selection expressions.
433
+     *
434
+     * @return $this This QueryBuilder instance.
435
+     */
436
+    public function selectDistinct($select) {
437
+        $this->queryBuilder->addSelect(
438
+            'DISTINCT ' . $this->helper->quoteColumnName($select)
439
+        );
440
+
441
+        return $this;
442
+    }
443
+
444
+    /**
445
+     * Adds an item that is to be returned in the query result.
446
+     *
447
+     * <code>
448
+     *     $qb = $conn->getQueryBuilder()
449
+     *         ->select('u.id')
450
+     *         ->addSelect('p.id')
451
+     *         ->from('users', 'u')
452
+     *         ->leftJoin('u', 'phonenumbers', 'u.id = p.user_id');
453
+     * </code>
454
+     *
455
+     * @param mixed ...$selects The selection expression.
456
+     *
457
+     * @return $this This QueryBuilder instance.
458
+     */
459
+    public function addSelect(...$selects) {
460
+        if (count($selects) === 1 && is_array($selects[0])) {
461
+            $selects = $selects[0];
462
+        }
463
+
464
+        $this->queryBuilder->addSelect(
465
+            $this->helper->quoteColumnNames($selects)
466
+        );
467
+
468
+        return $this;
469
+    }
470
+
471
+    /**
472
+     * Turns the query being built into a bulk delete query that ranges over
473
+     * a certain table.
474
+     *
475
+     * <code>
476
+     *     $qb = $conn->getQueryBuilder()
477
+     *         ->delete('users', 'u')
478
+     *         ->where('u.id = :user_id');
479
+     *         ->setParameter(':user_id', 1);
480
+     * </code>
481
+     *
482
+     * @param string $delete The table whose rows are subject to the deletion.
483
+     * @param string $alias The table alias used in the constructed query.
484
+     *
485
+     * @return $this This QueryBuilder instance.
486
+     */
487
+    public function delete($delete = null, $alias = null) {
488
+        $this->queryBuilder->delete(
489
+            $this->getTableName($delete),
490
+            $alias
491
+        );
492
+
493
+        return $this;
494
+    }
495
+
496
+    /**
497
+     * Turns the query being built into a bulk update query that ranges over
498
+     * a certain table
499
+     *
500
+     * <code>
501
+     *     $qb = $conn->getQueryBuilder()
502
+     *         ->update('users', 'u')
503
+     *         ->set('u.password', md5('password'))
504
+     *         ->where('u.id = ?');
505
+     * </code>
506
+     *
507
+     * @param string $update The table whose rows are subject to the update.
508
+     * @param string $alias The table alias used in the constructed query.
509
+     *
510
+     * @return $this This QueryBuilder instance.
511
+     */
512
+    public function update($update = null, $alias = null) {
513
+        $this->queryBuilder->update(
514
+            $this->getTableName($update),
515
+            $alias
516
+        );
517
+
518
+        return $this;
519
+    }
520
+
521
+    /**
522
+     * Turns the query being built into an insert query that inserts into
523
+     * a certain table
524
+     *
525
+     * <code>
526
+     *     $qb = $conn->getQueryBuilder()
527
+     *         ->insert('users')
528
+     *         ->values(
529
+     *             array(
530
+     *                 'name' => '?',
531
+     *                 'password' => '?'
532
+     *             )
533
+     *         );
534
+     * </code>
535
+     *
536
+     * @param string $insert The table into which the rows should be inserted.
537
+     *
538
+     * @return $this This QueryBuilder instance.
539
+     */
540
+    public function insert($insert = null) {
541
+        $this->queryBuilder->insert(
542
+            $this->getTableName($insert)
543
+        );
544
+
545
+        $this->lastInsertedTable = $insert;
546
+
547
+        return $this;
548
+    }
549
+
550
+    /**
551
+     * Creates and adds a query root corresponding to the table identified by the
552
+     * given alias, forming a cartesian product with any existing query roots.
553
+     *
554
+     * <code>
555
+     *     $qb = $conn->getQueryBuilder()
556
+     *         ->select('u.id')
557
+     *         ->from('users', 'u')
558
+     * </code>
559
+     *
560
+     * @param string $from The table.
561
+     * @param string|null $alias The alias of the table.
562
+     *
563
+     * @return $this This QueryBuilder instance.
564
+     */
565
+    public function from($from, $alias = null) {
566
+        $this->queryBuilder->from(
567
+            $this->getTableName($from),
568
+            $this->quoteAlias($alias)
569
+        );
570
+
571
+        return $this;
572
+    }
573
+
574
+    /**
575
+     * Creates and adds a join to the query.
576
+     *
577
+     * <code>
578
+     *     $qb = $conn->getQueryBuilder()
579
+     *         ->select('u.name')
580
+     *         ->from('users', 'u')
581
+     *         ->join('u', 'phonenumbers', 'p', 'p.is_primary = 1');
582
+     * </code>
583
+     *
584
+     * @param string $fromAlias The alias that points to a from clause.
585
+     * @param string $join The table name to join.
586
+     * @param string $alias The alias of the join table.
587
+     * @param string $condition The condition for the join.
588
+     *
589
+     * @return $this This QueryBuilder instance.
590
+     */
591
+    public function join($fromAlias, $join, $alias, $condition = null) {
592
+        $this->queryBuilder->join(
593
+            $this->quoteAlias($fromAlias),
594
+            $this->getTableName($join),
595
+            $this->quoteAlias($alias),
596
+            $condition
597
+        );
598
+
599
+        return $this;
600
+    }
601
+
602
+    /**
603
+     * Creates and adds a join to the query.
604
+     *
605
+     * <code>
606
+     *     $qb = $conn->getQueryBuilder()
607
+     *         ->select('u.name')
608
+     *         ->from('users', 'u')
609
+     *         ->innerJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
610
+     * </code>
611
+     *
612
+     * @param string $fromAlias The alias that points to a from clause.
613
+     * @param string $join The table name to join.
614
+     * @param string $alias The alias of the join table.
615
+     * @param string $condition The condition for the join.
616
+     *
617
+     * @return $this This QueryBuilder instance.
618
+     */
619
+    public function innerJoin($fromAlias, $join, $alias, $condition = null) {
620
+        $this->queryBuilder->innerJoin(
621
+            $this->quoteAlias($fromAlias),
622
+            $this->getTableName($join),
623
+            $this->quoteAlias($alias),
624
+            $condition
625
+        );
626
+
627
+        return $this;
628
+    }
629
+
630
+    /**
631
+     * Creates and adds a left join to the query.
632
+     *
633
+     * <code>
634
+     *     $qb = $conn->getQueryBuilder()
635
+     *         ->select('u.name')
636
+     *         ->from('users', 'u')
637
+     *         ->leftJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
638
+     * </code>
639
+     *
640
+     * @param string $fromAlias The alias that points to a from clause.
641
+     * @param string $join The table name to join.
642
+     * @param string $alias The alias of the join table.
643
+     * @param string $condition The condition for the join.
644
+     *
645
+     * @return $this This QueryBuilder instance.
646
+     */
647
+    public function leftJoin($fromAlias, $join, $alias, $condition = null) {
648
+        $this->queryBuilder->leftJoin(
649
+            $this->quoteAlias($fromAlias),
650
+            $this->getTableName($join),
651
+            $this->quoteAlias($alias),
652
+            $condition
653
+        );
654
+
655
+        return $this;
656
+    }
657
+
658
+    /**
659
+     * Creates and adds a right join to the query.
660
+     *
661
+     * <code>
662
+     *     $qb = $conn->getQueryBuilder()
663
+     *         ->select('u.name')
664
+     *         ->from('users', 'u')
665
+     *         ->rightJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
666
+     * </code>
667
+     *
668
+     * @param string $fromAlias The alias that points to a from clause.
669
+     * @param string $join The table name to join.
670
+     * @param string $alias The alias of the join table.
671
+     * @param string $condition The condition for the join.
672
+     *
673
+     * @return $this This QueryBuilder instance.
674
+     */
675
+    public function rightJoin($fromAlias, $join, $alias, $condition = null) {
676
+        $this->queryBuilder->rightJoin(
677
+            $this->quoteAlias($fromAlias),
678
+            $this->getTableName($join),
679
+            $this->quoteAlias($alias),
680
+            $condition
681
+        );
682
+
683
+        return $this;
684
+    }
685
+
686
+    /**
687
+     * Sets a new value for a column in a bulk update query.
688
+     *
689
+     * <code>
690
+     *     $qb = $conn->getQueryBuilder()
691
+     *         ->update('users', 'u')
692
+     *         ->set('u.password', md5('password'))
693
+     *         ->where('u.id = ?');
694
+     * </code>
695
+     *
696
+     * @param string $key The column to set.
697
+     * @param IParameter|string $value The value, expression, placeholder, etc.
698
+     *
699
+     * @return $this This QueryBuilder instance.
700
+     */
701
+    public function set($key, $value) {
702
+        $this->queryBuilder->set(
703
+            $this->helper->quoteColumnName($key),
704
+            $this->helper->quoteColumnName($value)
705
+        );
706
+
707
+        return $this;
708
+    }
709
+
710
+    /**
711
+     * Specifies one or more restrictions to the query result.
712
+     * Replaces any previously specified restrictions, if any.
713
+     *
714
+     * <code>
715
+     *     $qb = $conn->getQueryBuilder()
716
+     *         ->select('u.name')
717
+     *         ->from('users', 'u')
718
+     *         ->where('u.id = ?');
719
+     *
720
+     *     // You can optionally programatically build and/or expressions
721
+     *     $qb = $conn->getQueryBuilder();
722
+     *
723
+     *     $or = $qb->expr()->orx();
724
+     *     $or->add($qb->expr()->eq('u.id', 1));
725
+     *     $or->add($qb->expr()->eq('u.id', 2));
726
+     *
727
+     *     $qb->update('users', 'u')
728
+     *         ->set('u.password', md5('password'))
729
+     *         ->where($or);
730
+     * </code>
731
+     *
732
+     * @param mixed ...$predicates The restriction predicates.
733
+     *
734
+     * @return $this This QueryBuilder instance.
735
+     */
736
+    public function where(...$predicates) {
737
+        call_user_func_array(
738
+            [$this->queryBuilder, 'where'],
739
+            $predicates
740
+        );
741
+
742
+        return $this;
743
+    }
744
+
745
+    /**
746
+     * Adds one or more restrictions to the query results, forming a logical
747
+     * conjunction with any previously specified restrictions.
748
+     *
749
+     * <code>
750
+     *     $qb = $conn->getQueryBuilder()
751
+     *         ->select('u')
752
+     *         ->from('users', 'u')
753
+     *         ->where('u.username LIKE ?')
754
+     *         ->andWhere('u.is_active = 1');
755
+     * </code>
756
+     *
757
+     * @param mixed ...$where The query restrictions.
758
+     *
759
+     * @return $this This QueryBuilder instance.
760
+     *
761
+     * @see where()
762
+     */
763
+    public function andWhere(...$where) {
764
+        call_user_func_array(
765
+            [$this->queryBuilder, 'andWhere'],
766
+            $where
767
+        );
768
+
769
+        return $this;
770
+    }
771
+
772
+    /**
773
+     * Adds one or more restrictions to the query results, forming a logical
774
+     * disjunction with any previously specified restrictions.
775
+     *
776
+     * <code>
777
+     *     $qb = $conn->getQueryBuilder()
778
+     *         ->select('u.name')
779
+     *         ->from('users', 'u')
780
+     *         ->where('u.id = 1')
781
+     *         ->orWhere('u.id = 2');
782
+     * </code>
783
+     *
784
+     * @param mixed ...$where The WHERE statement.
785
+     *
786
+     * @return $this This QueryBuilder instance.
787
+     *
788
+     * @see where()
789
+     */
790
+    public function orWhere(...$where) {
791
+        call_user_func_array(
792
+            [$this->queryBuilder, 'orWhere'],
793
+            $where
794
+        );
795
+
796
+        return $this;
797
+    }
798
+
799
+    /**
800
+     * Specifies a grouping over the results of the query.
801
+     * Replaces any previously specified groupings, if any.
802
+     *
803
+     * <code>
804
+     *     $qb = $conn->getQueryBuilder()
805
+     *         ->select('u.name')
806
+     *         ->from('users', 'u')
807
+     *         ->groupBy('u.id');
808
+     * </code>
809
+     *
810
+     * @param mixed ...$groupBys The grouping expression.
811
+     *
812
+     * @return $this This QueryBuilder instance.
813
+     */
814
+    public function groupBy(...$groupBys) {
815
+        if (count($groupBys) === 1 && is_array($groupBys[0])) {
816
+            $groupBys = $groupBys[0];
817
+        }
818
+
819
+        call_user_func_array(
820
+            [$this->queryBuilder, 'groupBy'],
821
+            $this->helper->quoteColumnNames($groupBys)
822
+        );
823
+
824
+        return $this;
825
+    }
826
+
827
+    /**
828
+     * Adds a grouping expression to the query.
829
+     *
830
+     * <code>
831
+     *     $qb = $conn->getQueryBuilder()
832
+     *         ->select('u.name')
833
+     *         ->from('users', 'u')
834
+     *         ->groupBy('u.lastLogin');
835
+     *         ->addGroupBy('u.createdAt')
836
+     * </code>
837
+     *
838
+     * @param mixed ...$groupBy The grouping expression.
839
+     *
840
+     * @return $this This QueryBuilder instance.
841
+     */
842
+    public function addGroupBy(...$groupBys) {
843
+        if (count($groupBys) === 1 && is_array($groupBys[0])) {
844
+            $$groupBys = $groupBys[0];
845
+        }
846
+
847
+        call_user_func_array(
848
+            [$this->queryBuilder, 'addGroupBy'],
849
+            $this->helper->quoteColumnNames($groupBys)
850
+        );
851
+
852
+        return $this;
853
+    }
854
+
855
+    /**
856
+     * Sets a value for a column in an insert query.
857
+     *
858
+     * <code>
859
+     *     $qb = $conn->getQueryBuilder()
860
+     *         ->insert('users')
861
+     *         ->values(
862
+     *             array(
863
+     *                 'name' => '?'
864
+     *             )
865
+     *         )
866
+     *         ->setValue('password', '?');
867
+     * </code>
868
+     *
869
+     * @param string $column The column into which the value should be inserted.
870
+     * @param string $value The value that should be inserted into the column.
871
+     *
872
+     * @return $this This QueryBuilder instance.
873
+     */
874
+    public function setValue($column, $value) {
875
+        $this->queryBuilder->setValue(
876
+            $this->helper->quoteColumnName($column),
877
+            $value
878
+        );
879
+
880
+        return $this;
881
+    }
882
+
883
+    /**
884
+     * Specifies values for an insert query indexed by column names.
885
+     * Replaces any previous values, if any.
886
+     *
887
+     * <code>
888
+     *     $qb = $conn->getQueryBuilder()
889
+     *         ->insert('users')
890
+     *         ->values(
891
+     *             array(
892
+     *                 'name' => '?',
893
+     *                 'password' => '?'
894
+     *             )
895
+     *         );
896
+     * </code>
897
+     *
898
+     * @param array $values The values to specify for the insert query indexed by column names.
899
+     *
900
+     * @return $this This QueryBuilder instance.
901
+     */
902
+    public function values(array $values) {
903
+        $quotedValues = [];
904
+        foreach ($values as $key => $value) {
905
+            $quotedValues[$this->helper->quoteColumnName($key)] = $value;
906
+        }
907
+
908
+        $this->queryBuilder->values($quotedValues);
909
+
910
+        return $this;
911
+    }
912
+
913
+    /**
914
+     * Specifies a restriction over the groups of the query.
915
+     * Replaces any previous having restrictions, if any.
916
+     *
917
+     * @param mixed ...$having The restriction over the groups.
918
+     *
919
+     * @return $this This QueryBuilder instance.
920
+     */
921
+    public function having(...$having) {
922
+        call_user_func_array(
923
+            [$this->queryBuilder, 'having'],
924
+            $having
925
+        );
926
+
927
+        return $this;
928
+    }
929
+
930
+    /**
931
+     * Adds a restriction over the groups of the query, forming a logical
932
+     * conjunction with any existing having restrictions.
933
+     *
934
+     * @param mixed ...$having The restriction to append.
935
+     *
936
+     * @return $this This QueryBuilder instance.
937
+     */
938
+    public function andHaving(...$having) {
939
+        call_user_func_array(
940
+            [$this->queryBuilder, 'andHaving'],
941
+            $having
942
+        );
943
+
944
+        return $this;
945
+    }
946
+
947
+    /**
948
+     * Adds a restriction over the groups of the query, forming a logical
949
+     * disjunction with any existing having restrictions.
950
+     *
951
+     * @param mixed ...$having The restriction to add.
952
+     *
953
+     * @return $this This QueryBuilder instance.
954
+     */
955
+    public function orHaving(...$having) {
956
+        call_user_func_array(
957
+            [$this->queryBuilder, 'orHaving'],
958
+            $having
959
+        );
960
+
961
+        return $this;
962
+    }
963
+
964
+    /**
965
+     * Specifies an ordering for the query results.
966
+     * Replaces any previously specified orderings, if any.
967
+     *
968
+     * @param string $sort The ordering expression.
969
+     * @param string $order The ordering direction.
970
+     *
971
+     * @return $this This QueryBuilder instance.
972
+     */
973
+    public function orderBy($sort, $order = null) {
974
+        $this->queryBuilder->orderBy(
975
+            $this->helper->quoteColumnName($sort),
976
+            $order
977
+        );
978
+
979
+        return $this;
980
+    }
981
+
982
+    /**
983
+     * Adds an ordering to the query results.
984
+     *
985
+     * @param string $sort The ordering expression.
986
+     * @param string $order The ordering direction.
987
+     *
988
+     * @return $this This QueryBuilder instance.
989
+     */
990
+    public function addOrderBy($sort, $order = null) {
991
+        $this->queryBuilder->addOrderBy(
992
+            $this->helper->quoteColumnName($sort),
993
+            $order
994
+        );
995
+
996
+        return $this;
997
+    }
998
+
999
+    /**
1000
+     * Gets a query part by its name.
1001
+     *
1002
+     * @param string $queryPartName
1003
+     *
1004
+     * @return mixed
1005
+     */
1006
+    public function getQueryPart($queryPartName) {
1007
+        return $this->queryBuilder->getQueryPart($queryPartName);
1008
+    }
1009
+
1010
+    /**
1011
+     * Gets all query parts.
1012
+     *
1013
+     * @return array
1014
+     */
1015
+    public function getQueryParts() {
1016
+        return $this->queryBuilder->getQueryParts();
1017
+    }
1018
+
1019
+    /**
1020
+     * Resets SQL parts.
1021
+     *
1022
+     * @param array|null $queryPartNames
1023
+     *
1024
+     * @return $this This QueryBuilder instance.
1025
+     */
1026
+    public function resetQueryParts($queryPartNames = null) {
1027
+        $this->queryBuilder->resetQueryParts($queryPartNames);
1028
+
1029
+        return $this;
1030
+    }
1031
+
1032
+    /**
1033
+     * Resets a single SQL part.
1034
+     *
1035
+     * @param string $queryPartName
1036
+     *
1037
+     * @return $this This QueryBuilder instance.
1038
+     */
1039
+    public function resetQueryPart($queryPartName) {
1040
+        $this->queryBuilder->resetQueryPart($queryPartName);
1041
+
1042
+        return $this;
1043
+    }
1044
+
1045
+    /**
1046
+     * Creates a new named parameter and bind the value $value to it.
1047
+     *
1048
+     * This method provides a shortcut for PDOStatement::bindValue
1049
+     * when using prepared statements.
1050
+     *
1051
+     * The parameter $value specifies the value that you want to bind. If
1052
+     * $placeholder is not provided bindValue() will automatically create a
1053
+     * placeholder for you. An automatic placeholder will be of the name
1054
+     * ':dcValue1', ':dcValue2' etc.
1055
+     *
1056
+     * For more information see {@link http://php.net/pdostatement-bindparam}
1057
+     *
1058
+     * Example:
1059
+     * <code>
1060
+     * $value = 2;
1061
+     * $q->eq( 'id', $q->bindValue( $value ) );
1062
+     * $stmt = $q->executeQuery(); // executed with 'id = 2'
1063
+     * </code>
1064
+     *
1065
+     * @license New BSD License
1066
+     * @link http://www.zetacomponents.org
1067
+     *
1068
+     * @param mixed $value
1069
+     * @param mixed $type
1070
+     * @param string $placeHolder The name to bind with. The string must start with a colon ':'.
1071
+     *
1072
+     * @return IParameter the placeholder name used.
1073
+     */
1074
+    public function createNamedParameter($value, $type = IQueryBuilder::PARAM_STR, $placeHolder = null) {
1075
+        return new Parameter($this->queryBuilder->createNamedParameter($value, $type, $placeHolder));
1076
+    }
1077
+
1078
+    /**
1079
+     * Creates a new positional parameter and bind the given value to it.
1080
+     *
1081
+     * Attention: If you are using positional parameters with the query builder you have
1082
+     * to be very careful to bind all parameters in the order they appear in the SQL
1083
+     * statement , otherwise they get bound in the wrong order which can lead to serious
1084
+     * bugs in your code.
1085
+     *
1086
+     * Example:
1087
+     * <code>
1088
+     *  $qb = $conn->getQueryBuilder();
1089
+     *  $qb->select('u.*')
1090
+     *     ->from('users', 'u')
1091
+     *     ->where('u.username = ' . $qb->createPositionalParameter('Foo', IQueryBuilder::PARAM_STR))
1092
+     *     ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', IQueryBuilder::PARAM_STR))
1093
+     * </code>
1094
+     *
1095
+     * @param mixed $value
1096
+     * @param integer $type
1097
+     *
1098
+     * @return IParameter
1099
+     */
1100
+    public function createPositionalParameter($value, $type = IQueryBuilder::PARAM_STR) {
1101
+        return new Parameter($this->queryBuilder->createPositionalParameter($value, $type));
1102
+    }
1103
+
1104
+    /**
1105
+     * Creates a new parameter
1106
+     *
1107
+     * Example:
1108
+     * <code>
1109
+     *  $qb = $conn->getQueryBuilder();
1110
+     *  $qb->select('u.*')
1111
+     *     ->from('users', 'u')
1112
+     *     ->where('u.username = ' . $qb->createParameter('name'))
1113
+     *     ->setParameter('name', 'Bar', IQueryBuilder::PARAM_STR))
1114
+     * </code>
1115
+     *
1116
+     * @param string $name
1117
+     *
1118
+     * @return IParameter
1119
+     */
1120
+    public function createParameter($name) {
1121
+        return new Parameter(':' . $name);
1122
+    }
1123
+
1124
+    /**
1125
+     * Creates a new function
1126
+     *
1127
+     * Attention: Column names inside the call have to be quoted before hand
1128
+     *
1129
+     * Example:
1130
+     * <code>
1131
+     *  $qb = $conn->getQueryBuilder();
1132
+     *  $qb->select($qb->createFunction('COUNT(*)'))
1133
+     *     ->from('users', 'u')
1134
+     *  echo $qb->getSQL(); // SELECT COUNT(*) FROM `users` u
1135
+     * </code>
1136
+     * <code>
1137
+     *  $qb = $conn->getQueryBuilder();
1138
+     *  $qb->select($qb->createFunction('COUNT(`column`)'))
1139
+     *     ->from('users', 'u')
1140
+     *  echo $qb->getSQL(); // SELECT COUNT(`column`) FROM `users` u
1141
+     * </code>
1142
+     *
1143
+     * @param string $call
1144
+     *
1145
+     * @return IQueryFunction
1146
+     */
1147
+    public function createFunction($call) {
1148
+        return new QueryFunction($call);
1149
+    }
1150
+
1151
+    /**
1152
+     * Used to get the id of the last inserted element
1153
+     * @return int
1154
+     * @throws \BadMethodCallException When being called before an insert query has been run.
1155
+     */
1156
+    public function getLastInsertId() {
1157
+        if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::INSERT && $this->lastInsertedTable) {
1158
+            // lastInsertId() needs the prefix but no quotes
1159
+            $table = $this->prefixTableName($this->lastInsertedTable);
1160
+            return (int) $this->connection->lastInsertId($table);
1161
+        }
1162
+
1163
+        throw new \BadMethodCallException('Invalid call to getLastInsertId without using insert() before.');
1164
+    }
1165
+
1166
+    /**
1167
+     * Returns the table name quoted and with database prefix as needed by the implementation
1168
+     *
1169
+     * @param string $table
1170
+     * @return string
1171
+     */
1172
+    public function getTableName($table) {
1173
+        if ($table instanceof IQueryFunction) {
1174
+            return (string) $table;
1175
+        }
1176
+
1177
+        $table = $this->prefixTableName($table);
1178
+        return $this->helper->quoteColumnName($table);
1179
+    }
1180
+
1181
+    /**
1182
+     * Returns the table name with database prefix as needed by the implementation
1183
+     *
1184
+     * @param string $table
1185
+     * @return string
1186
+     */
1187
+    protected function prefixTableName($table) {
1188
+        if ($this->automaticTablePrefix === false || strpos($table, '*PREFIX*') === 0) {
1189
+            return $table;
1190
+        }
1191
+
1192
+        return '*PREFIX*' . $table;
1193
+    }
1194
+
1195
+    /**
1196
+     * Returns the column name quoted and with table alias prefix as needed by the implementation
1197
+     *
1198
+     * @param string $column
1199
+     * @param string $tableAlias
1200
+     * @return string
1201
+     */
1202
+    public function getColumnName($column, $tableAlias = '') {
1203
+        if ($tableAlias !== '') {
1204
+            $tableAlias .= '.';
1205
+        }
1206
+
1207
+        return $this->helper->quoteColumnName($tableAlias . $column);
1208
+    }
1209
+
1210
+    /**
1211
+     * Returns the column name quoted and with table alias prefix as needed by the implementation
1212
+     *
1213
+     * @param string $alias
1214
+     * @return string
1215
+     */
1216
+    public function quoteAlias($alias) {
1217
+        if ($alias === '' || $alias === null) {
1218
+            return $alias;
1219
+        }
1220
+
1221
+        return $this->helper->quoteColumnName($alias);
1222
+    }
1223 1223
 }
Please login to merge, or discard this patch.
lib/public/DB/QueryBuilder/IQueryBuilder.php 1 patch
Indentation   +867 added lines, -867 removed lines patch added patch discarded remove patch
@@ -34,871 +34,871 @@
 block discarded – undo
34 34
  */
35 35
 interface IQueryBuilder {
36 36
 
37
-	/**
38
-	 * @since 9.0.0
39
-	 */
40
-	public const PARAM_NULL = \PDO::PARAM_NULL;
41
-	/**
42
-	 * @since 9.0.0
43
-	 */
44
-	public const PARAM_BOOL = \PDO::PARAM_BOOL;
45
-	/**
46
-	 * @since 9.0.0
47
-	 */
48
-	public const PARAM_INT = \PDO::PARAM_INT;
49
-	/**
50
-	 * @since 9.0.0
51
-	 */
52
-	public const PARAM_STR = \PDO::PARAM_STR;
53
-	/**
54
-	 * @since 9.0.0
55
-	 */
56
-	public const PARAM_LOB = \PDO::PARAM_LOB;
57
-	/**
58
-	 * @since 9.0.0
59
-	 */
60
-	public const PARAM_DATE = 'datetime';
61
-
62
-	/**
63
-	 * @since 9.0.0
64
-	 */
65
-	public const PARAM_INT_ARRAY = Connection::PARAM_INT_ARRAY;
66
-	/**
67
-	 * @since 9.0.0
68
-	 */
69
-	public const PARAM_STR_ARRAY = Connection::PARAM_STR_ARRAY;
70
-
71
-
72
-	/**
73
-	 * Enable/disable automatic prefixing of table names with the oc_ prefix
74
-	 *
75
-	 * @param bool $enabled If set to true table names will be prefixed with the
76
-	 * owncloud database prefix automatically.
77
-	 * @since 8.2.0
78
-	 */
79
-	public function automaticTablePrefix($enabled);
80
-
81
-	/**
82
-	 * Gets an ExpressionBuilder used for object-oriented construction of query expressions.
83
-	 * This producer method is intended for convenient inline usage. Example:
84
-	 *
85
-	 * <code>
86
-	 *     $qb = $conn->getQueryBuilder()
87
-	 *         ->select('u')
88
-	 *         ->from('users', 'u')
89
-	 *         ->where($qb->expr()->eq('u.id', 1));
90
-	 * </code>
91
-	 *
92
-	 * For more complex expression construction, consider storing the expression
93
-	 * builder object in a local variable.
94
-	 *
95
-	 * @return \OCP\DB\QueryBuilder\IExpressionBuilder
96
-	 * @since 8.2.0
97
-	 */
98
-	public function expr();
99
-
100
-	/**
101
-	 * Gets an FunctionBuilder used for object-oriented construction of query functions.
102
-	 * This producer method is intended for convenient inline usage. Example:
103
-	 *
104
-	 * <code>
105
-	 *     $qb = $conn->getQueryBuilder()
106
-	 *         ->select('u')
107
-	 *         ->from('users', 'u')
108
-	 *         ->where($qb->fun()->md5('u.id'));
109
-	 * </code>
110
-	 *
111
-	 * For more complex function construction, consider storing the function
112
-	 * builder object in a local variable.
113
-	 *
114
-	 * @return \OCP\DB\QueryBuilder\IFunctionBuilder
115
-	 * @since 12.0.0
116
-	 */
117
-	public function func();
118
-
119
-	/**
120
-	 * Gets the type of the currently built query.
121
-	 *
122
-	 * @return integer
123
-	 * @since 8.2.0
124
-	 */
125
-	public function getType();
126
-
127
-	/**
128
-	 * Gets the associated DBAL Connection for this query builder.
129
-	 *
130
-	 * @return \OCP\IDBConnection
131
-	 * @since 8.2.0
132
-	 */
133
-	public function getConnection();
134
-
135
-	/**
136
-	 * Gets the state of this query builder instance.
137
-	 *
138
-	 * @return integer Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.
139
-	 * @since 8.2.0
140
-	 */
141
-	public function getState();
142
-
143
-	/**
144
-	 * Executes this query using the bound parameters and their types.
145
-	 *
146
-	 * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate}
147
-	 * for insert, update and delete statements.
148
-	 *
149
-	 * @return \Doctrine\DBAL\Driver\Statement|int
150
-	 * @since 8.2.0
151
-	 */
152
-	public function execute();
153
-
154
-	/**
155
-	 * Gets the complete SQL string formed by the current specifications of this QueryBuilder.
156
-	 *
157
-	 * <code>
158
-	 *     $qb = $conn->getQueryBuilder()
159
-	 *         ->select('u')
160
-	 *         ->from('User', 'u')
161
-	 *     echo $qb->getSQL(); // SELECT u FROM User u
162
-	 * </code>
163
-	 *
164
-	 * @return string The SQL query string.
165
-	 * @since 8.2.0
166
-	 */
167
-	public function getSQL();
168
-
169
-	/**
170
-	 * Sets a query parameter for the query being constructed.
171
-	 *
172
-	 * <code>
173
-	 *     $qb = $conn->getQueryBuilder()
174
-	 *         ->select('u')
175
-	 *         ->from('users', 'u')
176
-	 *         ->where('u.id = :user_id')
177
-	 *         ->setParameter(':user_id', 1);
178
-	 * </code>
179
-	 *
180
-	 * @param string|integer $key The parameter position or name.
181
-	 * @param mixed $value The parameter value.
182
-	 * @param string|null|int $type One of the IQueryBuilder::PARAM_* constants.
183
-	 *
184
-	 * @return $this This QueryBuilder instance.
185
-	 * @since 8.2.0
186
-	 */
187
-	public function setParameter($key, $value, $type = null);
188
-
189
-	/**
190
-	 * Sets a collection of query parameters for the query being constructed.
191
-	 *
192
-	 * <code>
193
-	 *     $qb = $conn->getQueryBuilder()
194
-	 *         ->select('u')
195
-	 *         ->from('users', 'u')
196
-	 *         ->where('u.id = :user_id1 OR u.id = :user_id2')
197
-	 *         ->setParameters(array(
198
-	 *             ':user_id1' => 1,
199
-	 *             ':user_id2' => 2
200
-	 *         ));
201
-	 * </code>
202
-	 *
203
-	 * @param array $params The query parameters to set.
204
-	 * @param array $types The query parameters types to set.
205
-	 *
206
-	 * @return $this This QueryBuilder instance.
207
-	 * @since 8.2.0
208
-	 */
209
-	public function setParameters(array $params, array $types = []);
210
-
211
-	/**
212
-	 * Gets all defined query parameters for the query being constructed indexed by parameter index or name.
213
-	 *
214
-	 * @return array The currently defined query parameters indexed by parameter index or name.
215
-	 * @since 8.2.0
216
-	 */
217
-	public function getParameters();
218
-
219
-	/**
220
-	 * Gets a (previously set) query parameter of the query being constructed.
221
-	 *
222
-	 * @param mixed $key The key (index or name) of the bound parameter.
223
-	 *
224
-	 * @return mixed The value of the bound parameter.
225
-	 * @since 8.2.0
226
-	 */
227
-	public function getParameter($key);
228
-
229
-	/**
230
-	 * Gets all defined query parameter types for the query being constructed indexed by parameter index or name.
231
-	 *
232
-	 * @return array The currently defined query parameter types indexed by parameter index or name.
233
-	 * @since 8.2.0
234
-	 */
235
-	public function getParameterTypes();
236
-
237
-	/**
238
-	 * Gets a (previously set) query parameter type of the query being constructed.
239
-	 *
240
-	 * @param mixed $key The key (index or name) of the bound parameter type.
241
-	 *
242
-	 * @return mixed The value of the bound parameter type.
243
-	 * @since 8.2.0
244
-	 */
245
-	public function getParameterType($key);
246
-
247
-	/**
248
-	 * Sets the position of the first result to retrieve (the "offset").
249
-	 *
250
-	 * @param integer $firstResult The first result to return.
251
-	 *
252
-	 * @return $this This QueryBuilder instance.
253
-	 * @since 8.2.0
254
-	 */
255
-	public function setFirstResult($firstResult);
256
-
257
-	/**
258
-	 * Gets the position of the first result the query object was set to retrieve (the "offset").
259
-	 * Returns NULL if {@link setFirstResult} was not applied to this QueryBuilder.
260
-	 *
261
-	 * @return integer The position of the first result.
262
-	 * @since 8.2.0
263
-	 */
264
-	public function getFirstResult();
265
-
266
-	/**
267
-	 * Sets the maximum number of results to retrieve (the "limit").
268
-	 *
269
-	 * @param integer $maxResults The maximum number of results to retrieve.
270
-	 *
271
-	 * @return $this This QueryBuilder instance.
272
-	 * @since 8.2.0
273
-	 */
274
-	public function setMaxResults($maxResults);
275
-
276
-	/**
277
-	 * Gets the maximum number of results the query object was set to retrieve (the "limit").
278
-	 * Returns NULL if {@link setMaxResults} was not applied to this query builder.
279
-	 *
280
-	 * @return integer The maximum number of results.
281
-	 * @since 8.2.0
282
-	 */
283
-	public function getMaxResults();
284
-
285
-	/**
286
-	 * Specifies an item that is to be returned in the query result.
287
-	 * Replaces any previously specified selections, if any.
288
-	 *
289
-	 * <code>
290
-	 *     $qb = $conn->getQueryBuilder()
291
-	 *         ->select('u.id', 'p.id')
292
-	 *         ->from('users', 'u')
293
-	 *         ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
294
-	 * </code>
295
-	 *
296
-	 * @param mixed ...$selects The selection expressions.
297
-	 *
298
-	 * @return $this This QueryBuilder instance.
299
-	 * @since 8.2.0
300
-	 */
301
-	public function select(...$selects);
302
-
303
-	/**
304
-	 * Specifies an item that is to be returned with a different name in the query result.
305
-	 *
306
-	 * <code>
307
-	 *     $qb = $conn->getQueryBuilder()
308
-	 *         ->selectAlias('u.id', 'user_id')
309
-	 *         ->from('users', 'u')
310
-	 *         ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
311
-	 * </code>
312
-	 *
313
-	 * @param mixed $select The selection expressions.
314
-	 * @param string $alias The column alias used in the constructed query.
315
-	 *
316
-	 * @return $this This QueryBuilder instance.
317
-	 * @since 8.2.1
318
-	 */
319
-	public function selectAlias($select, $alias);
320
-
321
-	/**
322
-	 * Specifies an item that is to be returned uniquely in the query result.
323
-	 *
324
-	 * <code>
325
-	 *     $qb = $conn->getQueryBuilder()
326
-	 *         ->selectDistinct('type')
327
-	 *         ->from('users');
328
-	 * </code>
329
-	 *
330
-	 * @param mixed $select The selection expressions.
331
-	 *
332
-	 * @return $this This QueryBuilder instance.
333
-	 * @since 9.0.0
334
-	 */
335
-	public function selectDistinct($select);
336
-
337
-	/**
338
-	 * Adds an item that is to be returned in the query result.
339
-	 *
340
-	 * <code>
341
-	 *     $qb = $conn->getQueryBuilder()
342
-	 *         ->select('u.id')
343
-	 *         ->addSelect('p.id')
344
-	 *         ->from('users', 'u')
345
-	 *         ->leftJoin('u', 'phonenumbers', 'u.id = p.user_id');
346
-	 * </code>
347
-	 *
348
-	 * @param mixed ...$select The selection expression.
349
-	 *
350
-	 * @return $this This QueryBuilder instance.
351
-	 * @since 8.2.0
352
-	 */
353
-	public function addSelect(...$select);
354
-
355
-	/**
356
-	 * Turns the query being built into a bulk delete query that ranges over
357
-	 * a certain table.
358
-	 *
359
-	 * <code>
360
-	 *     $qb = $conn->getQueryBuilder()
361
-	 *         ->delete('users', 'u')
362
-	 *         ->where('u.id = :user_id');
363
-	 *         ->setParameter(':user_id', 1);
364
-	 * </code>
365
-	 *
366
-	 * @param string $delete The table whose rows are subject to the deletion.
367
-	 * @param string $alias The table alias used in the constructed query.
368
-	 *
369
-	 * @return $this This QueryBuilder instance.
370
-	 * @since 8.2.0
371
-	 */
372
-	public function delete($delete = null, $alias = null);
373
-
374
-	/**
375
-	 * Turns the query being built into a bulk update query that ranges over
376
-	 * a certain table
377
-	 *
378
-	 * <code>
379
-	 *     $qb = $conn->getQueryBuilder()
380
-	 *         ->update('users', 'u')
381
-	 *         ->set('u.password', md5('password'))
382
-	 *         ->where('u.id = ?');
383
-	 * </code>
384
-	 *
385
-	 * @param string $update The table whose rows are subject to the update.
386
-	 * @param string $alias The table alias used in the constructed query.
387
-	 *
388
-	 * @return $this This QueryBuilder instance.
389
-	 * @since 8.2.0
390
-	 */
391
-	public function update($update = null, $alias = null);
392
-
393
-	/**
394
-	 * Turns the query being built into an insert query that inserts into
395
-	 * a certain table
396
-	 *
397
-	 * <code>
398
-	 *     $qb = $conn->getQueryBuilder()
399
-	 *         ->insert('users')
400
-	 *         ->values(
401
-	 *             array(
402
-	 *                 'name' => '?',
403
-	 *                 'password' => '?'
404
-	 *             )
405
-	 *         );
406
-	 * </code>
407
-	 *
408
-	 * @param string $insert The table into which the rows should be inserted.
409
-	 *
410
-	 * @return $this This QueryBuilder instance.
411
-	 * @since 8.2.0
412
-	 */
413
-	public function insert($insert = null);
414
-
415
-	/**
416
-	 * Creates and adds a query root corresponding to the table identified by the
417
-	 * given alias, forming a cartesian product with any existing query roots.
418
-	 *
419
-	 * <code>
420
-	 *     $qb = $conn->getQueryBuilder()
421
-	 *         ->select('u.id')
422
-	 *         ->from('users', 'u')
423
-	 * </code>
424
-	 *
425
-	 * @param string $from The table.
426
-	 * @param string|null $alias The alias of the table.
427
-	 *
428
-	 * @return $this This QueryBuilder instance.
429
-	 * @since 8.2.0
430
-	 */
431
-	public function from($from, $alias = null);
432
-
433
-	/**
434
-	 * Creates and adds a join to the query.
435
-	 *
436
-	 * <code>
437
-	 *     $qb = $conn->getQueryBuilder()
438
-	 *         ->select('u.name')
439
-	 *         ->from('users', 'u')
440
-	 *         ->join('u', 'phonenumbers', 'p', 'p.is_primary = 1');
441
-	 * </code>
442
-	 *
443
-	 * @param string $fromAlias The alias that points to a from clause.
444
-	 * @param string $join The table name to join.
445
-	 * @param string $alias The alias of the join table.
446
-	 * @param string $condition The condition for the join.
447
-	 *
448
-	 * @return $this This QueryBuilder instance.
449
-	 * @since 8.2.0
450
-	 */
451
-	public function join($fromAlias, $join, $alias, $condition = null);
452
-
453
-	/**
454
-	 * Creates and adds a join to the query.
455
-	 *
456
-	 * <code>
457
-	 *     $qb = $conn->getQueryBuilder()
458
-	 *         ->select('u.name')
459
-	 *         ->from('users', 'u')
460
-	 *         ->innerJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
461
-	 * </code>
462
-	 *
463
-	 * @param string $fromAlias The alias that points to a from clause.
464
-	 * @param string $join The table name to join.
465
-	 * @param string $alias The alias of the join table.
466
-	 * @param string $condition The condition for the join.
467
-	 *
468
-	 * @return $this This QueryBuilder instance.
469
-	 * @since 8.2.0
470
-	 */
471
-	public function innerJoin($fromAlias, $join, $alias, $condition = null);
472
-
473
-	/**
474
-	 * Creates and adds a left join to the query.
475
-	 *
476
-	 * <code>
477
-	 *     $qb = $conn->getQueryBuilder()
478
-	 *         ->select('u.name')
479
-	 *         ->from('users', 'u')
480
-	 *         ->leftJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
481
-	 * </code>
482
-	 *
483
-	 * @param string $fromAlias The alias that points to a from clause.
484
-	 * @param string $join The table name to join.
485
-	 * @param string $alias The alias of the join table.
486
-	 * @param string $condition The condition for the join.
487
-	 *
488
-	 * @return $this This QueryBuilder instance.
489
-	 * @since 8.2.0
490
-	 */
491
-	public function leftJoin($fromAlias, $join, $alias, $condition = null);
492
-
493
-	/**
494
-	 * Creates and adds a right join to the query.
495
-	 *
496
-	 * <code>
497
-	 *     $qb = $conn->getQueryBuilder()
498
-	 *         ->select('u.name')
499
-	 *         ->from('users', 'u')
500
-	 *         ->rightJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
501
-	 * </code>
502
-	 *
503
-	 * @param string $fromAlias The alias that points to a from clause.
504
-	 * @param string $join The table name to join.
505
-	 * @param string $alias The alias of the join table.
506
-	 * @param string $condition The condition for the join.
507
-	 *
508
-	 * @return $this This QueryBuilder instance.
509
-	 * @since 8.2.0
510
-	 */
511
-	public function rightJoin($fromAlias, $join, $alias, $condition = null);
512
-
513
-	/**
514
-	 * Sets a new value for a column in a bulk update query.
515
-	 *
516
-	 * <code>
517
-	 *     $qb = $conn->getQueryBuilder()
518
-	 *         ->update('users', 'u')
519
-	 *         ->set('u.password', md5('password'))
520
-	 *         ->where('u.id = ?');
521
-	 * </code>
522
-	 *
523
-	 * @param string $key The column to set.
524
-	 * @param IParameter|string $value The value, expression, placeholder, etc.
525
-	 *
526
-	 * @return $this This QueryBuilder instance.
527
-	 * @since 8.2.0
528
-	 */
529
-	public function set($key, $value);
530
-
531
-	/**
532
-	 * Specifies one or more restrictions to the query result.
533
-	 * Replaces any previously specified restrictions, if any.
534
-	 *
535
-	 * <code>
536
-	 *     $qb = $conn->getQueryBuilder()
537
-	 *         ->select('u.name')
538
-	 *         ->from('users', 'u')
539
-	 *         ->where('u.id = ?');
540
-	 *
541
-	 *     // You can optionally programatically build and/or expressions
542
-	 *     $qb = $conn->getQueryBuilder();
543
-	 *
544
-	 *     $or = $qb->expr()->orx();
545
-	 *     $or->add($qb->expr()->eq('u.id', 1));
546
-	 *     $or->add($qb->expr()->eq('u.id', 2));
547
-	 *
548
-	 *     $qb->update('users', 'u')
549
-	 *         ->set('u.password', md5('password'))
550
-	 *         ->where($or);
551
-	 * </code>
552
-	 *
553
-	 * @param mixed $predicates The restriction predicates.
554
-	 *
555
-	 * @return $this This QueryBuilder instance.
556
-	 * @since 8.2.0
557
-	 */
558
-	public function where(...$predicates);
559
-
560
-	/**
561
-	 * Adds one or more restrictions to the query results, forming a logical
562
-	 * conjunction with any previously specified restrictions.
563
-	 *
564
-	 * <code>
565
-	 *     $qb = $conn->getQueryBuilder()
566
-	 *         ->select('u')
567
-	 *         ->from('users', 'u')
568
-	 *         ->where('u.username LIKE ?')
569
-	 *         ->andWhere('u.is_active = 1');
570
-	 * </code>
571
-	 *
572
-	 * @param mixed ...$where The query restrictions.
573
-	 *
574
-	 * @return $this This QueryBuilder instance.
575
-	 *
576
-	 * @see where()
577
-	 * @since 8.2.0
578
-	 */
579
-	public function andWhere(...$where);
580
-
581
-	/**
582
-	 * Adds one or more restrictions to the query results, forming a logical
583
-	 * disjunction with any previously specified restrictions.
584
-	 *
585
-	 * <code>
586
-	 *     $qb = $conn->getQueryBuilder()
587
-	 *         ->select('u.name')
588
-	 *         ->from('users', 'u')
589
-	 *         ->where('u.id = 1')
590
-	 *         ->orWhere('u.id = 2');
591
-	 * </code>
592
-	 *
593
-	 * @param mixed ...$where The WHERE statement.
594
-	 *
595
-	 * @return $this This QueryBuilder instance.
596
-	 *
597
-	 * @see where()
598
-	 * @since 8.2.0
599
-	 */
600
-	public function orWhere(...$where);
601
-
602
-	/**
603
-	 * Specifies a grouping over the results of the query.
604
-	 * Replaces any previously specified groupings, if any.
605
-	 *
606
-	 * <code>
607
-	 *     $qb = $conn->getQueryBuilder()
608
-	 *         ->select('u.name')
609
-	 *         ->from('users', 'u')
610
-	 *         ->groupBy('u.id');
611
-	 * </code>
612
-	 *
613
-	 * @param mixed ...$groupBys The grouping expression.
614
-	 *
615
-	 * @return $this This QueryBuilder instance.
616
-	 * @since 8.2.0
617
-	 */
618
-	public function groupBy(...$groupBys);
619
-
620
-	/**
621
-	 * Adds a grouping expression to the query.
622
-	 *
623
-	 * <code>
624
-	 *     $qb = $conn->getQueryBuilder()
625
-	 *         ->select('u.name')
626
-	 *         ->from('users', 'u')
627
-	 *         ->groupBy('u.lastLogin');
628
-	 *         ->addGroupBy('u.createdAt')
629
-	 * </code>
630
-	 *
631
-	 * @param mixed ...$groupBy The grouping expression.
632
-	 *
633
-	 * @return $this This QueryBuilder instance.
634
-	 * @since 8.2.0
635
-	 */
636
-	public function addGroupBy(...$groupBy);
637
-
638
-	/**
639
-	 * Sets a value for a column in an insert query.
640
-	 *
641
-	 * <code>
642
-	 *     $qb = $conn->getQueryBuilder()
643
-	 *         ->insert('users')
644
-	 *         ->values(
645
-	 *             array(
646
-	 *                 'name' => '?'
647
-	 *             )
648
-	 *         )
649
-	 *         ->setValue('password', '?');
650
-	 * </code>
651
-	 *
652
-	 * @param string $column The column into which the value should be inserted.
653
-	 * @param string $value The value that should be inserted into the column.
654
-	 *
655
-	 * @return $this This QueryBuilder instance.
656
-	 * @since 8.2.0
657
-	 */
658
-	public function setValue($column, $value);
659
-
660
-	/**
661
-	 * Specifies values for an insert query indexed by column names.
662
-	 * Replaces any previous values, if any.
663
-	 *
664
-	 * <code>
665
-	 *     $qb = $conn->getQueryBuilder()
666
-	 *         ->insert('users')
667
-	 *         ->values(
668
-	 *             array(
669
-	 *                 'name' => '?',
670
-	 *                 'password' => '?'
671
-	 *             )
672
-	 *         );
673
-	 * </code>
674
-	 *
675
-	 * @param array $values The values to specify for the insert query indexed by column names.
676
-	 *
677
-	 * @return $this This QueryBuilder instance.
678
-	 * @since 8.2.0
679
-	 */
680
-	public function values(array $values);
681
-
682
-	/**
683
-	 * Specifies a restriction over the groups of the query.
684
-	 * Replaces any previous having restrictions, if any.
685
-	 *
686
-	 * @param mixed ...$having The restriction over the groups.
687
-	 *
688
-	 * @return $this This QueryBuilder instance.
689
-	 * @since 8.2.0
690
-	 */
691
-	public function having(...$having);
692
-
693
-	/**
694
-	 * Adds a restriction over the groups of the query, forming a logical
695
-	 * conjunction with any existing having restrictions.
696
-	 *
697
-	 * @param mixed ...$having The restriction to append.
698
-	 *
699
-	 * @return $this This QueryBuilder instance.
700
-	 * @since 8.2.0
701
-	 */
702
-	public function andHaving(...$having);
703
-
704
-	/**
705
-	 * Adds a restriction over the groups of the query, forming a logical
706
-	 * disjunction with any existing having restrictions.
707
-	 *
708
-	 * @param mixed ...$having The restriction to add.
709
-	 *
710
-	 * @return $this This QueryBuilder instance.
711
-	 * @since 8.2.0
712
-	 */
713
-	public function orHaving(...$having);
714
-
715
-	/**
716
-	 * Specifies an ordering for the query results.
717
-	 * Replaces any previously specified orderings, if any.
718
-	 *
719
-	 * @param string $sort The ordering expression.
720
-	 * @param string $order The ordering direction.
721
-	 *
722
-	 * @return $this This QueryBuilder instance.
723
-	 * @since 8.2.0
724
-	 */
725
-	public function orderBy($sort, $order = null);
726
-
727
-	/**
728
-	 * Adds an ordering to the query results.
729
-	 *
730
-	 * @param string $sort The ordering expression.
731
-	 * @param string $order The ordering direction.
732
-	 *
733
-	 * @return $this This QueryBuilder instance.
734
-	 * @since 8.2.0
735
-	 */
736
-	public function addOrderBy($sort, $order = null);
737
-
738
-	/**
739
-	 * Gets a query part by its name.
740
-	 *
741
-	 * @param string $queryPartName
742
-	 *
743
-	 * @return mixed
744
-	 * @since 8.2.0
745
-	 */
746
-	public function getQueryPart($queryPartName);
747
-
748
-	/**
749
-	 * Gets all query parts.
750
-	 *
751
-	 * @return array
752
-	 * @since 8.2.0
753
-	 */
754
-	public function getQueryParts();
755
-
756
-	/**
757
-	 * Resets SQL parts.
758
-	 *
759
-	 * @param array|null $queryPartNames
760
-	 *
761
-	 * @return $this This QueryBuilder instance.
762
-	 * @since 8.2.0
763
-	 */
764
-	public function resetQueryParts($queryPartNames = null);
765
-
766
-	/**
767
-	 * Resets a single SQL part.
768
-	 *
769
-	 * @param string $queryPartName
770
-	 *
771
-	 * @return $this This QueryBuilder instance.
772
-	 * @since 8.2.0
773
-	 */
774
-	public function resetQueryPart($queryPartName);
775
-
776
-	/**
777
-	 * Creates a new named parameter and bind the value $value to it.
778
-	 *
779
-	 * This method provides a shortcut for PDOStatement::bindValue
780
-	 * when using prepared statements.
781
-	 *
782
-	 * The parameter $value specifies the value that you want to bind. If
783
-	 * $placeholder is not provided bindValue() will automatically create a
784
-	 * placeholder for you. An automatic placeholder will be of the name
785
-	 * ':dcValue1', ':dcValue2' etc.
786
-	 *
787
-	 * For more information see {@link http://php.net/pdostatement-bindparam}
788
-	 *
789
-	 * Example:
790
-	 * <code>
791
-	 * $value = 2;
792
-	 * $q->eq( 'id', $q->bindValue( $value ) );
793
-	 * $stmt = $q->executeQuery(); // executed with 'id = 2'
794
-	 * </code>
795
-	 *
796
-	 * @license New BSD License
797
-	 * @link http://www.zetacomponents.org
798
-	 *
799
-	 * @param mixed $value
800
-	 * @param mixed $type
801
-	 * @param string $placeHolder The name to bind with. The string must start with a colon ':'.
802
-	 *
803
-	 * @return IParameter
804
-	 * @since 8.2.0
805
-	 */
806
-	public function createNamedParameter($value, $type = self::PARAM_STR, $placeHolder = null);
807
-
808
-	/**
809
-	 * Creates a new positional parameter and bind the given value to it.
810
-	 *
811
-	 * Attention: If you are using positional parameters with the query builder you have
812
-	 * to be very careful to bind all parameters in the order they appear in the SQL
813
-	 * statement , otherwise they get bound in the wrong order which can lead to serious
814
-	 * bugs in your code.
815
-	 *
816
-	 * Example:
817
-	 * <code>
818
-	 *  $qb = $conn->getQueryBuilder();
819
-	 *  $qb->select('u.*')
820
-	 *     ->from('users', 'u')
821
-	 *     ->where('u.username = ' . $qb->createPositionalParameter('Foo', IQueryBuilder::PARAM_STR))
822
-	 *     ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', IQueryBuilder::PARAM_STR))
823
-	 * </code>
824
-	 *
825
-	 * @param mixed $value
826
-	 * @param integer $type
827
-	 *
828
-	 * @return IParameter
829
-	 * @since 8.2.0
830
-	 */
831
-	public function createPositionalParameter($value, $type = self::PARAM_STR);
832
-
833
-	/**
834
-	 * Creates a new parameter
835
-	 *
836
-	 * Example:
837
-	 * <code>
838
-	 *  $qb = $conn->getQueryBuilder();
839
-	 *  $qb->select('u.*')
840
-	 *     ->from('users', 'u')
841
-	 *     ->where('u.username = ' . $qb->createParameter('name'))
842
-	 *     ->setParameter('name', 'Bar', IQueryBuilder::PARAM_STR))
843
-	 * </code>
844
-	 *
845
-	 * @param string $name
846
-	 *
847
-	 * @return IParameter
848
-	 * @since 8.2.0
849
-	 */
850
-	public function createParameter($name);
851
-
852
-	/**
853
-	 * Creates a new function
854
-	 *
855
-	 * Attention: Column names inside the call have to be quoted before hand
856
-	 *
857
-	 * Example:
858
-	 * <code>
859
-	 *  $qb = $conn->getQueryBuilder();
860
-	 *  $qb->select($qb->createFunction('COUNT(*)'))
861
-	 *     ->from('users', 'u')
862
-	 *  echo $qb->getSQL(); // SELECT COUNT(*) FROM `users` u
863
-	 * </code>
864
-	 * <code>
865
-	 *  $qb = $conn->getQueryBuilder();
866
-	 *  $qb->select($qb->createFunction('COUNT(`column`)'))
867
-	 *     ->from('users', 'u')
868
-	 *  echo $qb->getSQL(); // SELECT COUNT(`column`) FROM `users` u
869
-	 * </code>
870
-	 *
871
-	 * @param string $call
872
-	 *
873
-	 * @return IQueryFunction
874
-	 * @since 8.2.0
875
-	 */
876
-	public function createFunction($call);
877
-
878
-	/**
879
-	 * Used to get the id of the last inserted element
880
-	 * @return int
881
-	 * @throws \BadMethodCallException When being called before an insert query has been run.
882
-	 * @since 9.0.0
883
-	 */
884
-	public function getLastInsertId();
885
-
886
-	/**
887
-	 * Returns the table name quoted and with database prefix as needed by the implementation
888
-	 *
889
-	 * @param string $table
890
-	 * @return string
891
-	 * @since 9.0.0
892
-	 */
893
-	public function getTableName($table);
894
-
895
-	/**
896
-	 * Returns the column name quoted and with table alias prefix as needed by the implementation
897
-	 *
898
-	 * @param string $column
899
-	 * @param string $tableAlias
900
-	 * @return string
901
-	 * @since 9.0.0
902
-	 */
903
-	public function getColumnName($column, $tableAlias = '');
37
+    /**
38
+     * @since 9.0.0
39
+     */
40
+    public const PARAM_NULL = \PDO::PARAM_NULL;
41
+    /**
42
+     * @since 9.0.0
43
+     */
44
+    public const PARAM_BOOL = \PDO::PARAM_BOOL;
45
+    /**
46
+     * @since 9.0.0
47
+     */
48
+    public const PARAM_INT = \PDO::PARAM_INT;
49
+    /**
50
+     * @since 9.0.0
51
+     */
52
+    public const PARAM_STR = \PDO::PARAM_STR;
53
+    /**
54
+     * @since 9.0.0
55
+     */
56
+    public const PARAM_LOB = \PDO::PARAM_LOB;
57
+    /**
58
+     * @since 9.0.0
59
+     */
60
+    public const PARAM_DATE = 'datetime';
61
+
62
+    /**
63
+     * @since 9.0.0
64
+     */
65
+    public const PARAM_INT_ARRAY = Connection::PARAM_INT_ARRAY;
66
+    /**
67
+     * @since 9.0.0
68
+     */
69
+    public const PARAM_STR_ARRAY = Connection::PARAM_STR_ARRAY;
70
+
71
+
72
+    /**
73
+     * Enable/disable automatic prefixing of table names with the oc_ prefix
74
+     *
75
+     * @param bool $enabled If set to true table names will be prefixed with the
76
+     * owncloud database prefix automatically.
77
+     * @since 8.2.0
78
+     */
79
+    public function automaticTablePrefix($enabled);
80
+
81
+    /**
82
+     * Gets an ExpressionBuilder used for object-oriented construction of query expressions.
83
+     * This producer method is intended for convenient inline usage. Example:
84
+     *
85
+     * <code>
86
+     *     $qb = $conn->getQueryBuilder()
87
+     *         ->select('u')
88
+     *         ->from('users', 'u')
89
+     *         ->where($qb->expr()->eq('u.id', 1));
90
+     * </code>
91
+     *
92
+     * For more complex expression construction, consider storing the expression
93
+     * builder object in a local variable.
94
+     *
95
+     * @return \OCP\DB\QueryBuilder\IExpressionBuilder
96
+     * @since 8.2.0
97
+     */
98
+    public function expr();
99
+
100
+    /**
101
+     * Gets an FunctionBuilder used for object-oriented construction of query functions.
102
+     * This producer method is intended for convenient inline usage. Example:
103
+     *
104
+     * <code>
105
+     *     $qb = $conn->getQueryBuilder()
106
+     *         ->select('u')
107
+     *         ->from('users', 'u')
108
+     *         ->where($qb->fun()->md5('u.id'));
109
+     * </code>
110
+     *
111
+     * For more complex function construction, consider storing the function
112
+     * builder object in a local variable.
113
+     *
114
+     * @return \OCP\DB\QueryBuilder\IFunctionBuilder
115
+     * @since 12.0.0
116
+     */
117
+    public function func();
118
+
119
+    /**
120
+     * Gets the type of the currently built query.
121
+     *
122
+     * @return integer
123
+     * @since 8.2.0
124
+     */
125
+    public function getType();
126
+
127
+    /**
128
+     * Gets the associated DBAL Connection for this query builder.
129
+     *
130
+     * @return \OCP\IDBConnection
131
+     * @since 8.2.0
132
+     */
133
+    public function getConnection();
134
+
135
+    /**
136
+     * Gets the state of this query builder instance.
137
+     *
138
+     * @return integer Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.
139
+     * @since 8.2.0
140
+     */
141
+    public function getState();
142
+
143
+    /**
144
+     * Executes this query using the bound parameters and their types.
145
+     *
146
+     * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate}
147
+     * for insert, update and delete statements.
148
+     *
149
+     * @return \Doctrine\DBAL\Driver\Statement|int
150
+     * @since 8.2.0
151
+     */
152
+    public function execute();
153
+
154
+    /**
155
+     * Gets the complete SQL string formed by the current specifications of this QueryBuilder.
156
+     *
157
+     * <code>
158
+     *     $qb = $conn->getQueryBuilder()
159
+     *         ->select('u')
160
+     *         ->from('User', 'u')
161
+     *     echo $qb->getSQL(); // SELECT u FROM User u
162
+     * </code>
163
+     *
164
+     * @return string The SQL query string.
165
+     * @since 8.2.0
166
+     */
167
+    public function getSQL();
168
+
169
+    /**
170
+     * Sets a query parameter for the query being constructed.
171
+     *
172
+     * <code>
173
+     *     $qb = $conn->getQueryBuilder()
174
+     *         ->select('u')
175
+     *         ->from('users', 'u')
176
+     *         ->where('u.id = :user_id')
177
+     *         ->setParameter(':user_id', 1);
178
+     * </code>
179
+     *
180
+     * @param string|integer $key The parameter position or name.
181
+     * @param mixed $value The parameter value.
182
+     * @param string|null|int $type One of the IQueryBuilder::PARAM_* constants.
183
+     *
184
+     * @return $this This QueryBuilder instance.
185
+     * @since 8.2.0
186
+     */
187
+    public function setParameter($key, $value, $type = null);
188
+
189
+    /**
190
+     * Sets a collection of query parameters for the query being constructed.
191
+     *
192
+     * <code>
193
+     *     $qb = $conn->getQueryBuilder()
194
+     *         ->select('u')
195
+     *         ->from('users', 'u')
196
+     *         ->where('u.id = :user_id1 OR u.id = :user_id2')
197
+     *         ->setParameters(array(
198
+     *             ':user_id1' => 1,
199
+     *             ':user_id2' => 2
200
+     *         ));
201
+     * </code>
202
+     *
203
+     * @param array $params The query parameters to set.
204
+     * @param array $types The query parameters types to set.
205
+     *
206
+     * @return $this This QueryBuilder instance.
207
+     * @since 8.2.0
208
+     */
209
+    public function setParameters(array $params, array $types = []);
210
+
211
+    /**
212
+     * Gets all defined query parameters for the query being constructed indexed by parameter index or name.
213
+     *
214
+     * @return array The currently defined query parameters indexed by parameter index or name.
215
+     * @since 8.2.0
216
+     */
217
+    public function getParameters();
218
+
219
+    /**
220
+     * Gets a (previously set) query parameter of the query being constructed.
221
+     *
222
+     * @param mixed $key The key (index or name) of the bound parameter.
223
+     *
224
+     * @return mixed The value of the bound parameter.
225
+     * @since 8.2.0
226
+     */
227
+    public function getParameter($key);
228
+
229
+    /**
230
+     * Gets all defined query parameter types for the query being constructed indexed by parameter index or name.
231
+     *
232
+     * @return array The currently defined query parameter types indexed by parameter index or name.
233
+     * @since 8.2.0
234
+     */
235
+    public function getParameterTypes();
236
+
237
+    /**
238
+     * Gets a (previously set) query parameter type of the query being constructed.
239
+     *
240
+     * @param mixed $key The key (index or name) of the bound parameter type.
241
+     *
242
+     * @return mixed The value of the bound parameter type.
243
+     * @since 8.2.0
244
+     */
245
+    public function getParameterType($key);
246
+
247
+    /**
248
+     * Sets the position of the first result to retrieve (the "offset").
249
+     *
250
+     * @param integer $firstResult The first result to return.
251
+     *
252
+     * @return $this This QueryBuilder instance.
253
+     * @since 8.2.0
254
+     */
255
+    public function setFirstResult($firstResult);
256
+
257
+    /**
258
+     * Gets the position of the first result the query object was set to retrieve (the "offset").
259
+     * Returns NULL if {@link setFirstResult} was not applied to this QueryBuilder.
260
+     *
261
+     * @return integer The position of the first result.
262
+     * @since 8.2.0
263
+     */
264
+    public function getFirstResult();
265
+
266
+    /**
267
+     * Sets the maximum number of results to retrieve (the "limit").
268
+     *
269
+     * @param integer $maxResults The maximum number of results to retrieve.
270
+     *
271
+     * @return $this This QueryBuilder instance.
272
+     * @since 8.2.0
273
+     */
274
+    public function setMaxResults($maxResults);
275
+
276
+    /**
277
+     * Gets the maximum number of results the query object was set to retrieve (the "limit").
278
+     * Returns NULL if {@link setMaxResults} was not applied to this query builder.
279
+     *
280
+     * @return integer The maximum number of results.
281
+     * @since 8.2.0
282
+     */
283
+    public function getMaxResults();
284
+
285
+    /**
286
+     * Specifies an item that is to be returned in the query result.
287
+     * Replaces any previously specified selections, if any.
288
+     *
289
+     * <code>
290
+     *     $qb = $conn->getQueryBuilder()
291
+     *         ->select('u.id', 'p.id')
292
+     *         ->from('users', 'u')
293
+     *         ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
294
+     * </code>
295
+     *
296
+     * @param mixed ...$selects The selection expressions.
297
+     *
298
+     * @return $this This QueryBuilder instance.
299
+     * @since 8.2.0
300
+     */
301
+    public function select(...$selects);
302
+
303
+    /**
304
+     * Specifies an item that is to be returned with a different name in the query result.
305
+     *
306
+     * <code>
307
+     *     $qb = $conn->getQueryBuilder()
308
+     *         ->selectAlias('u.id', 'user_id')
309
+     *         ->from('users', 'u')
310
+     *         ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
311
+     * </code>
312
+     *
313
+     * @param mixed $select The selection expressions.
314
+     * @param string $alias The column alias used in the constructed query.
315
+     *
316
+     * @return $this This QueryBuilder instance.
317
+     * @since 8.2.1
318
+     */
319
+    public function selectAlias($select, $alias);
320
+
321
+    /**
322
+     * Specifies an item that is to be returned uniquely in the query result.
323
+     *
324
+     * <code>
325
+     *     $qb = $conn->getQueryBuilder()
326
+     *         ->selectDistinct('type')
327
+     *         ->from('users');
328
+     * </code>
329
+     *
330
+     * @param mixed $select The selection expressions.
331
+     *
332
+     * @return $this This QueryBuilder instance.
333
+     * @since 9.0.0
334
+     */
335
+    public function selectDistinct($select);
336
+
337
+    /**
338
+     * Adds an item that is to be returned in the query result.
339
+     *
340
+     * <code>
341
+     *     $qb = $conn->getQueryBuilder()
342
+     *         ->select('u.id')
343
+     *         ->addSelect('p.id')
344
+     *         ->from('users', 'u')
345
+     *         ->leftJoin('u', 'phonenumbers', 'u.id = p.user_id');
346
+     * </code>
347
+     *
348
+     * @param mixed ...$select The selection expression.
349
+     *
350
+     * @return $this This QueryBuilder instance.
351
+     * @since 8.2.0
352
+     */
353
+    public function addSelect(...$select);
354
+
355
+    /**
356
+     * Turns the query being built into a bulk delete query that ranges over
357
+     * a certain table.
358
+     *
359
+     * <code>
360
+     *     $qb = $conn->getQueryBuilder()
361
+     *         ->delete('users', 'u')
362
+     *         ->where('u.id = :user_id');
363
+     *         ->setParameter(':user_id', 1);
364
+     * </code>
365
+     *
366
+     * @param string $delete The table whose rows are subject to the deletion.
367
+     * @param string $alias The table alias used in the constructed query.
368
+     *
369
+     * @return $this This QueryBuilder instance.
370
+     * @since 8.2.0
371
+     */
372
+    public function delete($delete = null, $alias = null);
373
+
374
+    /**
375
+     * Turns the query being built into a bulk update query that ranges over
376
+     * a certain table
377
+     *
378
+     * <code>
379
+     *     $qb = $conn->getQueryBuilder()
380
+     *         ->update('users', 'u')
381
+     *         ->set('u.password', md5('password'))
382
+     *         ->where('u.id = ?');
383
+     * </code>
384
+     *
385
+     * @param string $update The table whose rows are subject to the update.
386
+     * @param string $alias The table alias used in the constructed query.
387
+     *
388
+     * @return $this This QueryBuilder instance.
389
+     * @since 8.2.0
390
+     */
391
+    public function update($update = null, $alias = null);
392
+
393
+    /**
394
+     * Turns the query being built into an insert query that inserts into
395
+     * a certain table
396
+     *
397
+     * <code>
398
+     *     $qb = $conn->getQueryBuilder()
399
+     *         ->insert('users')
400
+     *         ->values(
401
+     *             array(
402
+     *                 'name' => '?',
403
+     *                 'password' => '?'
404
+     *             )
405
+     *         );
406
+     * </code>
407
+     *
408
+     * @param string $insert The table into which the rows should be inserted.
409
+     *
410
+     * @return $this This QueryBuilder instance.
411
+     * @since 8.2.0
412
+     */
413
+    public function insert($insert = null);
414
+
415
+    /**
416
+     * Creates and adds a query root corresponding to the table identified by the
417
+     * given alias, forming a cartesian product with any existing query roots.
418
+     *
419
+     * <code>
420
+     *     $qb = $conn->getQueryBuilder()
421
+     *         ->select('u.id')
422
+     *         ->from('users', 'u')
423
+     * </code>
424
+     *
425
+     * @param string $from The table.
426
+     * @param string|null $alias The alias of the table.
427
+     *
428
+     * @return $this This QueryBuilder instance.
429
+     * @since 8.2.0
430
+     */
431
+    public function from($from, $alias = null);
432
+
433
+    /**
434
+     * Creates and adds a join to the query.
435
+     *
436
+     * <code>
437
+     *     $qb = $conn->getQueryBuilder()
438
+     *         ->select('u.name')
439
+     *         ->from('users', 'u')
440
+     *         ->join('u', 'phonenumbers', 'p', 'p.is_primary = 1');
441
+     * </code>
442
+     *
443
+     * @param string $fromAlias The alias that points to a from clause.
444
+     * @param string $join The table name to join.
445
+     * @param string $alias The alias of the join table.
446
+     * @param string $condition The condition for the join.
447
+     *
448
+     * @return $this This QueryBuilder instance.
449
+     * @since 8.2.0
450
+     */
451
+    public function join($fromAlias, $join, $alias, $condition = null);
452
+
453
+    /**
454
+     * Creates and adds a join to the query.
455
+     *
456
+     * <code>
457
+     *     $qb = $conn->getQueryBuilder()
458
+     *         ->select('u.name')
459
+     *         ->from('users', 'u')
460
+     *         ->innerJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
461
+     * </code>
462
+     *
463
+     * @param string $fromAlias The alias that points to a from clause.
464
+     * @param string $join The table name to join.
465
+     * @param string $alias The alias of the join table.
466
+     * @param string $condition The condition for the join.
467
+     *
468
+     * @return $this This QueryBuilder instance.
469
+     * @since 8.2.0
470
+     */
471
+    public function innerJoin($fromAlias, $join, $alias, $condition = null);
472
+
473
+    /**
474
+     * Creates and adds a left join to the query.
475
+     *
476
+     * <code>
477
+     *     $qb = $conn->getQueryBuilder()
478
+     *         ->select('u.name')
479
+     *         ->from('users', 'u')
480
+     *         ->leftJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
481
+     * </code>
482
+     *
483
+     * @param string $fromAlias The alias that points to a from clause.
484
+     * @param string $join The table name to join.
485
+     * @param string $alias The alias of the join table.
486
+     * @param string $condition The condition for the join.
487
+     *
488
+     * @return $this This QueryBuilder instance.
489
+     * @since 8.2.0
490
+     */
491
+    public function leftJoin($fromAlias, $join, $alias, $condition = null);
492
+
493
+    /**
494
+     * Creates and adds a right join to the query.
495
+     *
496
+     * <code>
497
+     *     $qb = $conn->getQueryBuilder()
498
+     *         ->select('u.name')
499
+     *         ->from('users', 'u')
500
+     *         ->rightJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
501
+     * </code>
502
+     *
503
+     * @param string $fromAlias The alias that points to a from clause.
504
+     * @param string $join The table name to join.
505
+     * @param string $alias The alias of the join table.
506
+     * @param string $condition The condition for the join.
507
+     *
508
+     * @return $this This QueryBuilder instance.
509
+     * @since 8.2.0
510
+     */
511
+    public function rightJoin($fromAlias, $join, $alias, $condition = null);
512
+
513
+    /**
514
+     * Sets a new value for a column in a bulk update query.
515
+     *
516
+     * <code>
517
+     *     $qb = $conn->getQueryBuilder()
518
+     *         ->update('users', 'u')
519
+     *         ->set('u.password', md5('password'))
520
+     *         ->where('u.id = ?');
521
+     * </code>
522
+     *
523
+     * @param string $key The column to set.
524
+     * @param IParameter|string $value The value, expression, placeholder, etc.
525
+     *
526
+     * @return $this This QueryBuilder instance.
527
+     * @since 8.2.0
528
+     */
529
+    public function set($key, $value);
530
+
531
+    /**
532
+     * Specifies one or more restrictions to the query result.
533
+     * Replaces any previously specified restrictions, if any.
534
+     *
535
+     * <code>
536
+     *     $qb = $conn->getQueryBuilder()
537
+     *         ->select('u.name')
538
+     *         ->from('users', 'u')
539
+     *         ->where('u.id = ?');
540
+     *
541
+     *     // You can optionally programatically build and/or expressions
542
+     *     $qb = $conn->getQueryBuilder();
543
+     *
544
+     *     $or = $qb->expr()->orx();
545
+     *     $or->add($qb->expr()->eq('u.id', 1));
546
+     *     $or->add($qb->expr()->eq('u.id', 2));
547
+     *
548
+     *     $qb->update('users', 'u')
549
+     *         ->set('u.password', md5('password'))
550
+     *         ->where($or);
551
+     * </code>
552
+     *
553
+     * @param mixed $predicates The restriction predicates.
554
+     *
555
+     * @return $this This QueryBuilder instance.
556
+     * @since 8.2.0
557
+     */
558
+    public function where(...$predicates);
559
+
560
+    /**
561
+     * Adds one or more restrictions to the query results, forming a logical
562
+     * conjunction with any previously specified restrictions.
563
+     *
564
+     * <code>
565
+     *     $qb = $conn->getQueryBuilder()
566
+     *         ->select('u')
567
+     *         ->from('users', 'u')
568
+     *         ->where('u.username LIKE ?')
569
+     *         ->andWhere('u.is_active = 1');
570
+     * </code>
571
+     *
572
+     * @param mixed ...$where The query restrictions.
573
+     *
574
+     * @return $this This QueryBuilder instance.
575
+     *
576
+     * @see where()
577
+     * @since 8.2.0
578
+     */
579
+    public function andWhere(...$where);
580
+
581
+    /**
582
+     * Adds one or more restrictions to the query results, forming a logical
583
+     * disjunction with any previously specified restrictions.
584
+     *
585
+     * <code>
586
+     *     $qb = $conn->getQueryBuilder()
587
+     *         ->select('u.name')
588
+     *         ->from('users', 'u')
589
+     *         ->where('u.id = 1')
590
+     *         ->orWhere('u.id = 2');
591
+     * </code>
592
+     *
593
+     * @param mixed ...$where The WHERE statement.
594
+     *
595
+     * @return $this This QueryBuilder instance.
596
+     *
597
+     * @see where()
598
+     * @since 8.2.0
599
+     */
600
+    public function orWhere(...$where);
601
+
602
+    /**
603
+     * Specifies a grouping over the results of the query.
604
+     * Replaces any previously specified groupings, if any.
605
+     *
606
+     * <code>
607
+     *     $qb = $conn->getQueryBuilder()
608
+     *         ->select('u.name')
609
+     *         ->from('users', 'u')
610
+     *         ->groupBy('u.id');
611
+     * </code>
612
+     *
613
+     * @param mixed ...$groupBys The grouping expression.
614
+     *
615
+     * @return $this This QueryBuilder instance.
616
+     * @since 8.2.0
617
+     */
618
+    public function groupBy(...$groupBys);
619
+
620
+    /**
621
+     * Adds a grouping expression to the query.
622
+     *
623
+     * <code>
624
+     *     $qb = $conn->getQueryBuilder()
625
+     *         ->select('u.name')
626
+     *         ->from('users', 'u')
627
+     *         ->groupBy('u.lastLogin');
628
+     *         ->addGroupBy('u.createdAt')
629
+     * </code>
630
+     *
631
+     * @param mixed ...$groupBy The grouping expression.
632
+     *
633
+     * @return $this This QueryBuilder instance.
634
+     * @since 8.2.0
635
+     */
636
+    public function addGroupBy(...$groupBy);
637
+
638
+    /**
639
+     * Sets a value for a column in an insert query.
640
+     *
641
+     * <code>
642
+     *     $qb = $conn->getQueryBuilder()
643
+     *         ->insert('users')
644
+     *         ->values(
645
+     *             array(
646
+     *                 'name' => '?'
647
+     *             )
648
+     *         )
649
+     *         ->setValue('password', '?');
650
+     * </code>
651
+     *
652
+     * @param string $column The column into which the value should be inserted.
653
+     * @param string $value The value that should be inserted into the column.
654
+     *
655
+     * @return $this This QueryBuilder instance.
656
+     * @since 8.2.0
657
+     */
658
+    public function setValue($column, $value);
659
+
660
+    /**
661
+     * Specifies values for an insert query indexed by column names.
662
+     * Replaces any previous values, if any.
663
+     *
664
+     * <code>
665
+     *     $qb = $conn->getQueryBuilder()
666
+     *         ->insert('users')
667
+     *         ->values(
668
+     *             array(
669
+     *                 'name' => '?',
670
+     *                 'password' => '?'
671
+     *             )
672
+     *         );
673
+     * </code>
674
+     *
675
+     * @param array $values The values to specify for the insert query indexed by column names.
676
+     *
677
+     * @return $this This QueryBuilder instance.
678
+     * @since 8.2.0
679
+     */
680
+    public function values(array $values);
681
+
682
+    /**
683
+     * Specifies a restriction over the groups of the query.
684
+     * Replaces any previous having restrictions, if any.
685
+     *
686
+     * @param mixed ...$having The restriction over the groups.
687
+     *
688
+     * @return $this This QueryBuilder instance.
689
+     * @since 8.2.0
690
+     */
691
+    public function having(...$having);
692
+
693
+    /**
694
+     * Adds a restriction over the groups of the query, forming a logical
695
+     * conjunction with any existing having restrictions.
696
+     *
697
+     * @param mixed ...$having The restriction to append.
698
+     *
699
+     * @return $this This QueryBuilder instance.
700
+     * @since 8.2.0
701
+     */
702
+    public function andHaving(...$having);
703
+
704
+    /**
705
+     * Adds a restriction over the groups of the query, forming a logical
706
+     * disjunction with any existing having restrictions.
707
+     *
708
+     * @param mixed ...$having The restriction to add.
709
+     *
710
+     * @return $this This QueryBuilder instance.
711
+     * @since 8.2.0
712
+     */
713
+    public function orHaving(...$having);
714
+
715
+    /**
716
+     * Specifies an ordering for the query results.
717
+     * Replaces any previously specified orderings, if any.
718
+     *
719
+     * @param string $sort The ordering expression.
720
+     * @param string $order The ordering direction.
721
+     *
722
+     * @return $this This QueryBuilder instance.
723
+     * @since 8.2.0
724
+     */
725
+    public function orderBy($sort, $order = null);
726
+
727
+    /**
728
+     * Adds an ordering to the query results.
729
+     *
730
+     * @param string $sort The ordering expression.
731
+     * @param string $order The ordering direction.
732
+     *
733
+     * @return $this This QueryBuilder instance.
734
+     * @since 8.2.0
735
+     */
736
+    public function addOrderBy($sort, $order = null);
737
+
738
+    /**
739
+     * Gets a query part by its name.
740
+     *
741
+     * @param string $queryPartName
742
+     *
743
+     * @return mixed
744
+     * @since 8.2.0
745
+     */
746
+    public function getQueryPart($queryPartName);
747
+
748
+    /**
749
+     * Gets all query parts.
750
+     *
751
+     * @return array
752
+     * @since 8.2.0
753
+     */
754
+    public function getQueryParts();
755
+
756
+    /**
757
+     * Resets SQL parts.
758
+     *
759
+     * @param array|null $queryPartNames
760
+     *
761
+     * @return $this This QueryBuilder instance.
762
+     * @since 8.2.0
763
+     */
764
+    public function resetQueryParts($queryPartNames = null);
765
+
766
+    /**
767
+     * Resets a single SQL part.
768
+     *
769
+     * @param string $queryPartName
770
+     *
771
+     * @return $this This QueryBuilder instance.
772
+     * @since 8.2.0
773
+     */
774
+    public function resetQueryPart($queryPartName);
775
+
776
+    /**
777
+     * Creates a new named parameter and bind the value $value to it.
778
+     *
779
+     * This method provides a shortcut for PDOStatement::bindValue
780
+     * when using prepared statements.
781
+     *
782
+     * The parameter $value specifies the value that you want to bind. If
783
+     * $placeholder is not provided bindValue() will automatically create a
784
+     * placeholder for you. An automatic placeholder will be of the name
785
+     * ':dcValue1', ':dcValue2' etc.
786
+     *
787
+     * For more information see {@link http://php.net/pdostatement-bindparam}
788
+     *
789
+     * Example:
790
+     * <code>
791
+     * $value = 2;
792
+     * $q->eq( 'id', $q->bindValue( $value ) );
793
+     * $stmt = $q->executeQuery(); // executed with 'id = 2'
794
+     * </code>
795
+     *
796
+     * @license New BSD License
797
+     * @link http://www.zetacomponents.org
798
+     *
799
+     * @param mixed $value
800
+     * @param mixed $type
801
+     * @param string $placeHolder The name to bind with. The string must start with a colon ':'.
802
+     *
803
+     * @return IParameter
804
+     * @since 8.2.0
805
+     */
806
+    public function createNamedParameter($value, $type = self::PARAM_STR, $placeHolder = null);
807
+
808
+    /**
809
+     * Creates a new positional parameter and bind the given value to it.
810
+     *
811
+     * Attention: If you are using positional parameters with the query builder you have
812
+     * to be very careful to bind all parameters in the order they appear in the SQL
813
+     * statement , otherwise they get bound in the wrong order which can lead to serious
814
+     * bugs in your code.
815
+     *
816
+     * Example:
817
+     * <code>
818
+     *  $qb = $conn->getQueryBuilder();
819
+     *  $qb->select('u.*')
820
+     *     ->from('users', 'u')
821
+     *     ->where('u.username = ' . $qb->createPositionalParameter('Foo', IQueryBuilder::PARAM_STR))
822
+     *     ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', IQueryBuilder::PARAM_STR))
823
+     * </code>
824
+     *
825
+     * @param mixed $value
826
+     * @param integer $type
827
+     *
828
+     * @return IParameter
829
+     * @since 8.2.0
830
+     */
831
+    public function createPositionalParameter($value, $type = self::PARAM_STR);
832
+
833
+    /**
834
+     * Creates a new parameter
835
+     *
836
+     * Example:
837
+     * <code>
838
+     *  $qb = $conn->getQueryBuilder();
839
+     *  $qb->select('u.*')
840
+     *     ->from('users', 'u')
841
+     *     ->where('u.username = ' . $qb->createParameter('name'))
842
+     *     ->setParameter('name', 'Bar', IQueryBuilder::PARAM_STR))
843
+     * </code>
844
+     *
845
+     * @param string $name
846
+     *
847
+     * @return IParameter
848
+     * @since 8.2.0
849
+     */
850
+    public function createParameter($name);
851
+
852
+    /**
853
+     * Creates a new function
854
+     *
855
+     * Attention: Column names inside the call have to be quoted before hand
856
+     *
857
+     * Example:
858
+     * <code>
859
+     *  $qb = $conn->getQueryBuilder();
860
+     *  $qb->select($qb->createFunction('COUNT(*)'))
861
+     *     ->from('users', 'u')
862
+     *  echo $qb->getSQL(); // SELECT COUNT(*) FROM `users` u
863
+     * </code>
864
+     * <code>
865
+     *  $qb = $conn->getQueryBuilder();
866
+     *  $qb->select($qb->createFunction('COUNT(`column`)'))
867
+     *     ->from('users', 'u')
868
+     *  echo $qb->getSQL(); // SELECT COUNT(`column`) FROM `users` u
869
+     * </code>
870
+     *
871
+     * @param string $call
872
+     *
873
+     * @return IQueryFunction
874
+     * @since 8.2.0
875
+     */
876
+    public function createFunction($call);
877
+
878
+    /**
879
+     * Used to get the id of the last inserted element
880
+     * @return int
881
+     * @throws \BadMethodCallException When being called before an insert query has been run.
882
+     * @since 9.0.0
883
+     */
884
+    public function getLastInsertId();
885
+
886
+    /**
887
+     * Returns the table name quoted and with database prefix as needed by the implementation
888
+     *
889
+     * @param string $table
890
+     * @return string
891
+     * @since 9.0.0
892
+     */
893
+    public function getTableName($table);
894
+
895
+    /**
896
+     * Returns the column name quoted and with table alias prefix as needed by the implementation
897
+     *
898
+     * @param string $column
899
+     * @param string $tableAlias
900
+     * @return string
901
+     * @since 9.0.0
902
+     */
903
+    public function getColumnName($column, $tableAlias = '');
904 904
 }
Please login to merge, or discard this patch.