[5.6] Fix SQLite delete for complex delete statements - #22298
Merged
Conversation
deleugpn
reviewed
Dec 4, 2017
| 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. |
Contributor
|
Cool solution. |
themsaid
requested changes
Dec 5, 2017
themsaid
left a comment
Member
There was a problem hiding this comment.
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.
ntzm
reviewed
Dec 5, 2017
| // we use it in select sub-query and in delete where-in statement. | ||
| $selectSql = parent::compileSelect($query->select("{$query->from}.rowid")); | ||
|
|
||
| return trim( |
Contributor
There was a problem hiding this comment.
I don't think this trim is needed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.