Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Delete | |
100.00% |
16 / 16 |
|
100.00% |
4 / 4 |
6 | |
100.00% |
1 / 1 |
| sql | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 | |||
| params | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| reset | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| allTablesReferenced | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsdb\Query\Builder; |
| 4 | |
| 5 | /** |
| 6 | * Update |
| 7 | * |
| 8 | * Generates an SQL query for a DELETE operation. |
| 9 | * |
| 10 | * @package BO\Zmsdb\Query\Builder |
| 11 | * @author Alex Gisby<alex@solution10.com> |
| 12 | * @license MIT |
| 13 | */ |
| 14 | class Delete extends Query |
| 15 | { |
| 16 | use TableName; |
| 17 | use Where; |
| 18 | use Paginate; |
| 19 | |
| 20 | /** |
| 21 | * @var string The base part of the query |
| 22 | */ |
| 23 | protected $queryBase = 'DELETE FROM'; |
| 24 | |
| 25 | /** |
| 26 | * Generates the full SQL statement for this query with all the composite parts. |
| 27 | * |
| 28 | * @return string |
| 29 | */ |
| 30 | public function sql() |
| 31 | { |
| 32 | if ($this->table === null) { |
| 33 | return ''; |
| 34 | } |
| 35 | |
| 36 | $candidateParts = [ |
| 37 | $this->queryBase, |
| 38 | $this->dialect->quoteTable($this->table), |
| 39 | $this->buildWhereSQL($this->dialect), |
| 40 | $this->buildPaginateSQL() |
| 41 | ]; |
| 42 | |
| 43 | return trim(implode(' ', $candidateParts)); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Returns all the parameters, in the correct order, to pass into PDO. |
| 48 | * |
| 49 | * @return array |
| 50 | */ |
| 51 | public function params() |
| 52 | { |
| 53 | return $this->getWhereParams(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Resets the entire query. |
| 58 | * |
| 59 | * @return $this |
| 60 | */ |
| 61 | public function reset() |
| 62 | { |
| 63 | $this->table = null; |
| 64 | $this->resetWhere(); |
| 65 | return $this; |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * ------------------- All Tables ------------------------ |
| 70 | */ |
| 71 | |
| 72 | /** |
| 73 | * Returns all the tables that this query makes mention of, in FROMs and JOINs |
| 74 | * |
| 75 | * @return array |
| 76 | */ |
| 77 | public function allTablesReferenced() |
| 78 | { |
| 79 | if ($this->table()) { |
| 80 | return [$this->table()]; |
| 81 | } |
| 82 | return []; |
| 83 | } |
| 84 | } |