Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 3 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
RawSQLExpression | |
0.00% |
0 / 3 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
toSql | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
toGeneralizedSql | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Wikimedia\Rdbms; |
4 | |
5 | use Wikimedia\Rdbms\Database\DbQuoter; |
6 | |
7 | /** |
8 | * Raw SQL expression to be used in query builders |
9 | * |
10 | * @note This should be used very rarely and NEVER with user input. |
11 | * |
12 | * @newable |
13 | * @since 1.42 |
14 | */ |
15 | class RawSQLExpression extends Expression { |
16 | private string $expression = ''; |
17 | |
18 | /** |
19 | * This should be used very rarely and NEVER with user input. |
20 | * |
21 | * It can be used as a boolean expression in a WHERE condition, in cases where `$db->expr()` |
22 | * can't be used because the expression doesn't have a left side, operator and right side, |
23 | * e.g. for conditions like `WHERE EXISTS( SELECT ... )`. |
24 | * |
25 | * $queryBuilder->where( new RawSQLExpression( 'EXISTS(' . $subqueryBuilder->getSQL() . ')' ) ) |
26 | * |
27 | * Or when the condition is a simple SQL literal and writing it as SQL is the easiest: |
28 | * |
29 | * $queryBuilder->where( new RawSQLExpression( 'range_start != range_end' ) ) |
30 | * |
31 | * (See also RawSQLValue, which may be more readable in other cases.) |
32 | * |
33 | * @param string $expression Expression (SQL fragment) |
34 | * @param-taint $expression exec_sql |
35 | * @since 1.42 |
36 | */ |
37 | public function __construct( string $expression ) { |
38 | $this->expression = $expression; |
39 | } |
40 | |
41 | /** |
42 | * @internal to be used by rdbms library only |
43 | */ |
44 | public function toSql( DbQuoter $dbQuoter ): string { |
45 | return $this->expression; |
46 | } |
47 | |
48 | public function toGeneralizedSql(): string { |
49 | return $this->expression; |
50 | } |
51 | } |