Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3485117
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
drupal-3485117
Commits
fe2eecac
Commit
fe2eecac
authored
9 years ago
by
catch
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2475187
by amateescu: Add a user-space implementation for LIKE BINARY in SQLite
parent
6e8eb8ee
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
+26
-0
26 additions, 0 deletions
core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
with
26 additions
and
0 deletions
core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
+
26
−
0
View file @
fe2eecac
...
...
@@ -112,6 +112,12 @@ public static function open(array &$connection_options = array()) {
$pdo
->
sqliteCreateFunction
(
'rand'
,
array
(
__CLASS__
,
'sqlFunctionRand'
));
$pdo
->
sqliteCreateFunction
(
'regexp'
,
array
(
__CLASS__
,
'sqlFunctionRegexp'
));
// SQLite does not support the LIKE BINARY operator, so we overload the
// non-standard GLOB operator for case-sensitive matching. Another option
// would have been to override another non-standard operator, MATCH, but
// that does not support the NOT keyword prefix.
$pdo
->
sqliteCreateFunction
(
'glob'
,
array
(
__CLASS__
,
'sqlFunctionLikeBinary'
));
// Create a user-space case-insensitive collation with UTF-8 support.
$pdo
->
sqliteCreateCollation
(
'NOCASE_UTF8'
,
array
(
'Drupal\Component\Utility\Unicode'
,
'strcasecmp'
));
...
...
@@ -256,6 +262,24 @@ public static function sqlFunctionRegexp($pattern, $subject) {
return
preg_match
(
$pattern
,
$subject
);
}
/**
* 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 https://sqlite.org/pragma.html#pragma_case_sensitive_like
* @see https://sqlite.org/lang_expr.html#like
*/
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
(
array
(
'%'
,
'_'
),
array
(
'.*?'
,
'.'
),
preg_quote
(
$pattern
,
'/'
));
return
preg_match
(
'/^'
.
$pattern
.
'$/'
,
$subject
);
}
/**
* {@inheritdoc}
*/
...
...
@@ -325,6 +349,8 @@ public function mapConditionOperator($operator) {
static
$specials
=
array
(
'LIKE'
=>
array
(
'postfix'
=>
" ESCAPE '
\\
'"
),
'NOT LIKE'
=>
array
(
'postfix'
=>
" ESCAPE '
\\
'"
),
'LIKE BINARY'
=>
array
(
'postfix'
=>
" ESCAPE '
\\
'"
,
'operator'
=>
'GLOB'
),
'NOT LIKE BINARY'
=>
array
(
'postfix'
=>
" ESCAPE '
\\
'"
,
'operator'
=>
'NOT GLOB'
),
);
return
isset
(
$specials
[
$operator
])
?
$specials
[
$operator
]
:
NULL
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment