|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Mysql; |
|
6
|
|
|
|
|
7
|
|
|
use Exception; |
|
8
|
|
|
use Yiisoft\Db\Exception\InvalidConfigException; |
|
9
|
|
|
use Yiisoft\Db\Schema\AbstractColumnSchemaBuilder; |
|
10
|
|
|
use Yiisoft\Db\Schema\QuoterInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* The class ColumnSchemaBuilder for Mysql database. |
|
14
|
|
|
*/ |
|
15
|
|
|
final class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder |
|
16
|
|
|
{ |
|
17
|
|
|
private QuoterInterface|null $quoter = null; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Builds the unsigned string for column. Defaults to unsupported. |
|
21
|
|
|
* |
|
22
|
|
|
* @return string a string containing UNSIGNED keyword. |
|
23
|
|
|
*/ |
|
24
|
11 |
|
protected function buildUnsignedString(): string |
|
25
|
|
|
{ |
|
26
|
11 |
|
return $this->isUnsigned() ? ' UNSIGNED' : ''; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Builds the comment specification for the column. |
|
31
|
|
|
* |
|
32
|
|
|
* @throws Exception|InvalidConfigException |
|
33
|
|
|
* |
|
34
|
|
|
* @return string a string containing the COMMENT keyword and the comment itself. |
|
35
|
|
|
*/ |
|
36
|
11 |
|
protected function buildCommentString(): string |
|
37
|
|
|
{ |
|
38
|
11 |
|
if ($this->quoter === null) { |
|
39
|
1 |
|
throw new InvalidConfigException('Quoter not setted.'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
10 |
|
return $this->getComment() !== null ? ' COMMENT ' |
|
43
|
10 |
|
. (string) $this->quoter->quoteValue($this->getComment()) : ''; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
11 |
|
public function asString(): string |
|
47
|
|
|
{ |
|
48
|
11 |
|
$format = match ($this->getTypeCategory()) { |
|
49
|
11 |
|
self::CATEGORY_PK => '{type}{length}{comment}{check}{append}', |
|
50
|
11 |
|
self::CATEGORY_NUMERIC => '{type}{length}{unsigned}{notnull}{default}{unique}{comment}{append}{check}', |
|
51
|
11 |
|
default => '{type}{length}{notnull}{default}{unique}{comment}{append}{check}', |
|
52
|
11 |
|
}; |
|
53
|
|
|
|
|
54
|
11 |
|
return $this->buildCompleteString($format); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
148 |
|
public function setQuoter(QuoterInterface $quoter): self |
|
58
|
|
|
{ |
|
59
|
148 |
|
$this->quoter = $quoter; |
|
60
|
148 |
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|