0 追蹤者

類別 yii\db\mssql\ColumnSchema

繼承關係yii\db\mssql\ColumnSchema » yii\db\ColumnSchema » yii\base\BaseObject
實作yii\base\Configurable
自版本起可用2.0.23
原始碼 https://github.com/yiisoft/yii2/blob/master/framework/db/mssql/ColumnSchema.php

MSSQL 資料庫的 ColumnSchema 類別

公開屬性

隱藏繼承的屬性

屬性 類型 描述 定義於
$allowNull boolean 指出此欄位是否可為空值。 yii\db\ColumnSchema
$autoIncrement boolean 指出此欄位是否為自動遞增 yii\db\ColumnSchema
$comment string 此欄位的註解。 yii\db\ColumnSchema
$dbType string 此欄位的資料庫類型。 yii\db\ColumnSchema
$defaultValue mixed 此欄位的預設值 yii\db\ColumnSchema
$enumValues array 可列舉的值。 yii\db\ColumnSchema
$isComputed boolean 指出此欄位是否為計算欄位 yii\db\mssql\ColumnSchema
$isPrimaryKey boolean 指出此欄位是否為主鍵 yii\db\ColumnSchema
$name string 此欄位的名稱 (不含引號)。 yii\db\ColumnSchema
$phpType string 此欄位的 PHP 類型。 yii\db\ColumnSchema
$precision integer 欄位資料的精確度 (若為數值)。 yii\db\ColumnSchema
$scale integer 欄位資料的小數位數 (若為數值)。 yii\db\ColumnSchema
$size integer 欄位的顯示大小。 yii\db\ColumnSchema
$type string 此欄位的抽象類型。 yii\db\ColumnSchema
$unsigned boolean 指出此欄位是否為無號。 yii\db\ColumnSchema

公開方法

隱藏繼承的方法

方法 描述 定義於
__call() 呼叫指定的非類別方法。 yii\base\BaseObject
__construct() 建構子。 yii\base\BaseObject
__get() 傳回物件屬性的值。 yii\base\BaseObject
__isset() 檢查屬性是否已設定,即已定義且非空值。 yii\base\BaseObject
__set() 設定物件屬性的值。 yii\base\BaseObject
__unset() 將物件屬性設定為空值。 yii\base\BaseObject
canGetProperty() 傳回一個值,指出屬性是否可讀取。 yii\base\BaseObject
canSetProperty() 傳回一個值,指出屬性是否可設定。 yii\base\BaseObject
className() 傳回此類別的完整命名空間名稱。 yii\base\BaseObject
dbTypecast() 根據 $type$dbType 轉換輸入值,以便在資料庫查詢中使用。 yii\db\ColumnSchema
defaultPhpTypecast() 準備預設值並根據 $phpType 轉換。 yii\db\mssql\ColumnSchema
hasMethod() 傳回一個值,指出是否已定義方法。 yii\base\BaseObject
hasProperty() 傳回一個值,指出是否已定義屬性。 yii\base\BaseObject
init() 初始化物件。 yii\base\BaseObject
phpTypecast() 從資料庫檢索後,根據 $phpType 轉換輸入值。 yii\db\ColumnSchema

保護方法

隱藏繼承的方法

方法 描述 定義於
typecast() 從資料庫檢索後,根據 $phpType 轉換輸入值。 yii\db\ColumnSchema

屬性詳細資訊

隱藏繼承的屬性

$isComputed public property (available since version 2.0.39)

指出此欄位是否為計算欄位

public boolean $isComputed null

方法詳情

隱藏繼承的方法

__call() public method

定義於: 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() public method

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

建構子。

預設實作會做兩件事

  • 使用給定的組態 $config 初始化物件。
  • 呼叫 init()

如果這個方法在子類別中被覆寫,建議

  • 建構子的最後一個參數是一個組態陣列,就像這裡的 $config
  • 在建構子的結尾呼叫父類別的實作。
public void __construct ( $config = [] )
$config array

將用於初始化物件屬性的名稱-值對

                public function __construct($config = [])
{
    if (!empty($config)) {
        Yii::configure($this, $config);
    }
    $this->init();
}

            
__get() public method

定義於: 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() public method

