|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2017 Robin Appelman <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Robin Appelman <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OC\DB\QueryBuilder\FunctionBuilder; |
|
25
|
|
|
|
|
26
|
|
|
use OC\DB\QueryBuilder\QueryFunction; |
|
27
|
|
|
use OCP\DB\QueryBuilder\ILiteral; |
|
28
|
|
|
use OCP\DB\QueryBuilder\IParameter; |
|
29
|
|
|
use OCP\DB\QueryBuilder\IQueryFunction; |
|
30
|
|
|
|
|
31
|
|
|
class OCIFunctionBuilder extends FunctionBuilder { |
|
32
|
|
|
public function md5($input) { |
|
33
|
|
|
return new QueryFunction('LOWER(DBMS_OBFUSCATION_TOOLKIT.md5 (input => UTL_RAW.cast_to_raw(' . $this->helper->quoteColumnName($input) .')))'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* As per https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions060.htm |
|
38
|
|
|
* Oracle uses the first value to cast the rest or the values. So when the |
|
39
|
|
|
* first value is a literal, plain value or column, instead of doing the |
|
40
|
|
|
* math, it will cast the expression to int and continue with a "0". So when |
|
41
|
|
|
* the second parameter is a function or column, we have to put that as |
|
42
|
|
|
* first parameter. |
|
43
|
|
|
* |
|
44
|
|
|
* @param string|ILiteral|IParameter|IQueryFunction $x |
|
45
|
|
|
* @param string|ILiteral|IParameter|IQueryFunction $y |
|
46
|
|
|
* @return IQueryFunction |
|
47
|
|
|
*/ |
|
48
|
|
|
public function greatest($x, $y) { |
|
49
|
|
|
if (is_string($y) || $y instanceof IQueryFunction) { |
|
50
|
|
|
return parent::greatest($y, $x); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return parent::greatest($x, $y); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* As per https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions060.htm |
|
58
|
|
|
* Oracle uses the first value to cast the rest or the values. So when the |
|
59
|
|
|
* first value is a literal, plain value or column, instead of doing the |
|
60
|
|
|
* math, it will cast the expression to int and continue with a "0". So when |
|
61
|
|
|
* the second parameter is a function or column, we have to put that as |
|
62
|
|
|
* first parameter. |
|
63
|
|
|
* |
|
64
|
|
|
* @param string|ILiteral|IParameter|IQueryFunction $x |
|
65
|
|
|
* @param string|ILiteral|IParameter|IQueryFunction $y |
|
66
|
|
|
* @return IQueryFunction |
|
67
|
|
|
*/ |
|
68
|
|
|
public function least($x, $y) { |
|
69
|
|
|
if (is_string($y) || $y instanceof IQueryFunction) { |
|
70
|
|
|
return parent::least($y, $x); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return parent::least($x, $y); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|