0 關注者

類別 yii\db\cubrid\ColumnSchemaBuilder

繼承關係yii\db\cubrid\ColumnSchemaBuilder » yii\db\ColumnSchemaBuilder » yii\base\BaseObject
實作介面yii\base\Configurable
起始版本2.0.8
原始碼 https://github.com/yiisoft/yii2/blob/master/framework/db/cubrid/ColumnSchemaBuilder.php

ColumnSchemaBuilder 是 Cubrid 資料庫的 Schema 建構器。

公共屬性

隱藏繼承的屬性

屬性 類型 描述 定義於
$after string 此欄位將被新增在其後的欄位。 yii\db\ColumnSchemaBuilder
$append mixed 要附加到欄位 schema 定義的 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 欄位是否可為空值。 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

受保護的屬性

隱藏繼承的屬性

屬性 類型 描述 定義於

公共方法

隱藏繼承的方法

方法 描述 定義於
__call() 呼叫未定義為類別方法的具名方法。 yii\base\BaseObject
__construct() 建立欄位 schema 建構器實例,並指定類型和值精確度。 yii\db\ColumnSchemaBuilder
__get() 傳回物件屬性的值。 yii\base\BaseObject
__isset() 檢查屬性是否已設定,即已定義且非空值。 yii\base\BaseObject
__set() 設定物件屬性的值。 yii\base\BaseObject
__toString() 為欄位的 schema 建構完整字串。 yii\db\cubrid\ColumnSchemaBuilder
__unset() 將物件屬性設定為 null。 yii\base\BaseObject
after() 為欄位新增 AFTER 约束。 yii\db\ColumnSchemaBuilder
append() 指定要附加到欄位定義的額外 SQL。 yii\db\ColumnSchemaBuilder
canGetProperty() 傳回值,指出屬性是否可讀取。 yii\base\BaseObject
canSetProperty() 傳回值,指出屬性是否可設定。 yii\base\BaseObject
check() 為欄位設定 CHECK 约束。 yii\db\ColumnSchemaBuilder
className() 傳回此類別的完整限定名稱。 yii\base\BaseObject
comment() 指定欄位的註解。 yii\db\ColumnSchemaBuilder
defaultExpression() 為欄位指定預設 SQL 表達式。 yii\db\ColumnSchemaBuilder
defaultValue() 為欄位指定預設值。 yii\db\ColumnSchemaBuilder
first() 為欄位新增 FIRST 约束。 yii\db\ColumnSchemaBuilder
getCategoryMap() yii\db\ColumnSchemaBuilder
hasMethod() 傳回值,指出是否已定義方法。 yii\base\BaseObject
hasProperty() 傳回值,指出是否已定義屬性。 yii\base\BaseObject
init() 初始化物件。 yii\base\BaseObject
notNull() 為欄位新增 NOT NULL 约束。 yii\db\ColumnSchemaBuilder
null() 為欄位新增 NULL 约束。 yii\db\ColumnSchemaBuilder
setCategoryMap() yii\db\ColumnSchemaBuilder
unique() 為欄位新增 UNIQUE 约束。 yii\db\ColumnSchemaBuilder
unsigned() 將欄位標記為無號。 yii\db\ColumnSchemaBuilder

受保護的方法

隱藏繼承的方法

方法 描述 定義於
buildAfterString() 為欄位建構 after 约束字串。預設為不支援。 yii\db\cubrid\ColumnSchemaBuilder
buildAppendString() 建構附加到欄位定義的自訂字串。 yii\db\ColumnSchemaBuilder
buildCheckString() 為欄位建構 check 约束。 yii\db\ColumnSchemaBuilder
buildCommentString() 為欄位建構註解規範。 yii\db\cubrid\ColumnSchemaBuilder
buildCompleteString() 從輸入格式傳回完整的欄位定義。 yii\db\ColumnSchemaBuilder
buildDefaultString() 為欄位建構預設值規範。 yii\db\ColumnSchemaBuilder
buildDefaultValue() 傳回欄位的預設值。 yii\db\ColumnSchemaBuilder
buildFirstString() 為欄位建構 first 约束字串。預設為不支援。 yii\db\cubrid\ColumnSchemaBuilder
buildLengthString() 建構欄位的長度/精確度部分。 yii\db\ColumnSchemaBuilder
buildNotNullString() 為欄位建構 not null 约束。 yii\db\ColumnSchemaBuilder
buildUniqueString() 為欄位建構 unique 约束。 yii\db\ColumnSchemaBuilder
buildUnsignedString() 為欄位建構 unsigned 字串。預設為不支援。 yii\db\cubrid\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

方法詳情

隱藏繼承的方法

__call() 公共方法

定義於: yii\base\BaseObject::__call()

呼叫未定義為類別方法的具名方法。

請勿直接呼叫此方法,因為它是 PHP 魔術方法,將在呼叫未知方法時隱式呼叫。

public mixed __call ( $name, $params )
$name string

方法名稱

$params array

方法參數

return mixed

方法傳回值

throws yii\base\UnknownMethodException

當呼叫不明方法時

                public function __call($name, $params)
{
    throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
}

            
__construct() 公開方法

定義於: yii\db\ColumnSchemaBuilder::__construct()

建立欄位 schema 建構器實例,並指定類型和值精確度。

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);
}

            
__get() 公開方法

定義於: yii\base\BaseObject::__get()

傳回物件屬性的值。

請勿直接呼叫此方法,因為它是一個 PHP 魔術方法,當執行 $value = $object->property; 時會被隱式呼叫。

另請參閱 __set()

public mixed __get ( $name )
$name string

屬性名稱

return mixed

屬性值

throws yii\base\UnknownPropertyException

如果屬性未定義

throws 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);
}

            
__isset() 公開方法

定義於: yii\base\BaseObject::__isset()

檢查屬性是否已設定,即已定義且非空值。

請勿直接呼叫此方法,因為它是一個 PHP 魔術方法,當執行 isset($object->property) 時會被隱式呼叫。

請注意,如果屬性未定義,將會回傳 false。

另請參閱 https://php.dev.org.tw/manual/en/function.isset.php

public boolean __isset ( $name )
$name string

屬性名稱或事件名稱

return boolean

具名的屬性是否已設定 (非 null)。

                public function __isset($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        return $this->$getter() !== null;
    }
    return false;
}

            
__set() 公開方法

定義於: yii\base\BaseObject::__set()

設定物件屬性的值。

請勿直接呼叫此方法,因為它是一個 PHP 魔術方法,當執行 $object->property = $value; 時會被隱式呼叫。

另請參閱 __get()

public void __set ( $name, $value )
$name string

屬性名稱或事件名稱

$value mixed

屬性值

throws yii\base\UnknownPropertyException

如果屬性未定義

throws 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);
    }
}

            
__toString() 公開方法

為欄位的 schema 建構完整字串。

public string __toString ( )

                public function __toString()
{
    switch ($this->getTypeCategory()) {
        case self::CATEGORY_PK:
            $format = '{type}{check}{comment}{append}{pos}';
            break;
        case self::CATEGORY_NUMERIC:
            $format = '{type}{length}{unsigned}{notnull}{unique}{default}{check}{comment}{append}{pos}';
            break;
        default:
            $format = '{type}{length}{notnull}{unique}{default}{check}{comment}{append}{pos}';
    }
    return $this->buildCompleteString($format);
}

            
__unset() 公開方法

定義於: yii\base\BaseObject::__unset()

將物件屬性設定為 null。

請勿直接呼叫此方法,因為它是一個 PHP 魔術方法,當執行 unset($object->property) 時會被隱式呼叫。

請注意,如果屬性未定義,此方法將不會執行任何操作。如果屬性為唯讀,則會拋出例外。

另請參閱 https://php.dev.org.tw/manual/en/function.unset.php

public void __unset ( $name )
$name string

屬性名稱

throws 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);
    }
}

            
after() 公開方法 (自版本 2.0.8 起可用)

定義於: yii\db\ColumnSchemaBuilder::after()

為欄位新增 AFTER 约束。

請注意:僅支援 MySQL、Oracle 和 Cubrid。

public $this after ( $after )
$after string

將在此欄位之後新增 $this 欄位。

                public function after($after)
{
    $this->after = $after;
    return $this;
}

            
append() 公開方法 (自版本 2.0.9 起可用)

定義於: yii\db\ColumnSchemaBuilder::append()

指定要附加到欄位定義的額外 SQL。

位置修飾符將在支援它們的資料庫中,附加在欄位定義之後。

public $this append ( $sql )
$sql string

要附加的 SQL 字串。

                public function append($sql)
{
    $this->append = $sql;
    return $this;
}

            
buildAfterString() 受保護方法 (自版本 2.0.8 起可用)

為欄位建構 after 约束字串。預設為不支援。

protected string buildAfterString ( )
return string

包含 AFTER 限制的字串。

                protected function buildAfterString()
{
    return $this->after !== null ?
        ' AFTER ' . $this->db->quoteColumnName($this->after) :
        '';
}

            
buildAppendString() 受保護方法 (自版本 2.0.9 起可用)

定義於: yii\db\ColumnSchemaBuilder::buildAppendString()

建構附加到欄位定義的自訂字串。

protected string buildAppendString ( )
return string

要附加的自訂字串。

                protected function buildAppendString()
{
    return $this->append !== null ? ' ' . $this->append : '';
}

            
buildCheckString() 受保護方法

定義於: yii\db\ColumnSchemaBuilder::buildCheckString()

為欄位建構 check 约束。

protected string buildCheckString ( )
return string

包含 CHECK 限制的字串。

                protected function buildCheckString()
{
    return $this->check !== null ? " CHECK ({$this->check})" : '';
}

            
buildCommentString() 受保護方法 (自版本 2.0.8 起可用)

為欄位建構註解規範。

protected string buildCommentString ( )
return string

包含 COMMENT 關鍵字和註解本身的字串

                protected function buildCommentString()
{
    return $this->comment !== null ? ' COMMENT ' . $this->db->quoteValue($this->comment) : '';
}

            
buildCompleteString() 受保護方法 (自版本 2.0.8 起可用)

定義於: yii\db\ColumnSchemaBuilder::buildCompleteString()

從輸入格式傳回完整的欄位定義。

protected string buildCompleteString ( $format )
$format string

定義的格式。

return 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);
}

            
buildDefaultString() 受保護方法

定義於: yii\db\ColumnSchemaBuilder::buildDefaultString()

為欄位建構預設值規範。

protected string buildDefaultString ( )
return string

具有欄位預設值的字串。

                protected function buildDefaultString()
{
    $defaultValue = $this->buildDefaultValue();
    if ($defaultValue === null) {
        return '';
    }
    return ' DEFAULT ' . $defaultValue;
}

            
buildDefaultValue() 受保護方法

定義於: yii\db\ColumnSchemaBuilder::buildDefaultValue()

傳回欄位的預設值。

protected string|null buildDefaultValue ( )
return 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;
}

            
buildFirstString() 受保護方法 (自版本 2.0.8 起可用)

為欄位建構 first 约束字串。預設為不支援。

protected string buildFirstString ( )
return string

包含 FIRST 限制的字串。

                protected function buildFirstString()
{
    return $this->isFirst ? ' FIRST' : '';
}

            
buildLengthString() 受保護方法

定義於: 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})";
}

            
buildNotNullString() 受保護方法

定義於: yii\db\ColumnSchemaBuilder::buildNotNullString()

為欄位建構 not null 约束。

protected string buildNotNullString ( )
return 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 '';
}

            
buildUniqueString() 受保護方法

定義於: yii\db\ColumnSchemaBuilder::buildUniqueString()

為欄位建構 unique 约束。

protected string buildUniqueString ( )
return string

如果 $isUnique 為 true,則回傳字串 'UNIQUE',否則回傳空字串。

                protected function buildUniqueString()
{
    return $this->isUnique ? ' UNIQUE' : '';
}

            
buildUnsignedString() 受保護方法 (自版本 2.0.7 起可用)

為欄位建構 unsigned 字串。預設為不支援。

protected string buildUnsignedString ( )
return string

包含 UNSIGNED 關鍵字的字串。

                protected function buildUnsignedString()
{
    return $this->isUnsigned ? ' UNSIGNED' : '';
}

            
canGetProperty() 公開方法

定義於: yii\base\BaseObject::canGetProperty()

傳回值,指出屬性是否可讀取。

如果符合以下條件,屬性為可讀:

  • 類別具有與指定名稱相關聯的 getter 方法 (在這種情況下,屬性名稱不區分大小寫);
  • 類別具有具有指定名稱的成員變數 (當 $checkVars 為 true 時);

另請參閱 canSetProperty()

public boolean canGetProperty ( $name, $checkVars true )
$name string

屬性名稱

$checkVars boolean

是否將成員變數視為屬性

return boolean

屬性是否可讀

                public function canGetProperty($name, $checkVars = true)
{
    return method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name);
}

            
canSetProperty() 公開方法

定義於: yii\base\BaseObject::canSetProperty()

傳回值,指出屬性是否可設定。

如果符合以下條件,屬性為可寫:

  • 類別具有與指定名稱相關聯的 setter 方法 (在這種情況下,屬性名稱不區分大小寫);
  • 類別具有具有指定名稱的成員變數 (當 $checkVars 為 true 時);

另請參閱 canGetProperty()

public boolean canSetProperty ( $name, $checkVars true )
$name string

屬性名稱

$checkVars boolean

是否將成員變數視為屬性

return boolean

屬性是否可寫

                public function canSetProperty($name, $checkVars = true)
{
    return method_exists($this, 'set' . $name) || $checkVars && property_exists($this, $name);
}

            
check() 公開方法

定義於: yii\db\ColumnSchemaBuilder::check()

為欄位設定 CHECK 约束。

public $this check ( $check )
$check string

要新增的 CHECK 限制的 SQL。

                public function check($check)
{
    $this->check = $check;
    return $this;
}

            
className() 公開靜態方法
自 2.0.14 版本起已棄用。在 PHP >=5.5 上,請改用 ::class

定義於: yii\base\BaseObject::className()

傳回此類別的完整限定名稱。

public static string className ( )
return string

此類別的完整限定名稱。

                public static function className()
{
    return get_called_class();
}

            
comment() 公開方法 (自版本 2.0.8 起可用)

定義於: yii\db\ColumnSchemaBuilder::comment()

指定欄位的註解。

public $this comment ( $comment )
$comment string

註解

                public function comment($comment)
{
    $this->comment = $comment;
    return $this;
}

            
defaultExpression() 公開方法 (自版本 2.0.7 起可用)

定義於: yii\db\ColumnSchemaBuilder::defaultExpression()

為欄位指定預設 SQL 表達式。

public $this defaultExpression ( $default )
$default string

預設值運算式。

                public function defaultExpression($default)
{
    $this->default = new Expression($default);
    return $this;
}

            
defaultValue() 公開方法

定義於: yii\db\ColumnSchemaBuilder::defaultValue()

為欄位指定預設值。

public $this defaultValue ( $default )
$default mixed

預設值。

                public function defaultValue($default)
{
    if ($default === null) {
        $this->null();
    }
    $this->default = $default;
    return $this;
}

            
first() 公開方法 (自版本 2.0.8 起可用)

定義於: yii\db\ColumnSchemaBuilder::first()

為欄位新增 FIRST 约束。

請注意:僅支援 MySQL、Oracle 和 Cubrid。

public $this first ( )

                public function first()
{
    $this->isFirst = true;
    return $this;
}

            
getCategoryMap() 公開方法 (自版本 2.0.43 起可用)
public array getCategoryMap ( )
return array

抽象欄位類型 (鍵) 到類型類別 (值) 的映射。

                public function getCategoryMap()
{
    return static::$typeCategoryMap;
}

            
getTypeCategory() 受保護方法 (自版本 2.0.8 起可用)

定義於: yii\db\ColumnSchemaBuilder::getTypeCategory()

傳回欄位類型的類別。

protected string getTypeCategory ( )
return string

包含欄位類型類別名稱的字串。

                protected function getTypeCategory()
{
    return isset($this->categoryMap[$this->type]) ? $this->categoryMap[$this->type] : null;
}

            
hasMethod() 公開方法

定義於: yii\base\BaseObject::hasMethod()

傳回值,指出是否已定義方法。

預設實作是對 php 函數 method_exists() 的呼叫。當您實作了 php 魔術方法 __call() 時,您可以覆寫此方法。

public boolean hasMethod ( $name )
$name string

方法名稱

return boolean

方法是否已定義

                public function hasMethod($name)
{
    return method_exists($this, $name);
}

            
hasProperty() 公開方法

定義於: yii\base\BaseObject::hasProperty()

傳回值,指出是否已定義屬性。

如果符合以下條件,屬性已定義:

  • 類別具有與指定名稱相關聯的 getter 或 setter 方法 (在這種情況下,屬性名稱不區分大小寫);
  • 類別具有具有指定名稱的成員變數 (當 $checkVars 為 true 時);

另請參閱

public boolean hasProperty ( $name, $checkVars true )
$name string

屬性名稱

$checkVars boolean

是否將成員變數視為屬性

return boolean

屬性是否已定義

                public function hasProperty($name, $checkVars = true)
{
    return $this->canGetProperty($name, $checkVars) || $this->canSetProperty($name, false);
}

            
init() 公有方法

定義於: yii\base\BaseObject::init()

初始化物件。

此方法在建構子結束時被調用,在物件以給定的配置初始化之後。

public void init ( )

                public function init()
{
}

            
notNull() 公有方法

定義於: yii\db\ColumnSchemaBuilder::notNull()

為欄位新增 NOT NULL 约束。

public $this notNull ( )

                public function notNull()
{
    $this->isNotNull = true;
    return $this;
}

            
null() 公有方法 (自版本 2.0.9 起可用)

定義於: yii\db\ColumnSchemaBuilder::null()

為欄位新增 NULL 约束。

public $this null ( )

                public function null()
{
    $this->isNotNull = false;
    return $this;
}

            
setCategoryMap() 公有方法 (自版本 2.0.43 起可用)
public void setCategoryMap ( $categoryMap )
$categoryMap array

抽象欄位類型 (鍵) 到類型類別 (值) 的映射。

                public function setCategoryMap($categoryMap)
{
    static::$typeCategoryMap = $categoryMap;
}

            
unique() 公有方法

定義於: yii\db\ColumnSchemaBuilder::unique()

為欄位新增 UNIQUE 约束。

public $this unique ( )

                public function unique()
{
    $this->isUnique = true;
    return $this;
}

            
unsigned() 公有方法 (自版本 2.0.7 起可用)

定義於: 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;
}