1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* This file is part of Aura for PHP. |
5
|
|
|
* |
6
|
|
|
* @license http://opensource.org/licenses/bsd-license.php BSD |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
namespace Aura\SqlQuery\Common; |
10
|
|
|
|
11
|
|
|
use Aura\SqlQuery\AbstractDmlQuery; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* |
15
|
|
|
* An object for DELETE queries. |
16
|
|
|
* |
17
|
|
|
* @package Aura.SqlQuery |
18
|
|
|
* |
19
|
|
|
*/ |
20
|
|
|
class Delete extends AbstractDmlQuery implements DeleteInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* |
24
|
|
|
* The table to delete from. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
* |
28
|
|
|
*/ |
29
|
|
|
protected $from; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* |
33
|
|
|
* Sets the table to delete from. |
34
|
|
|
* |
35
|
|
|
* @param string $table The table to delete from. |
36
|
|
|
* |
37
|
|
|
* @return $this |
38
|
|
|
* |
39
|
|
|
*/ |
40
|
13 |
|
public function from($table) |
41
|
|
|
{ |
42
|
13 |
|
$this->from = $this->quoter->quoteName($table); |
43
|
13 |
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* |
48
|
|
|
* Builds this query object into a string. |
49
|
|
|
* |
50
|
|
|
* @return string |
51
|
|
|
* |
52
|
|
|
*/ |
53
|
11 |
|
protected function build() |
54
|
|
|
{ |
55
|
|
|
return 'DELETE' |
56
|
11 |
|
. $this->buildFlags() |
57
|
11 |
|
. $this->buildFrom() |
58
|
11 |
|
. $this->buildWhere() |
59
|
11 |
|
. $this->buildOrderBy() |
60
|
11 |
|
. $this->buildLimit() |
61
|
11 |
|
. $this->buildReturning(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* |
66
|
|
|
* Builds the FROM clause. |
67
|
|
|
* |
68
|
|
|
* @return string |
69
|
|
|
* |
70
|
|
|
*/ |
71
|
11 |
|
protected function buildFrom() |
72
|
|
|
{ |
73
|
11 |
|
return " FROM {$this->from}"; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* |
78
|
|
|
* Adds a WHERE condition to the query by AND. If the condition has |
79
|
|
|
* ?-placeholders, additional arguments to the method will be bound to |
80
|
|
|
* those placeholders sequentially. |
81
|
|
|
* |
82
|
|
|
* @param string $cond The WHERE condition. |
83
|
|
|
* @param mixed ...$bind arguments to bind to placeholders |
84
|
|
|
* |
85
|
|
|
* @return $this |
86
|
|
|
* |
87
|
|
|
*/ |
88
|
10 |
|
public function where($cond) |
89
|
|
|
{ |
90
|
10 |
|
$this->addWhere('AND', func_get_args()); |
91
|
10 |
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* |
96
|
|
|
* Adds a WHERE condition to the query by OR. If the condition has |
97
|
|
|
* ?-placeholders, additional arguments to the method will be bound to |
98
|
|
|
* those placeholders sequentially. |
99
|
|
|
* |
100
|
|
|
* @param string $cond The WHERE condition. |
101
|
|
|
* @param mixed ...$bind arguments to bind to placeholders |
102
|
|
|
* |
103
|
|
|
* @return $this |
104
|
|
|
* |
105
|
|
|
* @see where() |
106
|
|
|
* |
107
|
|
|
*/ |
108
|
10 |
|
public function orWhere($cond) |
109
|
|
|
{ |
110
|
10 |
|
$this->addWhere('OR', func_get_args()); |
111
|
10 |
|
return $this; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|