|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Joas Schilling <[email protected]> |
|
6
|
|
|
* @author Robin Appelman <[email protected]> |
|
7
|
|
|
* @author Thomas Müller <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* @license AGPL-3.0 |
|
10
|
|
|
* |
|
11
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
13
|
|
|
* as published by the Free Software Foundation. |
|
14
|
|
|
* |
|
15
|
|
|
* This program is distributed in the hope that it will be useful, |
|
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
* GNU Affero General Public License for more details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
22
|
|
|
* |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace OC\DB\QueryBuilder\ExpressionBuilder; |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
use OC\DB\QueryBuilder\QueryFunction; |
|
29
|
|
|
use OCP\DB\QueryBuilder\ILiteral; |
|
30
|
|
|
use OCP\DB\QueryBuilder\IParameter; |
|
31
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder; |
|
32
|
|
|
use OCP\DB\QueryBuilder\IQueryFunction; |
|
33
|
|
|
|
|
34
|
|
|
class OCIExpressionBuilder extends ExpressionBuilder { |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param mixed $column |
|
38
|
|
|
* @param mixed|null $type |
|
39
|
|
|
* @return array|IQueryFunction|string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function prepareColumn($column, $type) { |
|
42
|
|
|
if ($type === IQueryBuilder::PARAM_STR && !is_array($column) && !($column instanceof IParameter) && !($column instanceof ILiteral)) { |
|
43
|
|
|
$column = $this->castColumn($column, $type); |
|
44
|
|
|
} else { |
|
45
|
|
|
$column = $this->helper->quoteColumnNames($column); |
|
46
|
|
|
} |
|
47
|
|
|
return $column; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @inheritdoc |
|
52
|
|
|
*/ |
|
53
|
|
|
public function comparison($x, $operator, $y, $type = null) { |
|
54
|
|
|
$x = $this->prepareColumn($x, $type); |
|
55
|
|
|
$y = $this->prepareColumn($y, $type); |
|
56
|
|
|
|
|
57
|
|
|
return $this->expressionBuilder->comparison($x, $operator, $y); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @inheritdoc |
|
62
|
|
|
*/ |
|
63
|
|
|
public function eq($x, $y, $type = null) { |
|
64
|
|
|
$x = $this->prepareColumn($x, $type); |
|
65
|
|
|
$y = $this->prepareColumn($y, $type); |
|
66
|
|
|
|
|
67
|
|
|
return $this->expressionBuilder->eq($x, $y); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @inheritdoc |
|
72
|
|
|
*/ |
|
73
|
|
|
public function neq($x, $y, $type = null) { |
|
74
|
|
|
$x = $this->prepareColumn($x, $type); |
|
75
|
|
|
$y = $this->prepareColumn($y, $type); |
|
76
|
|
|
|
|
77
|
|
|
return $this->expressionBuilder->neq($x, $y); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @inheritdoc |
|
82
|
|
|
*/ |
|
83
|
|
|
public function lt($x, $y, $type = null) { |
|
84
|
|
|
$x = $this->prepareColumn($x, $type); |
|
85
|
|
|
$y = $this->prepareColumn($y, $type); |
|
86
|
|
|
|
|
87
|
|
|
return $this->expressionBuilder->lt($x, $y); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @inheritdoc |
|
92
|
|
|
*/ |
|
93
|
|
|
public function lte($x, $y, $type = null) { |
|
94
|
|
|
$x = $this->prepareColumn($x, $type); |
|
95
|
|
|
$y = $this->prepareColumn($y, $type); |
|
96
|
|
|
|
|
97
|
|
|
return $this->expressionBuilder->lte($x, $y); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @inheritdoc |
|
102
|
|
|
*/ |
|
103
|
|
|
public function gt($x, $y, $type = null) { |
|
104
|
|
|
$x = $this->prepareColumn($x, $type); |
|
105
|
|
|
$y = $this->prepareColumn($y, $type); |
|
106
|
|
|
|
|
107
|
|
|
return $this->expressionBuilder->gt($x, $y); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @inheritdoc |
|
112
|
|
|
*/ |
|
113
|
|
|
public function gte($x, $y, $type = null) { |
|
114
|
|
|
$x = $this->prepareColumn($x, $type); |
|
115
|
|
|
$y = $this->prepareColumn($y, $type); |
|
116
|
|
|
|
|
117
|
|
|
return $this->expressionBuilder->gte($x, $y); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @inheritdoc |
|
122
|
|
|
*/ |
|
123
|
|
|
public function in($x, $y, $type = null) { |
|
124
|
|
|
$x = $this->prepareColumn($x, $type); |
|
125
|
|
|
$y = $this->prepareColumn($y, $type); |
|
126
|
|
|
|
|
127
|
|
|
return $this->expressionBuilder->in($x, $y); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @inheritdoc |
|
132
|
|
|
*/ |
|
133
|
|
|
public function notIn($x, $y, $type = null) { |
|
134
|
|
|
$x = $this->prepareColumn($x, $type); |
|
135
|
|
|
$y = $this->prepareColumn($y, $type); |
|
136
|
|
|
|
|
137
|
|
|
return $this->expressionBuilder->notIn($x, $y); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Creates a $x = '' statement, because Oracle needs a different check |
|
142
|
|
|
* |
|
143
|
|
|
* @param string $x The field in string format to be inspected by the comparison. |
|
144
|
|
|
* @return string |
|
145
|
|
|
* @since 13.0.0 |
|
146
|
|
|
*/ |
|
147
|
|
|
public function emptyString($x) { |
|
148
|
|
|
return $this->isNull($x); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Creates a `$x <> ''` statement, because Oracle needs a different check |
|
153
|
|
|
* |
|
154
|
|
|
* @param string $x The field in string format to be inspected by the comparison. |
|
155
|
|
|
* @return string |
|
156
|
|
|
* @since 13.0.0 |
|
157
|
|
|
*/ |
|
158
|
|
|
public function nonEmptyString($x) { |
|
159
|
|
|
return $this->isNotNull($x); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Returns a IQueryFunction that casts the column to the given type |
|
164
|
|
|
* |
|
165
|
|
|
* @param string $column |
|
166
|
|
|
* @param mixed $type One of IQueryBuilder::PARAM_* |
|
167
|
|
|
* @return IQueryFunction |
|
168
|
|
|
*/ |
|
169
|
|
View Code Duplication |
public function castColumn($column, $type) { |
|
170
|
|
|
if ($type === IQueryBuilder::PARAM_STR) { |
|
171
|
|
|
$column = $this->helper->quoteColumnName($column); |
|
172
|
|
|
return new QueryFunction('to_char(' . $column . ')'); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
return parent::castColumn($column, $type); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* @inheritdoc |
|
180
|
|
|
*/ |
|
181
|
|
|
public function like($x, $y, $type = null) { |
|
182
|
|
|
return parent::like($x, $y, $type) . " ESCAPE '\\'"; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* @inheritdoc |
|
187
|
|
|
*/ |
|
188
|
|
|
public function iLike($x, $y, $type = null) { |
|
189
|
|
|
$x = $this->helper->quoteColumnName($x); |
|
190
|
|
|
$y = $this->helper->quoteColumnName($y); |
|
191
|
|
|
return new QueryFunction('REGEXP_LIKE(' . $x . ', \'^\' || REPLACE(REPLACE(' . $y . ', \'%\', \'.*\'), \'_\', \'.\') || \'$\', \'i\')'); |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|