Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB::delete() does not support comparison operators other than = and does so without warning #24

Open
defunctl opened this issue Nov 19, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@defunctl
Copy link
Contributor

DB::delete() uses wpdb::delete() under the hood, which only supports the = comparison operator.

This can cause some seriously unexpected results, because the SQL is silently converted and doesn't warn the developer that they aren't executing their expected query.

Ideally, we would no longer use wpdb::delete() under the hood and instead build our own DELETE SQL. Temporary solutions could be some doc updates and finding a way to throw an exception if a developer tries to do this.


Delete query with comparison operator other than =:

DB::table( 'posts' )->where( 'ID', 100, '>' )->delete();

The expected SQL for the above query:

DELETE FROM wp_posts
WHERE `ID` > 100

The actual SQL for the above query:

DELETE FROM wp_posts
WHERE `ID` = 100
@defunctl defunctl added the bug Something isn't working label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants