|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace StorageTests\Database\Dialects; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use Builder; |
|
7
|
|
|
use CommonTestClass; |
|
8
|
|
|
use kalanis\kw_mapper\Interfaces\IQueryBuilder; |
|
9
|
|
|
use kalanis\kw_mapper\MapperException; |
|
10
|
|
|
use kalanis\kw_mapper\Storage\Database\Dialects; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class OracleTest extends CommonTestClass |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @throws MapperException |
|
17
|
|
|
*/ |
|
18
|
|
|
public function testDescribe(): void |
|
19
|
|
|
{ |
|
20
|
|
|
$query = new Builder(); |
|
21
|
|
|
$query->setBaseTable('foo'); |
|
22
|
|
|
$sql = new Dialects\Oracle(); |
|
23
|
|
|
$this->assertEquals('DESCRIBE `foo`;', $sql->describe($query)); |
|
24
|
|
|
$this->assertNotEmpty($sql->availableJoins()); |
|
25
|
|
|
$query->resetCounter(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @throws MapperException |
|
30
|
|
|
*/ |
|
31
|
|
|
public function testInsert(): void |
|
32
|
|
|
{ |
|
33
|
|
|
$query = new Builder(); |
|
34
|
|
|
$query->setBaseTable('foo'); |
|
35
|
|
|
$query->addProperty('foo', 'bar', 'baz'); |
|
36
|
|
|
$query->addProperty('foo', 'htf', 'yjd'); |
|
37
|
|
|
$query->addProperty('foo', 'vrs', 'abh'); |
|
38
|
|
|
$sql = new Dialects\Oracle(); |
|
39
|
|
|
$this->assertEquals('INSERT INTO `foo` (`bar`, `htf`, `vrs`) VALUES (:bar_0, :htf_1, :vrs_2);', $sql->insert($query)); |
|
40
|
|
|
$this->assertEquals([ ':bar_0' => 'baz', ':htf_1' => 'yjd', ':vrs_2' => 'abh', ], $query->getParams()); |
|
41
|
|
|
$query->resetCounter(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @throws MapperException |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testDelete(): void |
|
48
|
|
|
{ |
|
49
|
|
|
$query = new Builder(); |
|
50
|
|
|
$query->setBaseTable('foo'); |
|
51
|
|
|
$query->addCondition('foo', 'dbt', IQueryBuilder::OPERATION_EQ, 'ggf'); |
|
52
|
|
|
$query->addCondition('foo', 'dfd', IQueryBuilder::OPERATION_NEQ, 'yxn'); |
|
53
|
|
|
$sql = new Dialects\Oracle(); |
|
54
|
|
|
$this->assertEquals('DELETE FROM `foo` WHERE `dbt` = :dbt_0 AND `dfd` != :dfd_1;', $sql->delete($query)); |
|
55
|
|
|
$this->assertEquals([ ':dbt_0' => 'ggf', ':dfd_1' => 'yxn', ], $query->getParams()); |
|
56
|
|
|
$query->resetCounter(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @throws MapperException |
|
61
|
|
|
*/ |
|
62
|
|
|
public function testUpdate(): void |
|
63
|
|
|
{ |
|
64
|
|
|
$query = new Builder(); |
|
65
|
|
|
$query->setBaseTable('foo'); |
|
66
|
|
|
$query->addProperty('foo', 'bar', 'baz'); |
|
67
|
|
|
$query->addProperty('foo', 'htf', 'yjd'); |
|
68
|
|
|
$query->addProperty('foo', 'vrs', 'abh'); |
|
69
|
|
|
$query->addCondition('foo', 'dbt', IQueryBuilder::OPERATION_EQ, 'ggf'); |
|
70
|
|
|
$query->addCondition('foo', 'dfd', IQueryBuilder::OPERATION_NEQ, 'yxn'); |
|
71
|
|
|
$sql = new Dialects\Oracle(); |
|
72
|
|
|
$this->assertEquals('UPDATE `foo` SET `bar` = :bar_0, `htf` = :htf_1, `vrs` = :vrs_2 WHERE `dbt` = :dbt_3 AND `dfd` != :dfd_4;', $sql->update($query)); |
|
73
|
|
|
$this->assertEquals([ ':bar_0' => 'baz', ':htf_1' => 'yjd', ':vrs_2' => 'abh', ':dbt_3' => 'ggf', ':dfd_4' => 'yxn', ], $query->getParams()); |
|
74
|
|
|
$query->resetCounter(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @throws MapperException |
|
79
|
|
|
*/ |
|
80
|
|
|
public function testSelect(): void |
|
81
|
|
|
{ |
|
82
|
|
|
$query = new Builder(); |
|
83
|
|
|
$query->setBaseTable('foo'); |
|
84
|
|
|
$query->addColumn('foo', 'bar', 'baz'); |
|
85
|
|
|
$query->addColumn('foo', 'htf', 'yjd'); |
|
86
|
|
|
$query->addColumn('dfg', 'vrs', 'abh'); |
|
87
|
|
|
$query->addJoin('dfg', 'btr', 'gda', 'foo', 'fds', IQueryBuilder::JOIN_LEFT, 'dfg'); |
|
88
|
|
|
$query->addCondition('foo', 'dbt', IQueryBuilder::OPERATION_EQ, 'ggf'); |
|
89
|
|
|
$query->addCondition('foo', 'dfd', IQueryBuilder::OPERATION_NEQ, 'yxn'); |
|
90
|
|
|
$query->addOrderBy('dfg', 'vrs', IQueryBuilder::ORDER_ASC); |
|
91
|
|
|
$query->addGroupBy('foo', 'gds'); |
|
92
|
|
|
$query->setLimits(5,3); |
|
93
|
|
|
$sql = new Dialects\Oracle(); |
|
94
|
|
|
$this->assertEquals('SELECT `foo`.`bar` AS `baz`, `foo`.`htf` AS `yjd`, `dfg`.`vrs` AS `abh` FROM `foo` LEFT JOIN `btr` AS `dfg` ON (`foo`.`fds` = `dfg`.`gda`) WHERE `foo`.`dbt` = :dbt_0 AND `foo`.`dfd` != :dfd_1 GROUP BY `foo`.`gds` ORDER BY `dfg`.`vrs` ASC OFFSET 5 ROWS FETCH NEXT 3 ROWS ONLY;', $sql->select($query)); |
|
95
|
|
|
$this->assertEquals([ ':dbt_0' => 'ggf', ':dfd_1' => 'yxn', ], $query->getParams()); |
|
96
|
|
|
$query->setLimit(null); |
|
97
|
|
|
$this->assertEquals('SELECT `foo`.`bar` AS `baz`, `foo`.`htf` AS `yjd`, `dfg`.`vrs` AS `abh` FROM `foo` LEFT JOIN `btr` AS `dfg` ON (`foo`.`fds` = `dfg`.`gda`) WHERE `foo`.`dbt` = :dbt_0 AND `foo`.`dfd` != :dfd_1 GROUP BY `foo`.`gds` ORDER BY `dfg`.`vrs` ASC;', $sql->select($query)); |
|
98
|
|
|
$query->resetCounter(); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|