Compare commits

..

No commits in common. "master" and "3.5.7" have entirely different histories.

2 changed files with 16 additions and 12 deletions

View file

@ -15,7 +15,7 @@ which would be equivalent to the following in MySQL:
SELECT `columns` FROM `table` WHERE `filter` ORDER BY `order_by` LIMIT `limit`; SELECT `columns` FROM `table` WHERE `filter` ORDER BY `order_by` LIMIT `limit`;
``` ```
- All methods can be chained in any order (even multiple times) after a [`from()`](#from) as long as a [`select()`](#select), [`insert()`](#insert), [`update()`](#update), or [`delete()`](#delete) is the last method. - All methods can be chained in any order (even multiple times) after a [`for()`](#for) as long as a [`select()`](#select), [`insert()`](#insert), [`update()`](#update), or [`delete()`](#delete) is the last method.
- Chaining the same method more than once will override its previous value. Passing `null` to any method that accepts it will unset its value completely. - Chaining the same method more than once will override its previous value. Passing `null` to any method that accepts it will unset its value completely.
## Install from composer ## Install from composer

View file

@ -35,7 +35,7 @@
*/ */
private function throw_if_no_table() { private function throw_if_no_table() {
if (!isset($this->table)) { if (!$this->table) {
throw new Exception("No table name defined"); throw new Exception("No table name defined");
} }
} }
@ -81,7 +81,7 @@
since: "3.5.7", since: "3.5.7",
)] )]
public function for(string $table): self { public function for(string $table): self {
return $this->from($table); $this->from($table);
} }
// Create a WHERE statement from filters // Create a WHERE statement from filters
@ -163,8 +163,17 @@
return $this; return $this;
} }
// Coerce offset to zero if no offset is defined // Set LIMIT without range directly as integer
$offset = $offset ?? 0; if (is_int($limit)) {
$this->limit = $limit;
return $this;
}
// No offset defined, set limit property directly as string
if (is_null($offset)) {
$this->limit = (string) $limit;
return $this;
}
// Set limit and offset as SQL CSV // Set limit and offset as SQL CSV
$this->limit = "{$offset},{$limit}"; $this->limit = "{$offset},{$limit}";
@ -268,14 +277,9 @@
$this->throw_if_no_table(); $this->throw_if_no_table();
// Set DELETE WHERE conditions from arguments // Set DELETE WHERE conditions from arguments
if ($conditions) { $this->where(...$conditions);
$this->where(...$conditions);
}
// Get array of SQL WHERE string and filter values $sql = "DELETE FROM `{$this->table}` WHERE {$this->filter_sql}";
$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)); return $this->execute_query($sql, self::to_list_array($this->filter_values));
} }