class Condition in Drupal driver for SQL Server and SQL Azure 3.0.x
Same name and namespace in other branches
- 8.2 drivers/lib/Drupal/Driver/Database/sqlsrv/Condition.php \Drupal\Driver\Database\sqlsrv\Condition
Hierarchy
- class \Drupal\Core\Database\Query\Condition implements \Drupal\Core\Database\Query\Countable, ConditionInterface
- class \Drupal\Driver\Database\sqlsrv\Condition
Expanded class hierarchy of Condition
3 files declare their use of Condition
- OrderByTest.php in tests/
src/ Unit/ OrderByTest.php - SqlsrvConditionTest.php in tests/
src/ Unit/ SqlsrvConditionTest.php - SqlsrvTest.php in tests/
src/ Kernel/ SqlsrvTest.php
File
- drivers/
lib/ Drupal/ Driver/ Database/ sqlsrv/ Condition.php, line 13
Namespace
Drupal\Driver\Database\sqlsrvView source
class Condition extends QueryCondition {
/**
* {@inheritdoc}
*
* Overridden to replace REGEXP expressions.
* Should this move to Condition::condition()?
*/
public function compile(DatabaseConnection $connection, PlaceholderInterface $queryPlaceholder) {
// Find any REGEXP conditions and turn them into function calls.
foreach ($this->conditions as &$condition) {
if (isset($condition['operator'])) {
if ($condition['operator'] == 'REGEXP' || $condition['operator'] == 'NOT REGEXP') {
$placeholder = ':db_condition_placeholder_' . $queryPlaceholder
->nextPlaceholder();
$field_fragment = $connection
->escapeField($condition['field']);
$comparison = $condition['operator'] == 'REGEXP' ? '1' : '0';
$condition['field'] = "REGEXP({$placeholder}, {$field_fragment}) = {$comparison}";
$condition['operator'] = NULL;
$condition['value'] = [
$placeholder => $condition['value'],
];
}
elseif ($condition['operator'] == 'LIKE' || $condition['operator'] == 'NOT LIKE') {
$condition['value'] = strtr($condition['value'], [
'[' => '[[]',
'\\%' => '[%]',
'\\_' => '[_]',
'\\\\' => '\\',
]);
}
}
}
parent::compile($connection, $queryPlaceholder);
}
/**
* {@inheritdoc}
*
* Overridden to replace REGEXP expressions.
* Needs to be tested for complex nested expressions.
*/
public function where($snippet, $args = []) {
$operator = NULL;
if (strpos($snippet, " NOT REGEXP ") !== FALSE) {
$operator = ' NOT REGEXP ';
}
elseif (strpos($snippet, " REGEXP ") !== FALSE) {
$operator = ' REGEXP ';
}
if ($operator !== NULL) {
$fragments = explode($operator, $snippet);
$field = $fragments[0];
$value = $fragments[1];
$comparison = $operator == ' REGEXP ' ? '1' : '0';
$snippet = "REGEXP({$value}, {$field}) = {$comparison}";
$operator = NULL;
}
$this->conditions[] = [
'field' => $snippet,
'value' => $args,
'operator' => $operator,
];
$this->changed = TRUE;
return $this;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Condition:: |
protected | property | Array of arguments. | |
Condition:: |
protected | property | Whether the conditions have been changed. | |
Condition:: |
protected static | property | Provides a map of condition operators to condition operator options. | |
Condition:: |
protected | property | Array of conditions. | |
Condition:: |
protected | property | The identifier of the query placeholder this condition has been compiled against. | |
Condition:: |
protected | property | Contains the string version of the Condition. | |
Condition:: |
public | function |
Sets a condition that is always false. Overrides ConditionInterface:: |
|
Condition:: |
public | function |
Creates a new group of conditions ANDed together. Overrides ConditionInterface:: |
|
Condition:: |
public | function |
Gets a complete list of all values to insert into the prepared statement. Overrides ConditionInterface:: |
|
Condition:: |
public | function |
Overridden to replace REGEXP expressions.
Should this move to Condition::condition()? Overrides Condition:: |
|
Condition:: |
public | function |
Check whether a condition has been previously compiled. Overrides ConditionInterface:: |
|
Condition:: |
public | function |
Helper function: builds the most common conditional clauses. Overrides ConditionInterface:: |
|
Condition:: |
public | function |
Creates an object holding a group of conditions. Overrides ConditionInterface:: |
|
Condition:: |
public | function |
Gets the, possibly nested, list of conditions in this conditional clause. Overrides ConditionInterface:: |
|
Condition:: |
public | function | Implements Countable::count(). | |
Condition:: |
public | function |
Sets a condition that the specified subquery returns values. Overrides ConditionInterface:: |
|
Condition:: |
public | function |
Sets a condition that the specified field be NOT NULL. Overrides ConditionInterface:: |
|
Condition:: |
public | function |
Sets a condition that the specified field be NULL. Overrides ConditionInterface:: |
|
Condition:: |
protected | function | Gets any special processing requirements for the condition operator. | |
Condition:: |
public | function |
Sets a condition that the specified subquery returns no values. Overrides ConditionInterface:: |
|
Condition:: |
public | function |
Creates a new group of conditions ORed together. Overrides ConditionInterface:: |
|
Condition:: |
public | function |
Overridden to replace REGEXP expressions.
Needs to be tested for complex nested expressions. Overrides Condition:: |
|
Condition:: |
public | function | PHP magic __clone() method. | |
Condition:: |
public | function | Constructs a Condition object. | |
Condition:: |
public | function | Implements PHP magic __toString method to convert the conditions to string. |