1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ___ _ _ |
5
|
|
|
* | _ \__ _| |_ __ _| |__ __ _ ___ ___ |
6
|
|
|
* | _/ _` | _/ _` | '_ \/ _` (_-</ -_) |
7
|
|
|
* |_| \__,_|\__\__,_|_.__/\__,_/__/\___| |
8
|
|
|
* |
9
|
|
|
* This file is part of Kristuff\Patabase. |
10
|
|
|
* (c) Kristuff <[email protected]> |
11
|
|
|
* |
12
|
|
|
* For the full copyright and license information, please view the LICENSE |
13
|
|
|
* file that was distributed with this source code. |
14
|
|
|
* |
15
|
|
|
* @version 1.0.1 |
16
|
|
|
* @copyright 2017-2022 Christophe Buliard |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Kristuff\Patabase\Query; |
20
|
|
|
|
21
|
|
|
use Kristuff\Patabase\Query\QueryBuilder; |
22
|
|
|
use Kristuff\Patabase\Query\QueryFilter; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class Where |
26
|
|
|
* |
27
|
|
|
* Handle SQL [WHERE] conditions |
28
|
|
|
*/ |
29
|
|
|
class Where extends QueryFilter |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* sql base: WHERE or HAVING |
33
|
|
|
* |
34
|
|
|
* @access protected |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $sqlBase = 'WHERE'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Equal to condition |
41
|
|
|
* |
42
|
|
|
* @access public |
43
|
|
|
* @param string $column The column name |
44
|
|
|
* @param mixed $value The condition value |
45
|
|
|
* @return $this|QueryBuilder |
46
|
|
|
*/ |
47
|
|
|
public function equal(string $column, $value) |
48
|
|
|
{ |
49
|
|
|
$this->addCondition('EQUAL', $this->query->escape($column).' = ', $column, $value); |
50
|
|
|
return $this->returnFunction(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* NotEqual to condition |
55
|
|
|
* |
56
|
|
|
* @access public |
57
|
|
|
* @param string $column The column name |
58
|
|
|
* @param mixed $value The condition value |
59
|
|
|
* |
60
|
|
|
* @return $this|QueryBuilder |
61
|
|
|
*/ |
62
|
|
|
public function notEqual(string $column, $value) |
63
|
|
|
{ |
64
|
|
|
$this->addCondition('NOT_EQUAL', $this->query->escape($column).' != ', $column, $value); |
65
|
|
|
return $this->returnFunction(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Greater than condition |
70
|
|
|
* |
71
|
|
|
* @access public |
72
|
|
|
* @param string $column The column name |
73
|
|
|
* @param mixed $value The condition value |
74
|
|
|
* |
75
|
|
|
* @return $this|QueryBuilder |
76
|
|
|
*/ |
77
|
|
|
public function greater(string $column, $value) |
78
|
|
|
{ |
79
|
|
|
$this->addCondition('SUP', $this->query->escape($column).' > ', $column, $value); |
80
|
|
|
return $this->returnFunction(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Greater than or equal condition |
85
|
|
|
* |
86
|
|
|
* @access public |
87
|
|
|
* @param string $column The column name |
88
|
|
|
* @param mixed $value The condition value |
89
|
|
|
* |
90
|
|
|
* @return $this|QueryBuilder |
91
|
|
|
*/ |
92
|
|
|
public function greaterEqual(string $column, $value) |
93
|
|
|
{ |
94
|
|
|
$this->addCondition('SUP_EQUAL', $this->query->escape($column).' >= ', $column, $value); |
95
|
|
|
return $this->returnFunction(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Lower than condition |
100
|
|
|
* |
101
|
|
|
* @access public |
102
|
|
|
* @param string $column The column name |
103
|
|
|
* @param mixed $value The condition value |
104
|
|
|
* |
105
|
|
|
* @return $this|QueryBuilder |
106
|
|
|
*/ |
107
|
|
|
public function lower(string $column, $value) |
108
|
|
|
{ |
109
|
|
|
$this->addCondition('INF', $this->query->escape($column).' < ', $column, $value); |
110
|
|
|
return $this->returnFunction(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Lower than or equal condition |
115
|
|
|
* |
116
|
|
|
* @access public |
117
|
|
|
* @param string $column The column name |
118
|
|
|
* @param mixed $value The condition value |
119
|
|
|
* |
120
|
|
|
* @return $this|QueryBuilder |
121
|
|
|
*/ |
122
|
|
|
public function lowerEqual(string $column, $value) |
123
|
|
|
{ |
124
|
|
|
$this->addCondition('INF_EQUAL', $this->query->escape($column).' <= ', $column, $value); |
125
|
|
|
return $this->returnFunction(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* IS NULL condition |
130
|
|
|
* |
131
|
|
|
* @access public |
132
|
|
|
* @param string $column The column name |
133
|
|
|
* |
134
|
|
|
* @return $this|QueryBuilder |
135
|
|
|
*/ |
136
|
|
|
public function isNull(string $column) |
137
|
|
|
{ |
138
|
|
|
$this->addCondition('NULL', $this->query->escape($column).' IS NULL ', $column, null); |
139
|
|
|
return $this->returnFunction(); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* IS NOT NULL condition |
144
|
|
|
* |
145
|
|
|
* @access public |
146
|
|
|
* @param string $column The column name |
147
|
|
|
* |
148
|
|
|
* @return $this|QueryBuilder |
149
|
|
|
*/ |
150
|
|
|
public function notNull(string $column) |
151
|
|
|
{ |
152
|
|
|
$this->addCondition('NOT_NULL', $this->query->escape($column).' IS NOT NULL ', $column, null); |
153
|
|
|
return $this->returnFunction(); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* IN condition |
158
|
|
|
* |
159
|
|
|
* @access public |
160
|
|
|
* @param string $column The column name |
161
|
|
|
* @param array $values The conditions values |
162
|
|
|
* |
163
|
|
|
* @return $this|QueryBuilder |
164
|
|
|
*/ |
165
|
|
|
public function in(string $column, array $values) |
166
|
|
|
{ |
167
|
|
|
if (! empty($values)) { |
168
|
|
|
$this->addCondition('IN', $this->query->escape($column).' IN ', $column, $values); |
169
|
|
|
} |
170
|
|
|
return $this->returnFunction(); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* NOT IN condition |
175
|
|
|
* |
176
|
|
|
* @access public |
177
|
|
|
* @param string $column The column name |
178
|
|
|
* @param array $values The conditions values |
179
|
|
|
* |
180
|
|
|
* @return $this|QueryBuilder |
181
|
|
|
*/ |
182
|
|
|
public function notIn(string $column, array $values) |
183
|
|
|
{ |
184
|
|
|
if (! empty($values)) { |
185
|
|
|
$this->addCondition('NOT_IN', $this->query->escape($column).' NOT IN ', $column, $values); |
186
|
|
|
} |
187
|
|
|
return $this->returnFunction(); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* LIKE condition |
192
|
|
|
* |
193
|
|
|
* @access public |
194
|
|
|
* @param string $column The column name |
195
|
|
|
* @param string $pattern The condition pattern |
196
|
|
|
* |
197
|
|
|
* @return $this|QueryBuilder |
198
|
|
|
*/ |
199
|
|
|
public function like(string $column, string $pattern) |
200
|
|
|
{ |
201
|
|
|
$this->addCondition('LIKE', $this->query->escape($column).' LIKE ', $column, $pattern); |
202
|
|
|
return $this->returnFunction(); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* NOT LIKE condition |
207
|
|
|
* |
208
|
|
|
* @access public |
209
|
|
|
* @param string $column The column name |
210
|
|
|
* @param string $pattern The condition pattern |
211
|
|
|
* |
212
|
|
|
* @return $this|QueryBuilder |
213
|
|
|
*/ |
214
|
|
|
public function notLike(string $column, string $pattern) |
215
|
|
|
{ |
216
|
|
|
$this->addCondition('NOT_LIKE', $this->query->escape($column).' NOT LIKE ', $column, $pattern); |
217
|
|
|
return $this->returnFunction(); |
218
|
|
|
} |
219
|
|
|
} |