クラス yii\db\mysql\ColumnSchemaBuilder
ColumnSchemaBuilder は、MySQL データベース用のスキーマビルダーです。
公開プロパティ
プロパティ | 型 | 説明 | 定義元 |
---|---|---|---|
$after | string | この列の後に追加される列。 | yii\db\ColumnSchemaBuilder |
$append | mixed | 列スキーマ定義に追加されるSQL文字列。 | yii\db\ColumnSchemaBuilder |
$categoryMap | array | 抽象的な列の種類(キー)と種類カテゴリ(値)のマッピング。 | yii\db\ColumnSchemaBuilder |
$check | string | 列のCHECK 制約。 |
yii\db\ColumnSchemaBuilder |
$comment | string | 列のコメント値。 | yii\db\ColumnSchemaBuilder |
$db | yii\db\Connection | 現在のデータベース接続。 | yii\db\ColumnSchemaBuilder |
$default | mixed | 列のデフォルト値。 | yii\db\ColumnSchemaBuilder |
$isFirst | boolean | この列をテーブルの先頭に挿入するかどうか。 | yii\db\ColumnSchemaBuilder |
$isNotNull | boolean|null | 列がNULL可能かどうか。 | yii\db\ColumnSchemaBuilder |
$isUnique | boolean | 列の値を一意にするかどうか。 | yii\db\ColumnSchemaBuilder |
$isUnsigned | boolean | 列の値を符号なしにするかどうか。 | yii\db\ColumnSchemaBuilder |
$length | integer|string|array | 列のサイズまたは精度の定義。 | yii\db\ColumnSchemaBuilder |
$type | string | 列の種類定義(INTEGER、VARCHAR、DATETIMEなど)。 | yii\db\ColumnSchemaBuilder |
$typeCategoryMap | array | 抽象的な列の種類(キー)と種類カテゴリ(値)のマッピング。 | yii\db\ColumnSchemaBuilder |
公開メソッド
保護されたメソッド
メソッド | 説明 | 定義元 |
---|---|---|
buildAfterString() | 列のAFTER制約を構築します。デフォルトではサポートされていません。 | yii\db\mysql\ColumnSchemaBuilder |
buildAppendString() | 列定義に追加されるカスタム文字列を構築します。 | yii\db\ColumnSchemaBuilder |
buildCheckString() | 列のCHECK制約を構築します。 | yii\db\ColumnSchemaBuilder |
buildCommentString() | 列のコメント仕様を構築します。 | yii\db\mysql\ColumnSchemaBuilder |
buildCompleteString() | 入力形式から完全な列定義を返します。 | yii\db\ColumnSchemaBuilder |
buildDefaultString() | 列のデフォルト値の仕様を構築します。 | yii\db\ColumnSchemaBuilder |
buildDefaultValue() | 列のデフォルト値を返します。 | yii\db\ColumnSchemaBuilder |
buildFirstString() | 列のFIRST制約を構築します。デフォルトではサポートされていません。 | yii\db\mysql\ColumnSchemaBuilder |
buildLengthString() | 列の長さ/精度の部分を構築します。 | yii\db\ColumnSchemaBuilder |
buildNotNullString() | 列のNOT NULL制約を構築します。 | yii\db\ColumnSchemaBuilder |
buildUniqueString() | 列の一意性制約を構築します。 | yii\db\ColumnSchemaBuilder |
buildUnsignedString() | 列の符号なし文字列を構築します。デフォルトではサポートされていません。 | yii\db\mysql\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()
{
switch ($this->getTypeCategory()) {
case self::CATEGORY_PK:
$format = '{type}{length}{comment}{check}{append}{pos}';
break;
case self::CATEGORY_NUMERIC:
$format = '{type}{length}{unsigned}{notnull}{default}{unique}{comment}{append}{pos}{check}';
break;
default:
$format = '{type}{length}{notnull}{default}{unique}{comment}{append}{pos}{check}';
}
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;
}
列のAFTER制約を構築します。デフォルトではサポートされていません。
protected string buildAfterString ( ) | ||
戻り値 | string |
AFTER制約を含む文字列。 |
---|
protected function buildAfterString()
{
return $this->after !== null ?
' AFTER ' . $this->db->quoteColumnName($this->after) :
'';
}
定義位置: 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})" : '';
}
列のコメント仕様を構築します。
protected string buildCommentString ( ) | ||
戻り値 | string |
COMMENTキーワードとコメントそのものを含む文字列。 |
---|
protected function buildCommentString()
{
return $this->comment !== null ? ' COMMENT ' . $this->db->quoteValue($this->comment) : '';
}
定義位置: 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;
}
列のFIRST制約を構築します。デフォルトではサポートされていません。
protected string buildFirstString ( ) | ||
戻り値 | string |
FIRST制約を含む文字列。 |
---|
protected function buildFirstString()
{
return $this->isFirst ? ' FIRST' : '';
}
定義位置: 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' : '';
}
列の符号なし文字列を構築します。デフォルトではサポートされていません。
protected string buildUnsignedString ( ) | ||
戻り値 | string |
UNSIGNEDキーワードを含む文字列。 |
---|
protected function buildUnsignedString()
{
return $this->isUnsigned ? ' UNSIGNED' : '';
}
定義位置: 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;
}
public array getCategoryMap ( ) | ||
戻り値 | array |
抽象的な列の種類(キー)と種類カテゴリ(値)のマッピング。 |
---|
public function getCategoryMap()
{
return static::$typeCategoryMap;
}
定義位置: 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()
{
}
定義位置: 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;
}
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;
}
サインアップ または ログイン してコメントしてください。