Closed objectivisto closed 2 years ago
I also encountered this problem...
xdebug 分析后发现可能是正则的问题 https://github.com/catfan/Medoo/blob/8d2147808a2795cf58f6da94f82281f6a5433221/src/Medoo.php#L1171
执行到此行 LIKE 数值丢失😫
I have the problem in a select() too ... if there is a LIKE statement 'mycolumn[~]' => $value
and $value contains a dash then $value doesn' get surrounding %
chars in the query.
Fixed it on 66ddd62.
The behavior is also strange when it contains underscores.
$database->select('options', 'option_id', ['option_id[~]'=>'a_']);
↓
SELECT `option_id` FROM `options` WHERE (`optionid` LIKE 'a')
'a_' is not wrapped in '%'.
It works fine if I escape with '\'.
$database->select('options', 'option_id', ['option_id[~]'=>'a\_']);
↓
SELECT `option_id` FROM `options` WHERE (`optionid` LIKE '%a\%')
Is this bug?
medoo version 2.1.3
@webgoto _
is a wildcard character for representing a single character. a_
will match aa
, ab
, ac
, and more.
So if you just want to match the underscore _
character, you need to add a slash.
Medoo’s count() in version 2.1.2 is generating a wrong SQL statement, if we use the LIKE operator in the WHERE clause, and the search term contains a dash. Under these conditions, it is missing the embedding % character at the start and the end of the search term.
This works well:
$searchString = "tomspage”; // no dash in search term $countAds = $db->count('xyzAd', array('linkManual[~]'=>$searchString)); Correct query generated: SELECT COUNT(*) FROM
xyzAd
WHERE (linkManual
LIKE '%tomspage%')This does not work:
$searchString = “toms-page"; // with dash in search term $countAds = $db->count('xyzAd', array('linkManual[~]'=>$searchString)); Faulty query generated (missing %%): SELECT COUNT(*) FROM
xyzAd
WHERE (linkManual
LIKE 'toms-page')In previous versions of Medoo it works well, verified in version 1.7.10.