Skip to content

Commit

Permalink
[5.5] Remove "select" bindings from MySQL delete statments. (#22285)
Browse files Browse the repository at this point in the history
*        prepare bindings for delete on mysql

* fixes
  • Loading branch information
themsaid authored and taylorotwell committed Dec 3, 2017
1 parent a919819 commit b2fbec9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2224,7 +2224,9 @@ public function delete($id = null)
}

return $this->connection->delete(
$this->grammar->compileDelete($this), $this->getBindings()
$this->grammar->compileDelete($this), $this->cleanBindings(
$this->grammar->prepareBindingsForDelete($this->bindings)
)
);
}

Expand Down
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Query/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,17 @@ 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)
{
return Arr::flatten($bindings);
}

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

namespace Illuminate\Database\Query\Grammars;

use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JsonExpression;
Expand Down Expand Up @@ -204,6 +205,21 @@ 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

0 comments on commit b2fbec9

Please sign in to comment.