1 | <?php |
||
8 | class UpdateQuery extends HasWhereExpression implements QueryInterface |
||
9 | { |
||
10 | /** @var string */ |
||
11 | protected $table; |
||
12 | |||
13 | /** @var array */ |
||
14 | protected $attributes; |
||
15 | |||
16 | /** |
||
17 | * @param string $table |
||
18 | * @param array $attributes |
||
19 | */ |
||
20 | 2 | public function __construct($table, array $attributes = []) |
|
25 | |||
26 | /** |
||
27 | * @param array $attributes |
||
28 | * @return static |
||
29 | */ |
||
30 | public function set(array $attributes = []) |
||
35 | |||
36 | /** |
||
37 | * @param array $attributes |
||
38 | * @return static |
||
39 | */ |
||
40 | public function addSet(array $attributes = []) |
||
45 | |||
46 | /** |
||
47 | * {@inheritdoc} |
||
48 | */ |
||
49 | 2 | public function toSql() |
|
50 | { |
||
51 | 2 | $parts = ['UPDATE `' . $this->table . '`']; |
|
52 | 2 | if (count($this->attributes)) { |
|
53 | 2 | $columns = array_keys($this->attributes); |
|
54 | 2 | $parts[] = "SET " . Helper::arrayImplode(', ', $columns, "`", "` = ?"); |
|
55 | } |
||
56 | 2 | if ($part = parent::toSql()) { |
|
57 | 2 | $parts[] = $part; |
|
58 | } |
||
59 | 2 | return implode(' ', $parts); |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | 2 | public function getBindings() |
|
69 | } |
||
70 |