function Connection::sqlFunctionLikeBinary

Same name and namespace in other branches
  1. 9 core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection::sqlFunctionLikeBinary()
  2. 8.9.x core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php \Drupal\Core\Database\Driver\sqlite\Connection::sqlFunctionLikeBinary()
  3. 10 core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection::sqlFunctionLikeBinary()

SQLite compatibility implementation for the LIKE BINARY SQL operator.

SQLite supports case-sensitive LIKE operations through the 'case_sensitive_like' PRAGMA statement, but only for ASCII characters, so we have to provide our own implementation with UTF-8 support.

See also

https://sqlite.org/pragma.html#pragma_case_sensitive_like

https://sqlite.org/lang_expr.html#like

File

core/modules/sqlite/src/Driver/Database/sqlite/Connection.php, line 339

Class

Connection
SQLite implementation of <a href="/api/drupal/core%21lib%21Drupal%21Core%21Database%21Connection.php/class/Connection/11.x" title="Base Database API class." class="local">\Drupal\Core\Database\Connection</a>.

Namespace

Drupal\sqlite\Driver\Database\sqlite

Code

public static function sqlFunctionLikeBinary($pattern, $subject) {
    // Replace the SQL LIKE wildcard meta-characters with the equivalent regular
    // expression meta-characters and escape the delimiter that will be used for
    // matching.
    $pattern = str_replace([
        '%',
        '_',
    ], [
        '.*?',
        '.',
    ], preg_quote($pattern, '/'));
    return preg_match('/^' . $pattern . '$/', $subject);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.