1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Mssql; |
6
|
|
|
|
7
|
|
|
use Yiisoft\Db\QueryBuilder\QueryBuilder as AbstractQueryBuilder; |
8
|
|
|
use Yiisoft\Db\Schema\ColumnSchemaBuilder; |
9
|
|
|
use Yiisoft\Db\Schema\QuoterInterface; |
10
|
|
|
use Yiisoft\Db\Schema\Schema; |
|
|
|
|
11
|
|
|
use Yiisoft\Db\Schema\SchemaInterface; |
12
|
|
|
|
13
|
|
|
use function preg_replace; |
14
|
|
|
|
15
|
|
|
final class QueryBuilder extends AbstractQueryBuilder |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Defines a CLUSTERED index type for {@see createIndex()}. |
19
|
|
|
*/ |
20
|
|
|
public const INDEX_CLUSTERED = 'CLUSTERED'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Defines a CLUSTERED index type for {@see createIndex()}. |
24
|
|
|
*/ |
25
|
|
|
public const INDEX_NONCLUSTERED = 'NONCLUSTERED'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @psalm-var string[] $typeMap Mapping from abstract column types (keys) to physical column types (values). |
29
|
|
|
*/ |
30
|
|
|
protected array $typeMap = [ |
31
|
|
|
Schema::TYPE_PK => 'int IDENTITY PRIMARY KEY', |
32
|
|
|
Schema::TYPE_UPK => 'int IDENTITY PRIMARY KEY', |
33
|
|
|
Schema::TYPE_BIGPK => 'bigint IDENTITY PRIMARY KEY', |
34
|
|
|
Schema::TYPE_UBIGPK => 'bigint IDENTITY PRIMARY KEY', |
35
|
|
|
Schema::TYPE_CHAR => 'nchar(1)', |
36
|
|
|
Schema::TYPE_STRING => 'nvarchar(255)', |
37
|
|
|
Schema::TYPE_TEXT => 'nvarchar(max)', |
38
|
|
|
Schema::TYPE_TINYINT => 'tinyint', |
39
|
|
|
Schema::TYPE_SMALLINT => 'smallint', |
40
|
|
|
Schema::TYPE_INTEGER => 'int', |
41
|
|
|
Schema::TYPE_BIGINT => 'bigint', |
42
|
|
|
Schema::TYPE_FLOAT => 'float', |
43
|
|
|
Schema::TYPE_DOUBLE => 'float', |
44
|
|
|
Schema::TYPE_DECIMAL => 'decimal(18,0)', |
45
|
|
|
Schema::TYPE_DATETIME => 'datetime', |
46
|
|
|
Schema::TYPE_TIMESTAMP => 'datetime', |
47
|
|
|
Schema::TYPE_TIME => 'time', |
48
|
|
|
Schema::TYPE_DATE => 'date', |
49
|
|
|
Schema::TYPE_BINARY => 'varbinary(max)', |
50
|
|
|
Schema::TYPE_BOOLEAN => 'bit', |
51
|
|
|
Schema::TYPE_MONEY => 'decimal(19,4)', |
52
|
|
|
]; |
53
|
|
|
private DDLQueryBuilder $ddlBuilder; |
54
|
|
|
private DMLQueryBuilder $dmlBuilder; |
55
|
|
|
private DQLQueryBuilder $dqlBuilder; |
56
|
|
|
|
57
|
386 |
|
public function __construct(QuoterInterface $quoter, SchemaInterface $schema) |
58
|
|
|
{ |
59
|
386 |
|
$this->ddlBuilder = new DDLQueryBuilder($this, $quoter, $schema); |
60
|
386 |
|
$this->dmlBuilder = new DMLQueryBuilder($this, $quoter, $schema); |
61
|
386 |
|
$this->dqlBuilder = new DQLQueryBuilder($this, $quoter, $schema); |
62
|
386 |
|
parent::__construct($quoter, $schema, $this->ddlBuilder, $this->dmlBuilder, $this->dqlBuilder); |
63
|
|
|
} |
64
|
|
|
|
65
|
13 |
|
public function getColumnType(ColumnSchemaBuilder|string $type): string |
66
|
|
|
{ |
67
|
13 |
|
$columnType = parent::getColumnType($type); |
68
|
|
|
|
69
|
|
|
/** remove unsupported keywords*/ |
70
|
13 |
|
$columnType = preg_replace("/\s*comment '.*'/i", '', $columnType); |
71
|
13 |
|
return preg_replace('/ first$/i', '', $columnType); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
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: