1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright 2021 Aleksandar Panic |
4
|
|
|
* |
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
6
|
|
|
* you may not use this file except in compliance with the License. |
7
|
|
|
* You may obtain a copy of the License at |
8
|
|
|
* |
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
10
|
|
|
* |
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14
|
|
|
* See the License for the specific language governing permissions and |
15
|
|
|
* limitations under the License. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace ArekX\PQL\Sql\Query; |
19
|
|
|
|
20
|
|
|
use ArekX\PQL\Contracts\StructuredQuery; |
21
|
|
|
use ArekX\PQL\Query; |
22
|
|
|
use ArekX\PQL\Sql\Query\Traits\ConditionTrait; |
23
|
|
|
use ArekX\PQL\Sql\Query\Traits\ConfigureTrait; |
24
|
|
|
use ArekX\PQL\Sql\Query\Traits\JoinTrait; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Represents a delete query to delete items from the |
28
|
|
|
* driver. |
29
|
|
|
*/ |
30
|
|
|
class Update extends Query |
31
|
|
|
{ |
32
|
|
|
use ConditionTrait; |
33
|
|
|
use JoinTrait; |
34
|
|
|
use ConfigureTrait; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Set the destination to which to update data. |
38
|
|
|
* |
39
|
|
|
* **SQL Injection Warning**: Value in this function is not usually escaped in the driver |
40
|
|
|
* and should not be used to pass values from the user input to it. If you need to pass |
41
|
|
|
* and escape query use Raw query. |
42
|
|
|
* |
43
|
|
|
* If a StructuredQuery is passed, it will be additionally parsed according to that type. |
44
|
|
|
* |
45
|
|
|
* @param string|StructuredQuery $to Table or other destination to update the data. |
46
|
|
|
* @return $this |
47
|
|
|
*/ |
48
|
9 |
|
public function to(StructuredQuery|string $to): static |
49
|
|
|
{ |
50
|
9 |
|
$this->use('to', $to); |
51
|
9 |
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Set values to be updated. |
56
|
|
|
* |
57
|
|
|
* Data accepted is an associative array where key is the column name and value is the value to update. |
58
|
|
|
* |
59
|
|
|
* **SQL Injection Warning**: If an array is passed the keys in the array are not escaped |
60
|
|
|
* meaning they should not be for user input, values are escaped properly and user input |
61
|
|
|
* can be used for them. |
62
|
|
|
* |
63
|
|
|
* @param array|StructuredQuery $data |
64
|
|
|
* @return $this |
65
|
|
|
*/ |
66
|
9 |
|
public function set(array|StructuredQuery $data): static |
67
|
|
|
{ |
68
|
9 |
|
$this->use('set', $data); |
69
|
9 |
|
return $this; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|