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
|
345 |
|
public function __construct( |
18
|
|
|
private QueryBuilderInterface $queryBuilder, |
19
|
|
|
private QuoterInterface $quoter, |
20
|
|
|
SchemaInterface $schema |
21
|
|
|
) { |
22
|
345 |
|
parent::__construct($queryBuilder, $quoter, $schema); |
23
|
|
|
} |
24
|
|
|
|
25
|
4 |
|
public function addForeignKey(string $name, string $table, array|string $columns, string $refTable, array|string $refColumns, ?string $delete = null, ?string $update = null): string |
26
|
|
|
{ |
27
|
4 |
|
$sql = 'ALTER TABLE ' . $this->quoter->quoteTableName($table) |
28
|
4 |
|
. ' ADD CONSTRAINT ' . $this->quoter->quoteColumnName($name) |
29
|
4 |
|
. ' FOREIGN KEY (' . $this->queryBuilder->buildColumns($columns) . ')' |
30
|
4 |
|
. ' REFERENCES ' . $this->quoter->quoteTableName($refTable) |
31
|
4 |
|
. ' (' . $this->queryBuilder->buildColumns($refColumns) . ')'; |
32
|
|
|
|
33
|
4 |
|
if ($delete !== null) { |
34
|
2 |
|
$sql .= ' ON DELETE ' . $delete; |
35
|
|
|
} |
36
|
|
|
|
37
|
4 |
|
if ($update !== null) { |
38
|
|
|
throw new Exception('Oracle does not support ON UPDATE clause.'); |
39
|
|
|
} |
40
|
|
|
|
41
|
4 |
|
return $sql; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function alterColumn(string $table, string $column, ColumnSchemaBuilder|string $type): string |
45
|
|
|
{ |
46
|
|
|
return 'ALTER TABLE ' |
47
|
|
|
. $this->quoter->quoteTableName($table) |
48
|
|
|
. ' MODIFY ' |
49
|
|
|
. $this->quoter->quoteColumnName($column) |
50
|
|
|
. ' ' . $this->queryBuilder->getColumnType($type); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function checkIntegrity(string $schema = '', string $table = '', bool $check = true): string |
54
|
|
|
{ |
55
|
|
|
throw new NotSupportedException('Oracle does not support enabling/disabling integrity check.'); |
56
|
|
|
} |
57
|
|
|
|
58
|
2 |
|
public function dropCommentFromColumn(string $table, string $column): string |
59
|
|
|
{ |
60
|
|
|
return 'COMMENT ON COLUMN ' |
61
|
2 |
|
. $this->quoter->quoteTableName($table) |
62
|
|
|
. '.' |
63
|
2 |
|
. $this->quoter->quoteColumnName($column) |
64
|
|
|
. " IS ''"; |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
public function dropCommentFromTable(string $table): string |
68
|
|
|
{ |
69
|
1 |
|
return 'COMMENT ON TABLE ' . $this->quoter->quoteTableName($table) . " IS ''"; |
70
|
|
|
} |
71
|
|
|
|
72
|
2 |
|
public function dropIndex(string $name, string $table): string |
73
|
|
|
{ |
74
|
2 |
|
return 'DROP INDEX ' . $this->quoter->quoteTableName($name); |
75
|
|
|
} |
76
|
|
|
|
77
|
2 |
|
public function renameTable(string $oldName, string $newName): string |
78
|
|
|
{ |
79
|
2 |
|
return 'ALTER TABLE ' . $this->quoter->quoteTableName($oldName) . ' RENAME TO ' . |
80
|
2 |
|
$this->quoter->quoteTableName($newName); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
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: