1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link http://www.yiiframework.com/ |
4
|
|
|
* @copyright Copyright (c) 2008 Yii Software LLC |
5
|
|
|
* @license http://www.yiiframework.com/license/ |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace yii\db\mssql; |
9
|
|
|
|
10
|
|
|
use yii\db\ColumnSchemaBuilder as AbstractColumnSchemaBuilder; |
11
|
|
|
use yii\db\Expression; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* ColumnSchemaBuilder is the schema builder for MSSQL databases. |
15
|
|
|
* |
16
|
|
|
* @property-read string|null $checkValue The `CHECK` constraint for the column. |
17
|
|
|
* @property-read string|Expression|null $defaultValue Default value of the column. |
18
|
|
|
* |
19
|
|
|
* @author Valerii Gorbachev <[email protected]> |
20
|
|
|
* @since 2.0.42 |
21
|
|
|
*/ |
22
|
|
|
class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder |
23
|
|
|
{ |
24
|
|
|
protected $format = '{type}{length}{notnull}{unique}{default}{check}{append}'; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Builds the full string for the column's schema. |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
|
|
public function __toString() |
32
|
|
|
{ |
33
|
|
|
if ($this->getTypeCategory() === self::CATEGORY_PK) { |
34
|
|
|
$format = '{type}{check}{comment}{append}'; |
35
|
|
|
} else { |
36
|
|
|
$format = $this->format; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return $this->buildCompleteString($format); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Changes default format string to MSSQL ALTER COMMAND. |
44
|
|
|
*/ |
45
|
|
|
public function setAlterColumnFormat() |
46
|
|
|
{ |
47
|
|
|
$this->format = '{type}{length}{notnull}{append}'; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Getting the `Default` value for constraint |
52
|
|
|
* @return string|Expression|null default value of the column. |
53
|
|
|
*/ |
54
|
|
|
public function getDefaultValue() |
55
|
|
|
{ |
56
|
|
|
if ($this->default instanceof Expression) { |
57
|
|
|
return $this->default; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $this->buildDefaultValue(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get the `Check` value for constraint |
65
|
|
|
* @return string|null the `CHECK` constraint for the column. |
66
|
|
|
*/ |
67
|
|
|
public function getCheckValue() |
68
|
|
|
{ |
69
|
|
|
return $this->check !== null ? (string) $this->check : null; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return bool whether the column values should be unique. If this is `true`, a `UNIQUE` constraint will be added. |
74
|
|
|
*/ |
75
|
|
|
public function isUnique() |
76
|
|
|
{ |
77
|
|
|
return $this->isUnique; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|