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\DDLQueryBuilder as AbstractDDLQueryBuilder; |
10
|
|
|
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; |
11
|
|
|
use Yiisoft\Db\Schema\ColumnSchemaBuilder; |
|
|
|
|
12
|
|
|
use Yiisoft\Db\Schema\QuoterInterface; |
13
|
|
|
use Yiisoft\Db\Schema\SchemaInterface; |
14
|
|
|
|
15
|
|
|
final class DDLQueryBuilder extends AbstractDDLQueryBuilder |
16
|
|
|
{ |
17
|
384 |
|
public function __construct( |
18
|
|
|
private QueryBuilderInterface $queryBuilder, |
19
|
|
|
private QuoterInterface $quoter, |
20
|
|
|
SchemaInterface $schema |
21
|
|
|
) { |
22
|
384 |
|
parent::__construct($queryBuilder, $quoter, $schema); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @throws NotSupportedException |
27
|
|
|
*/ |
28
|
1 |
|
public function addDefaultValue(string $name, string $table, string $column, mixed $value): string |
29
|
|
|
{ |
30
|
1 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by Oracle.'); |
31
|
|
|
} |
32
|
|
|
|
33
|
7 |
|
public function addForeignKey( |
34
|
|
|
string $name, |
35
|
|
|
string $table, |
36
|
|
|
array|string $columns, |
37
|
|
|
string $refTable, |
38
|
|
|
array|string $refColumns, |
39
|
|
|
string $delete = null, |
40
|
|
|
string $update = null |
41
|
|
|
): string { |
42
|
7 |
|
$sql = 'ALTER TABLE ' . $this->quoter->quoteTableName($table) |
43
|
7 |
|
. ' ADD CONSTRAINT ' . $this->quoter->quoteColumnName($name) |
44
|
7 |
|
. ' FOREIGN KEY (' . $this->queryBuilder->buildColumns($columns) . ')' |
45
|
7 |
|
. ' REFERENCES ' . $this->quoter->quoteTableName($refTable) |
46
|
7 |
|
. ' (' . $this->queryBuilder->buildColumns($refColumns) . ')'; |
47
|
|
|
|
48
|
7 |
|
if ($delete !== null) { |
49
|
2 |
|
$sql .= ' ON DELETE ' . $delete; |
50
|
|
|
} |
51
|
|
|
|
52
|
7 |
|
if ($update !== null) { |
53
|
|
|
throw new Exception('Oracle does not support ON UPDATE clause.'); |
54
|
|
|
} |
55
|
|
|
|
56
|
7 |
|
return $sql; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function alterColumn(string $table, string $column, ColumnSchemaBuilder|string $type): string |
60
|
|
|
{ |
61
|
|
|
return 'ALTER TABLE ' |
62
|
|
|
. $this->quoter->quoteTableName($table) |
63
|
|
|
. ' MODIFY ' |
64
|
|
|
. $this->quoter->quoteColumnName($column) |
65
|
|
|
. ' ' . $this->queryBuilder->getColumnType($type); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function checkIntegrity(string $schema = '', string $table = '', bool $check = true): string |
69
|
|
|
{ |
70
|
|
|
throw new NotSupportedException('Oracle does not support enabling/disabling integrity check.'); |
71
|
|
|
} |
72
|
|
|
|
73
|
2 |
|
public function dropCommentFromColumn(string $table, string $column): string |
74
|
|
|
{ |
75
|
|
|
return 'COMMENT ON COLUMN ' |
76
|
2 |
|
. $this->quoter->quoteTableName($table) |
77
|
|
|
. '.' |
78
|
2 |
|
. $this->quoter->quoteColumnName($column) |
79
|
|
|
. " IS ''"; |
80
|
|
|
} |
81
|
|
|
|
82
|
2 |
|
public function dropCommentFromTable(string $table): string |
83
|
|
|
{ |
84
|
2 |
|
return 'COMMENT ON TABLE ' . $this->quoter->quoteTableName($table) . " IS ''"; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @throws NotSupportedException |
89
|
|
|
*/ |
90
|
1 |
|
public function dropDefaultValue(string $name, string $table): string |
91
|
|
|
{ |
92
|
1 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by Oracle.'); |
93
|
|
|
} |
94
|
|
|
|
95
|
2 |
|
public function dropIndex(string $name, string $table): string |
96
|
|
|
{ |
97
|
2 |
|
return 'DROP INDEX ' . $this->quoter->quoteTableName($name); |
98
|
|
|
} |
99
|
|
|
|
100
|
2 |
|
public function renameTable(string $oldName, string $newName): string |
101
|
|
|
{ |
102
|
2 |
|
return 'ALTER TABLE ' . $this->quoter->quoteTableName($oldName) . ' RENAME TO ' . |
103
|
2 |
|
$this->quoter->quoteTableName($newName); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: