Issue #2427773 by sun, daffie: SQLite REGEXP user function exists, but is wrongly implemented

8.0.x
Alex Pott 2015-02-17 14:02:40 +00:00
parent bc491331fe
commit e25c440c99
1 changed files with 9 additions and 3 deletions

View File

@ -257,10 +257,16 @@ class Connection extends DatabaseConnection {
/** /**
* SQLite compatibility implementation for the REGEXP SQL operator. * SQLite compatibility implementation for the REGEXP SQL operator.
* *
* The REGEXP operator is a special syntax for the regexp() user function. * The REGEXP operator is natively known, but not implemented by default.
*
* @see http://www.sqlite.org/lang_expr.html#regexp
*/ */
public static function sqlFunctionRegexp($string, $pattern) { public static function sqlFunctionRegexp($pattern, $subject) {
return preg_match('#' . str_replace('#', '\#', $pattern) . '#i', $string); // preg_quote() cannot be used here, since $pattern may contain reserved
// regular expression characters already (such as ^, $, etc). Therefore,
// use a rare character as PCRE delimiter.
$pattern = '#' . addcslashes($pattern, '#') . '#i';
return preg_match($pattern, $subject);
} }
/** /**