定義於: 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() public method

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

            
__unset() public method

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

將物件屬性設定為空值。

請勿直接呼叫此方法,因為它是一個 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);
    }
}

            
canGetProperty() public method

定義於: 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() public method

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

            
className() public static method
自 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();
}

            
dbTypecast() public method

定義於: yii\db\ColumnSchema::dbTypecast()

根據 $type$dbType 轉換輸入值,以便在資料庫查詢中使用。

如果值為 null 或 yii\db\Expression,則不會轉換。

public mixed dbTypecast ( $value )
$value mixed

輸入值

return mixed

轉換後的值。這也可能是一個陣列,其中包含值作為第一個元素,PDO 類型作為第二個元素。

                public function dbTypecast($value)
{
    // the default implementation does the same as casting for PHP, but it should be possible
    // to override this with annotation of explicit PDO type.
    return $this->typecast($value);
}

            
defaultPhpTypecast() public method (available since version 2.0.24)

準備預設值並根據 $phpType 轉換。

public mixed defaultPhpTypecast ( $value )
$value mixed

預設值

return mixed

轉換後的值

                public function defaultPhpTypecast($value)
{
    if ($value !== null) {
        // convert from MSSQL column_default format, e.g. ('1') -> 1, ('string') -> string
        $value = substr(substr($value, 2), 0, -2);
    }
    return parent::phpTypecast($value);
}

            
hasMethod() public method

定義於: 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() public method

定義於: 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() public method

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

初始化物件。

在物件使用給定的組態初始化後,此方法會在建構子的結尾被調用。

public void init ( )

                public function init()
{
}

            
phpTypecast() public method

定義於: yii\db\ColumnSchema::phpTypecast()

從資料庫檢索後,根據 $phpType 轉換輸入值。

如果值為 null 或 yii\db\Expression,則不會轉換。

public mixed phpTypecast ( $value )
$value mixed

輸入值

return mixed

轉換後的值

                public function phpTypecast($value)
{
    return $this->typecast($value);
}

            
typecast() protected method (available since version 2.0.3)

定義於: yii\db\ColumnSchema::typecast()

從資料庫檢索後,根據 $phpType 轉換輸入值。

如果值為 null 或 yii\db\Expression,則不會轉換。

protected mixed typecast ( $value )
$value mixed

輸入值

return mixed

轉換後的值

                protected function typecast($value)
{
    if (
        $value === ''
        && !in_array(
            $this->type,
            [
                Schema::TYPE_TEXT,
                Schema::TYPE_STRING,
                Schema::TYPE_BINARY,
                Schema::TYPE_CHAR
            ],
            true
        )
    ) {
        return null;
    }
    if (
        $value === null
        || gettype($value) === $this->phpType
        || $value instanceof ExpressionInterface
        || $value instanceof Query
    ) {
        return $value;
    }
    if (
        is_array($value)
        && count($value) === 2
        && isset($value[1])
        && in_array($value[1], $this->getPdoParamTypes(), true)
    ) {
        return new PdoValue($value[0], $value[1]);
    }
    switch ($this->phpType) {
        case 'resource':
        case 'string':
            if (is_resource($value)) {
                return $value;
            }
            if (is_float($value)) {
                // ensure type cast always has . as decimal separator in all locales
                return StringHelper::floatToString($value);
            }
            if (
                is_numeric($value)
                && ColumnSchemaBuilder::CATEGORY_NUMERIC === ColumnSchemaBuilder::$typeCategoryMap[$this->type]
            ) {
                // https://github.com/yiisoft/yii2/issues/14663
                return $value;
            }
            if (PHP_VERSION_ID >= 80100 && is_object($value) && $value instanceof \BackedEnum) {
                return (string) $value->value;
            }
            return (string) $value;
        case 'integer':
            if (PHP_VERSION_ID >= 80100 && is_object($value) && $value instanceof \BackedEnum) {
                return (int) $value->value;
            }
            return (int) $value;
        case 'boolean':
            // treating a 0 bit value as false too
            // https://github.com/yiisoft/yii2/issues/9006
            return (bool) $value && $value !== "\0" && strtolower($value) !== 'false';
        case 'double':
            return (float) $value;
    }
    return $value;
}