diff --git a/core/includes/database.inc b/core/includes/database.inc
index 26cdcc0..7b4ac87 100644
--- a/core/includes/database.inc
+++ b/core/includes/database.inc
@@ -476,6 +476,13 @@ function db_escape_field($field) {
  * Backslash is defined as escape character for LIKE patterns in
  * DatabaseCondition::mapConditionOperator().
  *
+ * Drupal considers LIKE case insensitive and the following is often used
+ * to tell the database that case insensitive equivalence is desired:
+ * @code
+ * db_select('users')
+ *  ->condition('name', db_like($name), 'LIKE')
+ * @endcode
+ *
  * @param $string
  *   The string to escape.
  *
diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php
index 2d53763..bd4fdd4 100644
--- a/core/lib/Drupal/Core/Database/Connection.php
+++ b/core/lib/Drupal/Core/Database/Connection.php
@@ -846,6 +846,13 @@ public function escapeAlias($field) {
    * Backslash is defined as escape character for LIKE patterns in
    * Drupal\Core\Database\Query\Condition::mapConditionOperator().
    *
+   * Drupal considers LIKE case insensitive and the following is often used
+   * to tell the database that case insensitive equivalence is desired:
+   * @code
+   * $this->connection->select('users')
+   * ->condition('name', $this->connection->escapeLike($name), 'LIKE')
+   * @encode
+   *
    * @param $string
    *   The string to escape.
    *
diff --git a/core/lib/Drupal/Core/Database/Query/Select.php b/core/lib/Drupal/Core/Database/Query/Select.php
index cb131a9..e42c0b6 100644
--- a/core/lib/Drupal/Core/Database/Query/Select.php
+++ b/core/lib/Drupal/Core/Database/Query/Select.php
@@ -353,6 +353,10 @@ public function &getUnion() {
     return $this->union;
   }
 
+  public function getConnection() {
+    return $this->connection;
+  }
+
   public function getArguments(PlaceholderInterface $queryPlaceholder = NULL) {
     if (!isset($queryPlaceholder)) {
       $queryPlaceholder = $this;
@@ -784,4 +788,5 @@ public function __clone() {
       $this->union[$key]['query'] = clone($aggregate['query']);
     }
   }
+
 }
diff --git a/core/lib/Drupal/Core/Database/Query/SelectExtender.php b/core/lib/Drupal/Core/Database/Query/SelectExtender.php
index d60931d..ed25e17 100644
--- a/core/lib/Drupal/Core/Database/Query/SelectExtender.php
+++ b/core/lib/Drupal/Core/Database/Query/SelectExtender.php
@@ -171,6 +171,10 @@ public function &getUnion() {
     return $this->query->getUnion();
   }
 
+  public function getConnection() {
+    return $this->connection;
+  }
+
   public function getArguments(PlaceholderInterface $queryPlaceholder = NULL) {
     return $this->query->getArguments($queryPlaceholder);
   }
diff --git a/core/lib/Drupal/Core/Database/Query/SelectInterface.php b/core/lib/Drupal/Core/Database/Query/SelectInterface.php
index 8e1c757..9f5d949 100644
--- a/core/lib/Drupal/Core/Database/Query/SelectInterface.php
+++ b/core/lib/Drupal/Core/Database/Query/SelectInterface.php
@@ -124,6 +124,13 @@ public function &getTables();
   public function &getUnion();
 
   /**
+   * Returns the connection object this SELECT query works on.
+   *
+   * @return \Drupal\Core\Database\Connection
+   */
+  public function getConnection();
+
+  /**
    * Compiles and returns an associative array of the arguments for this prepared statement.
    *
    * @param $queryPlaceholder
diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/BinaryStringItem.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/BinaryStringItem.php
new file mode 100644
index 0000000..dc6dd55
--- /dev/null
+++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/BinaryStringItem.php
@@ -0,0 +1,49 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Entity\Plugin\DataType\BinaryStringItem.
+ */
+
+namespace Drupal\Core\Entity\Plugin\DataType;
+
+use Drupal\Core\TypedData\Annotation\DataType;
+use Drupal\Core\Annotation\Translation;
+use Drupal\Core\Entity\Field\FieldItemBase;
+
+/**
+ * Defines the 'binary_string_field' entity field item.
+ *
+ * @DataType(
+ *   id = "string_field",
+ *   label = @Translation("Binary string field item"),
+ *   description = @Translation("An entity field containing a binary string (case sensitive) value."),
+ *   list_class = "\Drupal\Core\Entity\Field\Field"
+ * )
+ */
+class BinaryStringItem extends FieldItemBase {
+
+  /**
+   * Definitions of the contained properties.
+   *
+   * @see BinaryStringItem::getPropertyDefinitions()
+   *
+   * @var array
+   */
+  static $propertyDefinitions;
+
+  /**
+   * Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions().
+   */
+  public function getPropertyDefinitions() {
+
+    if (!isset(static::$propertyDefinitions)) {
+      static::$propertyDefinitions['value'] = array(
+        'type' => 'string',
+        'label' => t('Text value'),
+        'binary' => TRUE,
+      );
+    }
+    return static::$propertyDefinitions;
+  }
+}
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php b/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
index 19f6a3d..6722fb2 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\Core\Entity\Query\Sql;
 
+use Drupal\Core\Database\Connection;
 use Drupal\Core\Entity\Query\ConditionBase;
 use Drupal\Core\Entity\Query\ConditionInterface;
 use Drupal\Core\Database\Query\SelectInterface;
@@ -42,8 +43,8 @@ public function compile($conditionContainer) {
       }
       else {
         $type = strtoupper($this->conjunction) == 'OR' || $condition['operator'] == 'IS NULL' ? 'LEFT' : 'INNER';
-        $this->translateCondition($condition);
-        $field = $tables->addField($condition['field'], $type, $condition['langcode']);
+        $field = $tables->addField($condition, $type);
+        $this->translateCondition($condition, $sqlQuery->getConnection());
         $conditionContainer->condition($field, $condition['value'], $condition['operator']);
       }
     }
@@ -68,20 +69,32 @@ public function notExists($field, $langcode = NULL) {
    *
    * @param array $condition
    */
-  protected function translateCondition(&$condition) {
+  protected function translateCondition(&$condition, Connection $connection) {
     switch ($condition['operator']) {
+      case '=':
+        if (!$condition['binary']) {
+          $condition['value'] = $connection->escapeLike($condition['value']);
+          $condition['operator'] = 'LIKE';
+        }
+        break;
+      case '<>':
+        if (!$condition['binary']) {
+          $condition['value'] = $connection->escapeLike($condition['value']);
+          $condition['operator'] = 'NOT LIKE';
+        }
+        break;
       case 'STARTS_WITH':
-        $condition['value'] .= '%';
+        $condition['value'] = $connection->escapeLike($condition['value']) . '%';
         $condition['operator'] = 'LIKE';
         break;
 
       case 'CONTAINS':
-        $condition['value'] = '%' . $condition['value'] . '%';
+        $condition['value'] = '%' . $connection->escapeLike($condition['value']) . '%';
         $condition['operator'] = 'LIKE';
         break;
 
       case 'ENDS_WITH':
-        $condition['value'] = '%' . $condition['value'];
+        $condition['value'] = '%' . $connection->escapeLike($condition['value']);
         $condition['operator'] = 'LIKE';
         break;
 
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php b/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php
index cd83691..60ef588 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\Core\Entity\Query\Sql;
 
+use Drupal\Core\Database\Connection;
 use Drupal\Core\Database\Query\SelectInterface;
 use Drupal\Core\Entity\Query\ConditionAggregateBase;
 use Drupal\Core\Entity\Query\ConditionAggregateInterface;
@@ -37,8 +38,8 @@ public function compile($conditionContainer) {
       }
       else {
         $type = ((strtoupper($this->conjunction) == 'OR') || ($condition['operator'] == 'IS NULL')) ? 'LEFT' : 'INNER';
-        $this->translateCondition($condition);
-        $field = $tables->addField($condition['field'], $type, $condition['langcode']);
+        $field = $tables->addField($condition, $type);
+        $this->translateCondition($condition, $sql_query->getConnection());
         $function = $condition['function'];
         $placeholder = ':db_placeholder_' . $conditionContainer->nextPlaceholder();
         $conditionContainer->having("$function($field) {$condition['operator']} $placeholder", array($placeholder => $condition['value']));
@@ -64,24 +65,36 @@ public function notExists($field, $function, $langcode = NULL) {
    * Translates the string operators to SQL equivalents.
    *
    * @param array $condition
-   *   An associative array containing the following keys:
-   *     - value: The value to filter by
-   *     - operator: The operator to use for comparison, for example "=".
    */
-  protected function translateCondition(&$condition) {
+  protected function translateCondition(&$condition, Connection $connection) {
     switch ($condition['operator']) {
+      case '=':
+        if (!$condition['binary']) {
+          $condition['value'] = $connection->escapeLike($condition['value']);
+          $condition['operator'] = 'LIKE';
+        }
+        break;
+      case '<>':
+        if (!$condition['binary']) {
+          $condition['value'] = $connection->escapeLike($condition['value']);
+          $condition['operator'] = 'NOT LIKE';
+        }
+        break;
       case 'STARTS_WITH':
-        $condition['value'] .= '%';
+        $condition['value'] = $connection->escapeLike($condition['value']) . '%';
         $condition['operator'] = 'LIKE';
         break;
+
       case 'CONTAINS':
-        $condition['value'] = '%' . $condition['value'] . '%';
+        $condition['value'] = '%' . $connection->escapeLike($condition['value']) . '%';
         $condition['operator'] = 'LIKE';
         break;
+
       case 'ENDS_WITH':
-        $condition['value'] = '%' . $condition['value'];
+        $condition['value'] = '%' . $connection->escapeLike($condition['value']);
         $condition['operator'] = 'LIKE';
         break;
+
     }
   }
 
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Query.php b/core/lib/Drupal/Core/Entity/Query/Sql/Query.php
index debc403..3cf753b 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Query.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Query.php
@@ -290,7 +290,8 @@ protected function getSqlField($field, $langcode) {
       return $base_property;
     }
     else {
-      return $this->tables->addField($field, 'LEFT', $langcode);
+      $definition = array('field' => $field, 'langcode' => $langcode);
+      return $this->tables->addField($definition, 'LEFT');
     }
   }
 
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
index a3d8e0a..bd8624b 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
@@ -52,7 +52,9 @@ public function __construct(SelectInterface $sql_query) {
   /**
    * {@inheritdoc}
    */
-  public function addField($field, $type, $langcode) {
+  public function addField(&$field_definition, $type) {
+    $field = $field_definition['field'];
+    $langcode = $field_definition['langcode'];
     $entity_type = $this->sqlQuery->getMetaData('entity_type');
     $age = $this->sqlQuery->getMetaData('age');
     // This variable ensures grouping works correctly. For example:
@@ -109,6 +111,15 @@ public function addField($field, $type, $langcode) {
       if ($field) {
         // Find the field column.
         $column = FALSE;
+        // Get the field definitions form a mocked entity.
+        $values = array();
+        $field_name = $field->getFieldName();
+        // If there are bundles, pick one.
+        if (!empty($entity_info['entity_keys']['bundle'])) {
+          $values[$entity_info['entity_keys']['bundle']] = reset($field_map[$field_name]['bundles'][$entity_type]);
+        }
+        $entity = entity_create($entity_type, $values);
+        $propertyDefinitions = $entity->{$field['field_name']}->getPropertyDefinitions();
         if ($key < $count) {
           $next = $specifiers[$key + 1];
           // Is this a field column?
@@ -128,10 +139,6 @@ public function addField($field, $type, $langcode) {
           if ($key < $count) {
             $relationship_specifier = $specifiers[$key + 1];
 
-            // Get the field definitions form a mocked entity.
-            $entity = entity_create($entity_type, array());
-            $propertyDefinitions = $entity->{$field['field_name']}->getPropertyDefinitions();
-
             // If the column is not yet known, ie. the
             // $node->field_image->entity case then use first property as
             // column, i.e. target_id or fid.
@@ -150,12 +157,13 @@ public function addField($field, $type, $langcode) {
         }
         $table = $this->ensureFieldTable($index_prefix, $field, $type, $langcode, $base_table, $entity_id_field, $field_id_field);
         $sql_column = _field_sql_storage_columnname($field['field_name'], $column);
+        $field_definition['binary'] = !empty($propertyDefinitions[$column]['binary']);
       }
       // This is an entity property (non-configurable field).
       else {
         // ensureEntityTable() decides whether an entity property will be
         // queried from the data table or the base table based on where it
-        // finds the property first. The data table is prefered, which is why
+        // finds the property first. The data table is preferred, which is why
         // it gets added before the base table.
         $entity_tables = array();
         if (isset($entity_info['data_table'])) {
@@ -164,7 +172,7 @@ public function addField($field, $type, $langcode) {
         }
         $entity_tables[$entity_info['base_table']] = drupal_get_schema($entity_info['base_table']);
         $sql_column = $specifier;
-        $table = $this->ensureEntityTable($index_prefix, $specifier, $type, $langcode, $base_table, $entity_id_field, $entity_tables);
+        $table = $this->ensureEntityTable($index_prefix, $specifier, $type, $langcode, $base_table, $entity_id_field, $entity_tables, $field_definition);
       }
       // If there are more specifiers to come, it's a relationship.
       if ($key < $count) {
@@ -211,9 +219,10 @@ public function addField($field, $type, $langcode) {
    * @return string
    * @throws \Drupal\Core\Entity\Query\QueryException
    */
-  protected function ensureEntityTable($index_prefix, $property, $type, $langcode, $base_table, $id_field, $entity_tables) {
+  protected function ensureEntityTable($index_prefix, $property, $type, $langcode, $base_table, $id_field, $entity_tables, &$field_definition) {
     foreach ($entity_tables as $table => $schema) {
       if (isset($schema['fields'][$property])) {
+        $field_definition['binary'] = !empty($schema['fields'][$property]['binary']);
         if (!isset($this->entityTables[$index_prefix . $table])) {
           $this->entityTables[$index_prefix . $table] = $this->addJoin($type, $table, "%alias.$id_field = $base_table.$id_field", $langcode);
         }
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/TablesInterface.php b/core/lib/Drupal/Core/Entity/Query/Sql/TablesInterface.php
index 50e5655..fb47dc8 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/TablesInterface.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/TablesInterface.php
@@ -15,13 +15,14 @@
   /**
    * Adds a field to a database query.
    *
-   * @param string $field
-   *   If it contains a dot, then field name dot field column. If it doesn't
-   *   then entity property name.
+   * @param array &$field_definition
+   *   An array with two keys:
+   *   - field: If it contains a dot, then field name dot field column. If it
+   *    doesn't then entity property name. The function will set the binary
+   *    key in the array to TRUE if the field is a binary field.
+   *   - langcode: The language code the field values are to be shown in.
    * @param string $type
    *   Join type, can either be INNER or LEFT.
-   * @param $langcode
-   *   The language code the field values are to be shown in.
    *
    * @throws \Drupal\Core\Entity\Query\QueryException
    *   If $field specifies an invalid relationship.
@@ -31,6 +32,6 @@
    *   and the appropriate SQL column as passed in. This allows the direct use
    *   of this in a query for a condition or sort.
    */
-  public function addField($field, $type, $langcode);
+  public function addField(&$field_definition, $type);
 
 }
diff --git a/core/modules/file/lib/Drupal/file/FileStorageController.php b/core/modules/file/lib/Drupal/file/FileStorageController.php
index f3167a6..166053f 100644
--- a/core/modules/file/lib/Drupal/file/FileStorageController.php
+++ b/core/modules/file/lib/Drupal/file/FileStorageController.php
@@ -74,7 +74,7 @@ public function baseFieldDefinitions() {
     $properties['uri'] = array(
       'label' => t('URI'),
       'description' => t('The URI to access the file (either local or remote).'),
-      'type' => 'string_field',
+      'type' => 'binary_string_field',
     );
     $properties['filemime'] = array(
       'label' => t('File MIME type'),
