Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function escapeLike($string)
 {
     return $this->query->escapeLike($string);
 }
Beispiel #2
0
 /**
  * Translates the string operators to SQL equivalents.
  *
  * @param array $condition
  *   The condition array.
  * @param \Drupal\Core\Database\Query\SelectInterface $sql_query
  *   Select query instance.
  * @param bool|null $case_sensitive
  *   If the condition should be case sensitive or not, NULL if the field does
  *   not define it.
  *
  * @see \Drupal\Core\Database\Query\ConditionInterface::condition()
  */
 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;
     }
 }
 /**
  * Translates the string operators to SQL equivalents.
  *
  * @param array $condition
  *   The condition array.
  * @param \Drupal\Core\Database\Query\SelectInterface $sql_query
  *   Select query instance.
  * @param bool|null $case_sensitive
  *   If the condition should be case sensitive or not, NULL if the field does
  *   not define it.
  *
  * @see \Drupal\Core\Database\Query\ConditionInterface::condition()
  */
 public static function translateCondition(&$condition, SelectInterface $sql_query, $case_sensitive)
 {
     // There is nothing to do for IN () queries except for PostgreSQL for which
     // the condition arguments need to have case lowered to support not case
     // sensitive fields.
     if (is_array($condition['value'])) {
         $entityQueryCondition = Database::getConnection()->getDriverClass('EntityQuery\\Condition');
         $entityQueryCondition::translateCondition($condition, $case_sensitive);
         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;
     }
 }