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