|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace kalanis\kw_mapper\Storage\Database\Dialects; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use kalanis\kw_mapper\Interfaces\IQueryBuilder; |
|
7
|
|
|
use kalanis\kw_mapper\Storage\Shared\QueryBuilder; |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class Oracle |
|
12
|
|
|
* @package kalanis\kw_mapper\Storage\Database\Dialects |
|
13
|
|
|
* Create queries for Oracle servers |
|
14
|
|
|
* WTF with limits - use Oracle12c database or you must write your own dialect |
|
15
|
|
|
* Also for the similar purposes you cannot limit amount of deleted or updated rows |
|
16
|
|
|
* @link https://www.databasestar.com/limit-the-number-of-rows-in-oracle/ |
|
17
|
|
|
*/ |
|
18
|
|
|
class Oracle extends ADialect |
|
19
|
|
|
{ |
|
20
|
|
|
use TEscapedDialect; |
|
21
|
|
|
|
|
22
|
1 |
|
public function insert(QueryBuilder $builder) |
|
23
|
|
|
{ |
|
24
|
1 |
|
return sprintf('INSERT INTO `%s` (%s) VALUES (%s);', |
|
25
|
1 |
|
$builder->getBaseTable(), |
|
26
|
1 |
|
$this->makeSimplePropertyList($builder->getProperties()), |
|
27
|
1 |
|
$this->makePropertyEntries($builder->getProperties()) |
|
28
|
1 |
|
); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
1 |
|
public function select(QueryBuilder $builder) |
|
32
|
|
|
{ |
|
33
|
1 |
|
return sprintf('SELECT %s FROM `%s` %s %s%s%s%s%s;', |
|
34
|
1 |
|
$this->makeFullColumns($builder->getColumns()), |
|
35
|
1 |
|
$builder->getBaseTable(), |
|
36
|
1 |
|
$this->makeJoin($builder->getJoins()), |
|
37
|
1 |
|
$this->makeFullConditions($builder->getConditions(), $builder->getRelation()), |
|
38
|
1 |
|
$this->makeFullGrouping($builder->getGrouping()), |
|
39
|
1 |
|
$this->makeFullHaving($builder->getHavingCondition(), $builder->getRelation()), |
|
40
|
1 |
|
$this->makeFullOrdering($builder->getOrdering()), |
|
41
|
1 |
|
$this->makeLimits($builder->getLimit(), $builder->getOffset()) |
|
42
|
1 |
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
1 |
|
public function update(QueryBuilder $builder) |
|
46
|
|
|
{ |
|
47
|
1 |
|
return sprintf('UPDATE `%s` SET %s%s;', |
|
48
|
1 |
|
$builder->getBaseTable(), |
|
49
|
1 |
|
$this->makeProperty($builder->getProperties()), |
|
50
|
1 |
|
$this->makeSimpleConditions($builder->getConditions(), $builder->getRelation()) |
|
51
|
1 |
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
1 |
|
public function delete(QueryBuilder $builder) |
|
55
|
|
|
{ |
|
56
|
1 |
|
return sprintf('DELETE FROM `%s`%s;', |
|
57
|
1 |
|
$builder->getBaseTable(), |
|
58
|
1 |
|
$this->makeSimpleConditions($builder->getConditions(), $builder->getRelation()) |
|
59
|
1 |
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
public function describe(QueryBuilder $builder) |
|
63
|
|
|
{ |
|
64
|
1 |
|
return sprintf('DESCRIBE `%s`;', $builder->getBaseTable() ); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
1 |
|
protected function makeLimits(?int $limit, ?int $offset): string |
|
68
|
|
|
{ |
|
69
|
1 |
|
return is_null($limit) |
|
70
|
1 |
|
? '' |
|
71
|
1 |
|
: sprintf(' OFFSET %d ROWS FETCH NEXT %d ROWS ONLY', intval($offset), $limit) |
|
72
|
1 |
|
; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
public function availableJoins(): array |
|
76
|
|
|
{ |
|
77
|
1 |
|
return [ |
|
78
|
1 |
|
IQueryBuilder::JOIN_BASIC, |
|
79
|
1 |
|
IQueryBuilder::JOIN_INNER, |
|
80
|
1 |
|
IQueryBuilder::JOIN_CROSS, |
|
81
|
1 |
|
IQueryBuilder::JOIN_LEFT, |
|
82
|
1 |
|
IQueryBuilder::JOIN_RIGHT, |
|
83
|
1 |
|
IQueryBuilder::JOIN_FULL, |
|
84
|
1 |
|
]; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|