1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Oracle; |
6
|
|
|
|
7
|
|
|
use Yiisoft\Db\Exception\Exception; |
8
|
|
|
use Yiisoft\Db\Exception\NotSupportedException; |
9
|
|
|
use Yiisoft\Db\QueryBuilder\AbstractDDLQueryBuilder; |
10
|
|
|
use Yiisoft\Db\Schema\Builder\ColumnInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Implements a (Data Definition Language) SQL statements for Oracle Server. |
14
|
|
|
*/ |
15
|
|
|
final class DDLQueryBuilder extends AbstractDDLQueryBuilder |
16
|
|
|
{ |
17
|
3 |
|
public function addDefaultValue(string $table, string $name, string $column, mixed $value): string |
18
|
|
|
{ |
19
|
3 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by Oracle.'); |
20
|
|
|
} |
21
|
|
|
|
22
|
8 |
|
public function addForeignKey( |
23
|
|
|
string $table, |
24
|
|
|
string $name, |
25
|
|
|
array|string $columns, |
26
|
|
|
string $referenceTable, |
27
|
|
|
array|string $referenceColumns, |
28
|
|
|
string $delete = null, |
29
|
|
|
string $update = null |
30
|
|
|
): string { |
31
|
8 |
|
$sql = 'ALTER TABLE ' . $this->quoter->quoteTableName($table) |
32
|
8 |
|
. ' ADD CONSTRAINT ' . $this->quoter->quoteColumnName($name) |
33
|
8 |
|
. ' FOREIGN KEY (' . $this->queryBuilder->buildColumns($columns) . ')' |
34
|
8 |
|
. ' REFERENCES ' . $this->quoter->quoteTableName($referenceTable) |
35
|
8 |
|
. ' (' . $this->queryBuilder->buildColumns($referenceColumns) . ')'; |
36
|
|
|
|
37
|
8 |
|
if ($delete !== null) { |
38
|
3 |
|
$sql .= ' ON DELETE ' . $delete; |
39
|
|
|
} |
40
|
|
|
|
41
|
8 |
|
if ($update !== null) { |
42
|
1 |
|
throw new Exception('Oracle does not support ON UPDATE clause.'); |
43
|
|
|
} |
44
|
|
|
|
45
|
7 |
|
return $sql; |
46
|
|
|
} |
47
|
|
|
|
48
|
1 |
|
public function alterColumn(string $table, string $column, ColumnInterface|string $type): string |
49
|
|
|
{ |
50
|
1 |
|
return 'ALTER TABLE ' |
51
|
1 |
|
. $this->quoter->quoteTableName($table) |
52
|
1 |
|
. ' MODIFY ' |
53
|
1 |
|
. $this->quoter->quoteColumnName($column) |
54
|
1 |
|
. ' ' . $this->queryBuilder->getColumnType($type); |
55
|
|
|
} |
56
|
|
|
|
57
|
1 |
|
public function checkIntegrity(string $schema = '', string $table = '', bool $check = true): string |
58
|
|
|
{ |
59
|
1 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by Oracle.'); |
60
|
|
|
} |
61
|
|
|
|
62
|
2 |
|
public function dropCommentFromColumn(string $table, string $column): string |
63
|
|
|
{ |
64
|
2 |
|
return 'COMMENT ON COLUMN ' |
65
|
2 |
|
. $this->quoter->quoteTableName($table) |
66
|
2 |
|
. '.' |
67
|
2 |
|
. $this->quoter->quoteColumnName($column) |
68
|
2 |
|
. " IS ''"; |
69
|
|
|
} |
70
|
|
|
|
71
|
2 |
|
public function dropCommentFromTable(string $table): string |
72
|
|
|
{ |
73
|
2 |
|
return 'COMMENT ON TABLE ' . $this->quoter->quoteTableName($table) . " IS ''"; |
74
|
|
|
} |
75
|
|
|
|
76
|
2 |
|
public function dropDefaultValue(string $table, string $name): string |
77
|
|
|
{ |
78
|
2 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by Oracle.'); |
79
|
|
|
} |
80
|
|
|
|
81
|
2 |
|
public function dropIndex(string $table, string $name): string |
82
|
|
|
{ |
83
|
2 |
|
return 'DROP INDEX ' . $this->quoter->quoteTableName($name); |
84
|
|
|
} |
85
|
|
|
|
86
|
3 |
|
public function renameTable(string $oldName, string $newName): string |
87
|
|
|
{ |
88
|
3 |
|
return 'ALTER TABLE ' . $this->quoter->quoteTableName($oldName) . ' RENAME TO ' . |
89
|
3 |
|
$this->quoter->quoteTableName($newName); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|