-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathQuery.php
More file actions
92 lines (74 loc) · 2.49 KB
/
Copy pathQuery.php
File metadata and controls
92 lines (74 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
declare(strict_types=1);
namespace Atk4\Data\Persistence\Sql\Oracle;
use Atk4\Data\Exception;
use Atk4\Data\Field;
use Atk4\Data\Persistence\Sql\Query as BaseQuery;
class Query extends BaseQuery
{
use ExpressionTrait;
protected string $paramBase = 'xxaaaa';
protected string $identifierEscapeChar = '"';
protected string $expressionClass = Expression::class;
#[\Override]
public function render(): array
{
if ($this->mode === 'select' && count($this->args['table'] ?? []) === 0) {
try {
$this->table('DUAL');
return parent::render();
} finally {
unset($this->args['table']);
}
}
return parent::render();
}
#[\Override]
protected function _subrenderCondition(array $row): string
{
if (count($row) === 3) {
[$field, $cond, $value] = $row;
if ($cond === null) {
$cond = '=';
}
}
if (count($row) === 3 && $field instanceof Field
&& in_array($field->type, ['text', 'blob'], true)) {
if ($field->type === 'text') {
$field = $this->expr('LOWER([])', [$field]);
$value = $this->expr('LOWER([])', [$value]);
}
if (in_array($cond, ['=', '!='], true)) {
$row = [$this->expr('dbms_lob.compare([], [])', [$field, $value]), $cond, 0];
} else {
throw (new Exception('Unsupported CLOB/BLOB field operator'))
->addMoreInfo('operator', $cond)
->addMoreInfo('type', $field->type);
}
}
return parent::_subrenderCondition($row);
}
#[\Override]
protected function _renderLimit(): ?string
{
if (!isset($this->args['limit'])) {
return null;
}
$cnt = (int) $this->args['limit']['cnt'];
$shift = (int) $this->args['limit']['shift'];
return ($shift ? ' offset ' . $shift . ' rows' : '')
. ' fetch next ' . $cnt . ' rows only';
}
#[\Override]
public function groupConcat($field, string $separator = ',')
{
return $this->expr('listagg({field}, []) within group (order by {field})', ['field' => $field, $separator]);
}
#[\Override]
public function exists()
{
return $this->dsql()->mode('select')->field(
$this->dsql()->expr('case when exists[] then 1 else 0 end', [$this])
);
}
}