mirror of
https://codeberg.org/vlw/php-mysql.git
synced 2025-09-13 16:23:42 +02:00
fix: only set WHERE
filters on delete()
if conditions are provided (#51)
This PR fixes a bug where if no conditions are passed to `MySQL->from("table")->delete()`, the generated query will look like this: ```sql DELETE FROM `table` WHERE ``` This is obviously invalid SQL syntax. This PR only adds the `WHERE` keyword and rules if conditions have been supplied to either `where()` or with `delete([])` Reviewed-on: https://codeberg.org/vlw/php-mysql/pulls/51
This commit is contained in:
parent
ddcd8a2961
commit
0e367f797f
1 changed files with 7 additions and 2 deletions
|
@ -268,9 +268,14 @@
|
|||
$this->throw_if_no_table();
|
||||
|
||||
// Set DELETE WHERE conditions from arguments
|
||||
$this->where(...$conditions);
|
||||
if ($conditions) {
|
||||
$this->where(...$conditions);
|
||||
}
|
||||
|
||||
$sql = "DELETE FROM `{$this->table}` WHERE {$this->filter_sql}";
|
||||
// Get array of SQL WHERE string and filter values
|
||||
$filter_sql = !is_null($this->filter_sql) ? " WHERE {$this->filter_sql}" : "";
|
||||
|
||||
$sql = "DELETE FROM `{$this->table}`{$filter_sql}";
|
||||
return $this->execute_query($sql, self::to_list_array($this->filter_values));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue