catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

Like quotation issue on v2.0 #966

Closed digitalade closed 3 years ago

digitalade commented 3 years ago

Describe the bug "Like" feature appears not to work in latest version?

Information

Detail Code It appears the LIKE functionality has stopped working in version 2.0.1. Previously noted working correctly in 1.7.3.

As detailed here : https://medoo.in/api/where I am using

$database->select("person", "id", [
    "city[~]" => "lon",
         "status" => 1
]);

the actual output of the query is

 WHERE (`city` LIKE 'lon') AND `person.status` = 1

(missing % signs)

Expected output I would expect the final query to contain

"WHERE city LIKE '%lon%';
catfan commented 3 years ago

We tested it, and it indeed outputs as %lon% as expected.

What PHP version are you using?

digitalade commented 3 years ago

Version 7.3.9;

However, I've done some more digging and realised that it is a hyphen sign that is causing issues.

I did simplify my example and I really shouldn't have. Apologies. The actual code that doesn't work in 2.0.3 but did in 1.7.3 is :

select("shift", "*", ["notes[~]" => "SSP-"]);

The hyphen breaks it. With the hyphen I lose the % symbols. Without the hyphen I get %SSP%

catfan commented 3 years ago

The hyphen is one of the wildcard characters for LIKE, and it fixed it on v2.0.

For quoting SSP-, you may need to manually add % on the front and the end.