public static Condition::translateCondition(&$condition, SelectInterface $sql_query, $case_sensitive)
Translates the string operators to SQL equivalents.
Parameters
array $condition: The condition array.
\Drupal\Core\Database\Query\SelectInterface $sql_query: Select query instance.
bool|null $case_sensitive: If the condition should be case sensitive or not, NULL if the field does not define it.
See also
\Drupal\Core\Database\Query\ConditionInterface::condition()
File
- core/lib/Drupal/Core/Entity/Query/Sql/Condition.php, line 86
Class
- Condition
- Implements entity query conditions for SQL databases.
Namespace
Drupal\Core\Entity\Query\Sql
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | public static function translateCondition(& $condition , SelectInterface $sql_query , $case_sensitive ) { // // There is nothing we can do for IN (). if ( is_array ( $condition [ 'value' ])) { return ; } // Ensure that the default operator is set to simplify the cases below. if ( empty ( $condition [ 'operator' ])) { $condition [ 'operator' ] = '=' ; } switch ( $condition [ 'operator' ]) { case '=' : // If a field explicitly requests that queries should not be case // sensitive, use the LIKE operator, otherwise keep =. if ( $case_sensitive === FALSE) { $condition [ 'value' ] = $sql_query ->escapeLike( $condition [ 'value' ]); $condition [ 'operator' ] = 'LIKE' ; } break ; case '<>' : // If a field explicitly requests that queries should not be case // sensitive, use the NOT LIKE operator, otherwise keep <>. if ( $case_sensitive === FALSE) { $condition [ 'value' ] = $sql_query ->escapeLike( $condition [ 'value' ]); $condition [ 'operator' ] = 'NOT LIKE' ; } break ; case 'STARTS_WITH' : if ( $case_sensitive ) { $condition [ 'operator' ] = 'LIKE BINARY' ; } else { $condition [ 'operator' ] = 'LIKE' ; } $condition [ 'value' ] = $sql_query ->escapeLike( $condition [ 'value' ]) . '%' ; break ; case 'CONTAINS' : if ( $case_sensitive ) { $condition [ 'operator' ] = 'LIKE BINARY' ; } else { $condition [ 'operator' ] = 'LIKE' ; } $condition [ 'value' ] = '%' . $sql_query ->escapeLike( $condition [ 'value' ]) . '%' ; break ; case 'ENDS_WITH' : if ( $case_sensitive ) { $condition [ 'operator' ] = 'LIKE BINARY' ; } else { $condition [ 'operator' ] = 'LIKE' ; } $condition [ 'value' ] = '%' . $sql_query ->escapeLike( $condition [ 'value' ]); break ; } } |
Please login to continue.