-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.6] Fix SQLite delete for complex delete statements #22298
Conversation
public function compileDelete(Builder $query) | ||
{ | ||
// SQLite delete statment doesn't fully support complex keywords like joins .. | ||
// We use select statment as a subquery to overcome this delimma. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
Cool solution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's sqlite it's pretty easy to add integration tests, please add a test in tests/Integration/Database with the cases this PR fixes.
// we use it in select sub-query and in delete where-in statement. | ||
$selectSql = parent::compileSelect($query->select("{$query->from}.rowid")); | ||
|
||
return trim( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this trim
is needed
Current SQLite delete implementation lack the support for complex statement like joins, or limits. This may lead to serious loss of data.
Current approach of SQLite delete:
> App\Post::latest('id')->limit(1)->delete();
=> 48 (deleted rows)
=> "query" => "delete from "posts""
new approach:
> App\Post::latest('id')->limit(1)->delete();
=> 1 (deleted rows)
=> "query" => "delete from "posts" where "rowid" in (select "posts"."rowid" from "posts" order by "id" desc limit 1)"
Also, this fixes the #22239 for SQLite.