1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Phalcon Framework. |
5
|
|
|
* |
6
|
|
|
* (c) Phalcon Team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* Implementation of this file has been influenced by AtlasPHP |
12
|
|
|
* |
13
|
|
|
* @link https://github.com/atlasphp/Atlas.Query |
14
|
|
|
* @license https://github.com/atlasphp/Atlas.Qyert/blob/1.x/LICENSE.md |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
declare(strict_types=1); |
18
|
|
|
|
19
|
|
|
namespace Phalcon\DataMapper\Query; |
20
|
|
|
|
21
|
|
|
use Phalcon\DataMapper\Pdo\Connection; |
22
|
|
|
|
23
|
|
|
class Delete extends AbstractConditions |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Delete constructor. |
27
|
|
|
* |
28
|
|
|
* @param Connection $connection |
29
|
|
|
* @param Bind $bind |
30
|
|
|
*/ |
31
|
|
|
public function __construct(Connection $connection, Bind $bind) |
32
|
|
|
{ |
33
|
|
|
parent::__construct($connection, $bind); |
34
|
|
|
|
35
|
|
|
$this->store["FROM"] = ""; |
36
|
|
|
$this->store["RETURNING"] = []; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Adds table(s) in the query |
41
|
|
|
* |
42
|
|
|
* @param string $table |
43
|
|
|
* |
44
|
|
|
* @return Delete |
45
|
|
|
*/ |
46
|
|
|
public function from(string $table): Delete |
47
|
|
|
{ |
48
|
|
|
$this->store["FROM"] = $table; |
49
|
|
|
|
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Adds the `RETURNING` clause |
55
|
|
|
* |
56
|
|
|
* @param array $columns |
57
|
|
|
* |
58
|
|
|
* @return Delete |
59
|
|
|
*/ |
60
|
|
|
public function returning(array $columns): Delete |
61
|
|
|
{ |
62
|
|
|
$this->store["RETURNING"] = array_merge( |
63
|
|
|
$this->store["RETURNING"], |
64
|
|
|
$columns |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
public function getStatement(): string |
74
|
|
|
{ |
75
|
|
|
return "DELETE" |
76
|
|
|
. $this->buildFlags() |
77
|
|
|
. " FROM " . $this->store["FROM"] |
78
|
|
|
. $this->buildCondition("WHERE") |
79
|
|
|
. $this->buildReturning(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Resets the internal store |
84
|
|
|
*/ |
85
|
|
|
public function reset(): void |
86
|
|
|
{ |
87
|
|
|
parent::reset(); |
88
|
|
|
|
89
|
|
|
$this->store["FROM"] = ""; |
90
|
|
|
$this->store["RETURNING"] = []; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|