クラス yii\db\mssql\ColumnSchemaBuilder
ColumnSchemaBuilderは、MSSQLデータベースのスキーマビルダーです。
公開プロパティ
公開メソッド
保護されたメソッド
メソッド | 説明 | 定義元 |
---|---|---|
buildAfterString() | 列のafter制約を構築します。デフォルトではサポートされていません。 | yii\db\ColumnSchemaBuilder |
buildAppendString() | 列定義に付加されるカスタム文字列を構築します。 | yii\db\ColumnSchemaBuilder |
buildCheckString() | 列のcheck制約を構築します。 | yii\db\ColumnSchemaBuilder |
buildCommentString() | 列のコメント仕様を構築します。 | yii\db\ColumnSchemaBuilder |
buildCompleteString() | 入力形式から完全な列定義を返します。 | yii\db\ColumnSchemaBuilder |
buildDefaultString() | 列のデフォルト値仕様を構築します。 | yii\db\ColumnSchemaBuilder |
buildDefaultValue() | 列のデフォルト値を返します。 | yii\db\ColumnSchemaBuilder |
buildFirstString() | 列の最初の制約を構築します。デフォルトではサポートされていません。 | yii\db\ColumnSchemaBuilder |
buildLengthString() | 列の長さ/精度部分を構築します。 | yii\db\ColumnSchemaBuilder |
buildNotNullString() | 列のNOT NULL制約を構築します。 | yii\db\ColumnSchemaBuilder |
buildUniqueString() | 列の一意制約を構築します。 | yii\db\ColumnSchemaBuilder |
buildUnsignedString() | 列のunsigned文字列を構築します。デフォルトではサポートされていません。 | yii\db\ColumnSchemaBuilder |
getTypeCategory() | 列の種類のカテゴリを返します。 | yii\db\ColumnSchemaBuilder |
定数
定数 | 値 | 説明 | 定義元 |
---|---|---|---|
CATEGORY_NUMERIC | 'numeric' | yii\db\ColumnSchemaBuilder | |
CATEGORY_OTHER | 'other' | yii\db\ColumnSchemaBuilder | |
CATEGORY_PK | 'pk' | yii\db\ColumnSchemaBuilder | |
CATEGORY_STRING | 'string' | yii\db\ColumnSchemaBuilder | |
CATEGORY_TIME | 'time' | yii\db\ColumnSchemaBuilder |
プロパティの詳細
メソッドの詳細
定義場所: yii\base\BaseObject::__call()
クラスメソッドではない名前付きメソッドを呼び出します。
これはPHPのマジックメソッドであり、未知のメソッドが呼び出された際に暗黙的に呼び出されるため、直接呼び出さないでください。
public mixed __call ( $name, $params ) | ||
$name | string |
メソッド名 |
$params | array |
メソッドパラメータ |
戻り値 | mixed |
メソッドの戻り値 |
---|---|---|
例外 | yii\base\UnknownMethodException |
未知のメソッドを呼び出した場合 |
public function __call($name, $params)
{
throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
}
定義場所: yii\db\ColumnSchemaBuilder::__construct()
型と値の精度を指定して、列スキーマビルダーインスタンスを作成します。
public void __construct ( $type, $length = null, $db = null, $config = [] ) | ||
$type | string |
列の種類。 $typeを参照してください。 |
$length | integer|string|array|null |
列の長さまたは精度。 $lengthを参照してください。 |
$db | yii\db\Connection|null |
現在のデータベース接続。 $dbを参照してください。 |
$config | array |
オブジェクトのプロパティを初期化するために使用される名前と値のペア |
public function __construct($type, $length = null, $db = null, $config = [])
{
$this->type = $type;
$this->length = $length;
$this->db = $db;
parent::__construct($config);
}
定義場所: yii\base\BaseObject::__get()
オブジェクトプロパティの値を返します。
これはPHPのマジックメソッドであり、`$value = $object->property;`を実行した際に暗黙的に呼び出されるため、直接呼び出さないでください。
__set()も参照してください。
public mixed __get ( $name ) | ||
$name | string |
プロパティ名 |
戻り値 | mixed |
プロパティ値 |
---|---|---|
例外 | yii\base\UnknownPropertyException |
プロパティが定義されていない場合 |
例外 | yii\base\InvalidCallException |
プロパティが書き込み専用の場合 |
public function __get($name)
{
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
return $this->$getter();
} elseif (method_exists($this, 'set' . $name)) {
throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
}
throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
}
定義場所: yii\base\BaseObject::__isset()
プロパティが設定されているかどうか(定義されていてNULLでない)を確認します。
これはPHPのマジックメソッドであり、`isset($object->property)`を実行した際に暗黙的に呼び出されるため、直接呼び出さないでください。
プロパティが定義されていない場合、falseが返されることに注意してください。
public boolean __isset ( $name ) | ||
$name | string |
プロパティ名またはイベント名 |
戻り値 | boolean |
指定されたプロパティが設定されているかどうか(NULLではないか)。 |
---|
public function __isset($name)
{
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
return $this->$getter() !== null;
}
return false;
}
定義場所: yii\base\BaseObject::__set()
オブジェクトプロパティの値を設定します。
これはPHPのマジックメソッドであり、`$object->property = $value;`を実行した際に暗黙的に呼び出されるため、直接呼び出さないでください。
__get()も参照してください。
public void __set ( $name, $value ) | ||
$name | string |
プロパティ名またはイベント名 |
$value | mixed |
プロパティ値 |
例外 | yii\base\UnknownPropertyException |
プロパティが定義されていない場合 |
---|---|---|
例外 | yii\base\InvalidCallException |
プロパティが読み取り専用の場合 |
public function __set($name, $value)
{
$setter = 'set' . $name;
if (method_exists($this, $setter)) {
$this->$setter($value);
} elseif (method_exists($this, 'get' . $name)) {
throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
} else {
throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
}
}
列のスキーマの完全な文字列を構築します。
public string __toString ( ) |
public function __toString()
{
if ($this->getTypeCategory() === self::CATEGORY_PK) {
$format = '{type}{check}{comment}{append}';
} else {
$format = $this->format;
}
return $this->buildCompleteString($format);
}
定義場所: yii\base\BaseObject::__unset()
オブジェクトプロパティをNULLに設定します。
これはPHPのマジックメソッドであり、`unset($object->property)`を実行した際に暗黙的に呼び出されるため、直接呼び出さないでください。
プロパティが定義されていない場合、このメソッドは何もしません。プロパティが読み取り専用の場合、例外をスローします。
public void __unset ( $name ) | ||
$name | string |
プロパティ名 |
例外 | yii\base\InvalidCallException |
プロパティが読み取り専用の場合。 |
---|
public function __unset($name)
{
$setter = 'set' . $name;
if (method_exists($this, $setter)) {
$this->$setter(null);
} elseif (method_exists($this, 'get' . $name)) {
throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '::' . $name);
}
}
public $this after ( $after ) | ||
$after | string |
このカラムを追加する先のカラム。 |
public function after($after)
{
$this->after = $after;
return $this;
}
定義場所: yii\db\ColumnSchemaBuilder::append()
列定義に付加する追加のSQLを指定します。
位置修飾子は、それらをサポートするデータベースではカラム定義の後に追加されます。
public $this append ( $sql ) | ||
$sql | string |
追加するSQL文字列。 |
public function append($sql)
{
$this->append = $sql;
return $this;
}
定義場所: yii\db\ColumnSchemaBuilder::buildAfterString()
列のafter制約を構築します。デフォルトではサポートされていません。
protected string buildAfterString ( ) | ||
戻り値 | string |
AFTER制約を含む文字列。 |
---|
protected function buildAfterString()
{
return '';
}
定義場所: yii\db\ColumnSchemaBuilder::buildAppendString()
列定義に付加されるカスタム文字列を構築します。
protected string buildAppendString ( ) | ||
戻り値 | string |
追加するカスタム文字列。 |
---|
protected function buildAppendString()
{
return $this->append !== null ? ' ' . $this->append : '';
}
定義場所: yii\db\ColumnSchemaBuilder::buildCheckString()
列のcheck制約を構築します。
protected string buildCheckString ( ) | ||
戻り値 | string |
CHECK制約を含む文字列。 |
---|
protected function buildCheckString()
{
return $this->check !== null ? " CHECK ({$this->check})" : '';
}
定義場所: yii\db\ColumnSchemaBuilder::buildCommentString()
列のコメント仕様を構築します。
protected string buildCommentString ( ) | ||
戻り値 | string |
COMMENTキーワードとコメント自体を含む文字列。 |
---|
protected function buildCommentString()
{
return '';
}
定義場所: yii\db\ColumnSchemaBuilder::buildCompleteString()
入力形式から完全な列定義を返します。
protected string buildCompleteString ( $format ) | ||
$format | string |
定義のフォーマット。 |
戻り値 | string |
完全なカラム定義を含む文字列。 |
---|
protected function buildCompleteString($format)
{
$placeholderValues = [
'{type}' => $this->type,
'{length}' => $this->buildLengthString(),
'{unsigned}' => $this->buildUnsignedString(),
'{notnull}' => $this->buildNotNullString(),
'{unique}' => $this->buildUniqueString(),
'{default}' => $this->buildDefaultString(),
'{check}' => $this->buildCheckString(),
'{comment}' => $this->buildCommentString(),
'{pos}' => $this->isFirst ? $this->buildFirstString() : $this->buildAfterString(),
'{append}' => $this->buildAppendString(),
];
return strtr($format, $placeholderValues);
}
定義場所: yii\db\ColumnSchemaBuilder::buildDefaultString()
列のデフォルト値仕様を構築します。
protected string buildDefaultString ( ) | ||
戻り値 | string |
カラムのデフォルト値を含む文字列。 |
---|
protected function buildDefaultString()
{
$defaultValue = $this->buildDefaultValue();
if ($defaultValue === null) {
return '';
}
return ' DEFAULT ' . $defaultValue;
}
定義場所: yii\db\ColumnSchemaBuilder::buildDefaultValue()
列のデフォルト値を返します。
protected string|null buildDefaultValue ( ) | ||
戻り値 | string|null |
カラムのデフォルト値を含む文字列。 |
---|
protected function buildDefaultValue()
{
if ($this->default === null) {
return $this->isNotNull === false ? 'NULL' : null;
}
switch (gettype($this->default)) {
case 'double':
// ensure type cast always has . as decimal separator in all locales
$defaultValue = StringHelper::floatToString($this->default);
break;
case 'boolean':
$defaultValue = $this->default ? 'TRUE' : 'FALSE';
break;
case 'integer':
case 'object':
$defaultValue = (string) $this->default;
break;
default:
$defaultValue = "'{$this->default}'";
}
return $defaultValue;
}
定義場所: yii\db\ColumnSchemaBuilder::buildFirstString()
列の最初の制約を構築します。デフォルトではサポートされていません。
protected string buildFirstString ( ) | ||
戻り値 | string |
FIRST制約を含む文字列。 |
---|
protected function buildFirstString()
{
return '';
}
定義場所: yii\db\ColumnSchemaBuilder::buildLengthString()
列の長さ/精度部分を構築します。
protected string buildLengthString ( ) |
protected function buildLengthString()
{
if ($this->length === null || $this->length === []) {
return '';
}
if (is_array($this->length)) {
$this->length = implode(',', $this->length);
}
return "({$this->length})";
}
定義場所: yii\db\ColumnSchemaBuilder::buildNotNullString()
列のNOT NULL制約を構築します。
protected string buildNotNullString ( ) | ||
戻り値 | string |
$isNotNull がtrueの場合'NOT NULL'を返し、$isNotNull がfalseの場合'NULL'を返し、それ以外の場合は空文字列を返します。 |
---|
protected function buildNotNullString()
{
if ($this->isNotNull === true) {
return ' NOT NULL';
} elseif ($this->isNotNull === false) {
return ' NULL';
}
return '';
}
定義されている場所: yii\db\ColumnSchemaBuilder::buildUniqueString()
列の一意制約を構築します。
protected string buildUniqueString ( ) | ||
戻り値 | string |
$isUnique が true の場合、文字列 'UNIQUE' を返し、それ以外の場合は空文字列を返します。 |
---|
protected function buildUniqueString()
{
return $this->isUnique ? ' UNIQUE' : '';
}
定義されている場所: yii\db\ColumnSchemaBuilder::buildUnsignedString()
列のunsigned文字列を構築します。デフォルトではサポートされていません。
protected string buildUnsignedString ( ) | ||
戻り値 | string |
UNSIGNED キーワードを含む文字列。 |
---|
protected function buildUnsignedString()
{
return '';
}
定義されている場所: yii\base\BaseObject::canGetProperty()
プロパティを読み取ることができるかどうかを示す値を返します。
プロパティは、以下の場合に読み取り可能です。
- クラスが指定された名前と関連付けられたゲッターメソッドを持っている場合(この場合、プロパティ名はケースインセンシティブです)。
- クラスが指定された名前のメンバ変数を持っている場合(
$checkVars
が true の場合)。
こちらも参照してください canSetProperty().
public boolean canGetProperty ( $name, $checkVars = true ) | ||
$name | string |
プロパティ名 |
$checkVars | boolean |
メンバ変数をプロパティとして扱うかどうか |
戻り値 | boolean |
プロパティを読み取ることができるかどうか |
---|
public function canGetProperty($name, $checkVars = true)
{
return method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name);
}
定義されている場所: yii\base\BaseObject::canSetProperty()
プロパティを設定できるかどうかを示す値を返します。
プロパティは、以下の場合に書き込み可能です。
- クラスが指定された名前と関連付けられたセッターメソッドを持っている場合(この場合、プロパティ名はケースインセンシティブです)。
- クラスが指定された名前のメンバ変数を持っている場合(
$checkVars
が true の場合)。
こちらも参照してください canGetProperty().
public boolean canSetProperty ( $name, $checkVars = true ) | ||
$name | string |
プロパティ名 |
$checkVars | boolean |
メンバ変数をプロパティとして扱うかどうか |
戻り値 | boolean |
プロパティを書き込むことができるかどうか |
---|
public function canSetProperty($name, $checkVars = true)
{
return method_exists($this, 'set' . $name) || $checkVars && property_exists($this, $name);
}
定義されている場所: yii\db\ColumnSchemaBuilder::check()
列のCHECK
制約を設定します。
public $this check ( $check ) | ||
$check | string |
追加する |
public function check($check)
{
$this->check = $check;
return $this;
}
::class
を使用してください。
定義されている場所: yii\base\BaseObject::className()
このクラスの完全修飾名を返します。
public static string className ( ) | ||
戻り値 | string |
このクラスの完全修飾名。 |
---|
public static function className()
{
return get_called_class();
}
定義されている場所: yii\db\ColumnSchemaBuilder::comment()
列のコメントを指定します。
public $this comment ( $comment ) | ||
$comment | string |
コメント |
public function comment($comment)
{
$this->comment = $comment;
return $this;
}
定義されている場所: yii\db\ColumnSchemaBuilder::defaultExpression()
列のデフォルトSQL式を指定します。
public $this defaultExpression ( $default ) | ||
$default | string |
デフォルト値の式。 |
public function defaultExpression($default)
{
$this->default = new Expression($default);
return $this;
}
定義されている場所: yii\db\ColumnSchemaBuilder::defaultValue()
列のデフォルト値を指定します。
public $this defaultValue ( $default ) | ||
$default | mixed |
デフォルト値。 |
public function defaultValue($default)
{
if ($default === null) {
$this->null();
}
$this->default = $default;
return $this;
}
定義されている場所: yii\db\ColumnSchemaBuilder::getCategoryMap()
public array getCategoryMap ( ) | ||
戻り値 | array |
抽象的な列の種類(キー)から種類カテゴリ(値)へのマッピング。 |
---|
public function getCategoryMap()
{
return static::$typeCategoryMap;
}
制約のCheck
値を取得します。
public string|null getCheckValue ( ) | ||
戻り値 | string|null |
列の |
---|
public function getCheckValue()
{
return $this->check !== null ? (string) $this->check : null;
}
制約のDefault
値を取得します。
public string|yii\db\Expression|null getDefaultValue ( ) | ||
戻り値 | string|yii\db\Expression|null |
列のデフォルト値。 |
---|
public function getDefaultValue()
{
if ($this->default instanceof Expression) {
return $this->default;
}
return $this->buildDefaultValue();
}
定義先: yii\db\ColumnSchemaBuilder::getTypeCategory()
列の種類のカテゴリを返します。
protected string getTypeCategory ( ) | ||
戻り値 | string |
カラムの種類カテゴリ名を格納した文字列。 |
---|
protected function getTypeCategory()
{
return isset($this->categoryMap[$this->type]) ? $this->categoryMap[$this->type] : null;
}
定義先: yii\base\BaseObject::hasMethod()
メソッドが定義されているかどうかを示す値を返します。
デフォルトの実装は、PHP関数`method_exists()`の呼び出しです。PHPマジックメソッド`__call()`を実装した場合は、このメソッドをオーバーライドできます。
public boolean hasMethod ( $name ) | ||
$name | string |
メソッド名 |
戻り値 | boolean |
メソッドが定義されているかどうか |
---|
public function hasMethod($name)
{
return method_exists($this, $name);
}
定義先: yii\base\BaseObject::hasProperty()
プロパティが定義されているかどうかを示す値を返します。
プロパティは、以下の場合に定義されています。
- 指定された名前と関連付けられたゲッターまたはセッターメソッドがクラスに存在する場合(この場合、プロパティ名はケースインセンシティブです)。
- クラスが指定された名前のメンバ変数を持っている場合(
$checkVars
が true の場合)。
参照
public boolean hasProperty ( $name, $checkVars = true ) | ||
$name | string |
プロパティ名 |
$checkVars | boolean |
メンバ変数をプロパティとして扱うかどうか |
戻り値 | boolean |
プロパティが定義されているかどうか |
---|
public function hasProperty($name, $checkVars = true)
{
return $this->canGetProperty($name, $checkVars) || $this->canSetProperty($name, false);
}
public void init ( ) |
public function init()
{
}
public boolean isUnique ( ) | ||
戻り値 | boolean |
カラムの値が一意である必要があるかどうか。これが`true`の場合、`UNIQUE`制約が追加されます。 |
---|
public function isUnique()
{
return $this->isUnique;
}
定義先: yii\db\ColumnSchemaBuilder::notNull()
列にNOT NULL
制約を追加します。
public $this notNull ( ) |
public function notNull()
{
$this->isNotNull = true;
return $this;
}
定義先: yii\db\ColumnSchemaBuilder::null()
列にNULL
制約を追加します。
public $this null ( ) |
public function null()
{
$this->isNotNull = false;
return $this;
}
デフォルトのフォーマット文字列をMSSQL ALTERコマンドに変更します。
public void setAlterColumnFormat ( ) |
public function setAlterColumnFormat()
{
$this->format = '{type}{length}{notnull}{append}';
}
public void setCategoryMap ( $categoryMap ) | ||
$categoryMap | array |
抽象的な列の種類(キー)から種類カテゴリ(値)へのマッピング。 |
public function setCategoryMap($categoryMap)
{
static::$typeCategoryMap = $categoryMap;
}
定義先: yii\db\ColumnSchemaBuilder::unique()
列にUNIQUE
制約を追加します。
public $this unique ( ) |
public function unique()
{
$this->isUnique = true;
return $this;
}
定義先: yii\db\ColumnSchemaBuilder::unsigned()
列を符号なしとしてマークします。
public $this unsigned ( ) |
public function unsigned()
{
switch ($this->type) {
case Schema::TYPE_PK:
$this->type = Schema::TYPE_UPK;
break;
case Schema::TYPE_BIGPK:
$this->type = Schema::TYPE_UBIGPK;
break;
}
$this->isUnsigned = true;
return $this;
}
コメントするにはサインアップまたはログインしてください。