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