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

[5.8] Refactor DELETE query bindings #29165

Merged
merged 1 commit into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Illuminate/Database/Query/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,9 @@ public function compileDelete(Builder $query)
*/
public function prepareBindingsForDelete(array $bindings)
{
return Arr::flatten($bindings);
return Arr::flatten(
Arr::except($bindings, 'select')
);
}

/**
Expand Down
16 changes: 0 additions & 16 deletions src/Illuminate/Database/Query/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Illuminate\Database\Query\Grammars;

use Illuminate\Support\Arr;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JsonExpression;

Expand Down Expand Up @@ -239,21 +238,6 @@ public function compileDelete(Builder $query)
: $this->compileDeleteWithoutJoins($query, $table, $where);
}

/**
* Prepare the bindings for a delete statement.
*
* @param array $bindings
* @return array
*/
public function prepareBindingsForDelete(array $bindings)
{
$cleanBindings = Arr::except($bindings, ['join', 'select']);

return array_values(
array_merge($bindings['join'], Arr::flatten($cleanBindings))
);
}

/**
* Compile a delete query that does not use joins.
*
Expand Down
15 changes: 0 additions & 15 deletions src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,6 @@ public function compileDelete(Builder $query)
return trim("delete from {$this->wrapTable($query->from)} $wheres");
}

/**
* Prepare the bindings for a delete statement.
*
* @param array $bindings
* @return array
*/
public function prepareBindingsForDelete(array $bindings)
{
$cleanBindings = Arr::except($bindings, ['select', 'join']);

return array_values(
array_merge($bindings['join'], Arr::flatten($cleanBindings))
);
}

/**
* Compile a truncate table statement into SQL.
*
Expand Down
5 changes: 5 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2076,6 +2076,11 @@ public function testDeleteMethod()
$result = $builder->from('users')->delete(1);
$this->assertEquals(1, $result);

$builder = $this->getBuilder();
$builder->getConnection()->shouldReceive('delete')->once()->with('delete from "users" where "users"."id" = ?', [1])->andReturn(1);
$result = $builder->from('users')->selectRaw('?', ['ignore'])->delete(1);
$this->assertEquals(1, $result);

$builder = $this->getSqliteBuilder();
$builder->getConnection()->shouldReceive('delete')->once()->with('delete from "users" where "rowid" in (select "users"."rowid" from "users" where "email" = ? order by "id" asc limit 1)', ['foo'])->andReturn(1);
$result = $builder->from('users')->where('email', '=', 'foo')->orderBy('id')->take(1)->delete();
Expand Down