catfan / Medoo

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

Seems that SQL LIKE Wildcard not implement #323

Closed SyuTingSong closed 7 years ago

SyuTingSong commented 8 years ago
$database->select("person", "id", [
    "city[~]" => "stan%" // Kazakhstan,  Uzbekistan, Türkmenistan
]);

Gets the SQL:

SELECT "id" FROM "person" WHERE "city" LIKE 'stan%'

As the doc spec should be:

SELECT "id" FROM "person" WHERE "city" LIKE '%stan'

$database->select("person", "id", [
    "city[~]" => "Londo_" // London, Londox, Londos...
]);

Gets the SQL:

SELECT "id" FROM "person" WHERE "city" LIKE '%Londo_%'

As the doc spec should be:

SELECT "id" FROM "person" WHERE "city" LIKE 'Londo_'
glenndavey83 commented 8 years ago

I've added support for SQL LIKE Wildcards as a fix for this issue in my pull request #328.

@catfan I think it's important to implement this fix sooner rather than later if the online documentation lists this as a feature. More testing and optimization may be done later for edge cases.

SyuTingSong commented 8 years ago

Thank you @glenndavey83 I found this issue when I am writing test-cases for Medoo. I will merge your code to my fork and test it.

To @catfan: I read some docs for MySQL, PostgreSQL, MS SQL Server, Oracle, SQLite and Sybase. The syntax [cbr]at for matching cat, bat, rat is originally supported by MS SQL Server only. And it supports [^cbr]at for matching any 3-letters word end with at and not beginning with c, b or r.

Medoo should either update the documentation or implement this in PHP.