0 追蹤者

類別 yii\db\oci\Schema

繼承關係yii\db\oci\Schema » yii\db\Schema » yii\base\BaseObject
實作介面yii\base\Configurable, yii\db\ConstraintFinderInterface
使用 Traityii\db\ConstraintFinderTrait
自版本起可用2.0
原始碼 https://github.com/yiisoft/yii2/blob/master/framework/db/oci/Schema.php

Schema 類別用於從 Oracle 資料庫檢索元數據。

公共屬性

隱藏繼承的屬性

屬性 類型 描述 定義於
$columnQuoteCharacter string|string[] 用於引用資料行名稱的字元。 yii\db\Schema
$columnSchemaClass string|array 資料行結構描述類別或類別配置 yii\db\Schema
$db yii\db\Connection 資料庫連線 yii\db\Schema
$defaultSchema string 目前工作階段使用的預設結構描述名稱。 yii\db\Schema
$exceptionMap array DB 錯誤與對應例外狀況的對應表。如果在 DB 錯誤訊息中找到左側部分,則使用右側部分的例外狀況類別。 yii\db\oci\Schema
$lastInsertID string 最後插入的資料列 ID,或從序列物件檢索的最後一個值。 yii\db\oci\Schema
$queryBuilder yii\db\QueryBuilder 此連線的查詢產生器。 yii\db\Schema
$schemaChecks \yii\db\CheckConstraint[][] 資料庫中所有表格的檢查約束。 yii\db\ConstraintFinderTrait
$schemaDefaultValues yii\db\DefaultValueConstraint[] 資料庫中所有表格的預設值約束。 yii\db\ConstraintFinderTrait
$schemaForeignKeys \yii\db\ForeignKeyConstraint[][] 資料庫中所有表格的外鍵。 yii\db\ConstraintFinderTrait
$schemaIndexes \yii\db\IndexConstraint[][] 資料庫中所有表格的索引。 yii\db\ConstraintFinderTrait
$schemaNames string[] 資料庫中所有結構描述名稱,系統結構描述除外。 yii\db\Schema
$schemaPrimaryKeys yii\db\Constraint[] 資料庫中所有表格的主鍵。 yii\db\ConstraintFinderTrait
$schemaUniques \yii\db\IndexConstraint[][] 資料庫中所有表格的唯一約束。 yii\db\ConstraintFinderTrait
$serverVersion string 伺服器版本字串。 yii\db\Schema
$tableNames string[] 資料庫中所有表格名稱。 yii\db\Schema
$tableQuoteCharacter string|string[] 用於引用結構描述、表格等的字元。 yii\db\oci\Schema
$tableSchemas yii\db\TableSchema[] 資料庫中所有表格的元數據。 yii\db\Schema
$transactionIsolationLevel string 此交易使用的交易隔離等級。 yii\db\Schema

受保護的屬性

隱藏繼承的屬性

屬性 類型 描述 定義於

公用方法

隱藏繼承的方法

方法 描述 定義於
__call() 呼叫指定的非類別方法。 yii\base\BaseObject
__construct() 建構子。 yii\base\BaseObject
__get() 傳回物件屬性的值。 yii\base\BaseObject
__isset() 檢查屬性是否已設定,即已定義且非 null。 yii\base\BaseObject
__set() 設定物件屬性的值。 yii\base\BaseObject
__unset() 將物件屬性設為 null。 yii\base\BaseObject
canGetProperty() 傳回一個值,指示屬性是否可讀取。 yii\base\BaseObject
canSetProperty() 傳回一個值,指示屬性是否可設定。 yii\base\BaseObject
className() 傳回此類別的完整限定名稱。 yii\base\BaseObject
convertException() 盡可能將 DB 例外狀況轉換為更具體的例外狀況。 yii\db\Schema
createColumnSchemaBuilder() 建立資料行結構描述產生器實例,並指定類型和值精確度。 yii\db\oci\Schema
createQueryBuilder() 為資料庫建立查詢產生器。 yii\db\oci\Schema
createSavepoint() 建立新的儲存點。 yii\db\Schema
findUniqueIndexes() 傳回指定表格的所有唯一索引。 yii\db\oci\Schema
getLastInsertID() yii\db\oci\Schema
getPdoType() 判斷給定 PHP 資料值的 PDO 類型。 yii\db\Schema
getQueryBuilder() yii\db\Schema
getRawTableName() 傳回給定表格名稱的實際名稱。 yii\db\Schema
getSchemaChecks() 傳回資料庫中所有表格的檢查約束。 yii\db\ConstraintFinderTrait
getSchemaDefaultValues() 傳回資料庫中所有表格的預設值約束。 yii\db\ConstraintFinderTrait
getSchemaForeignKeys() 傳回資料庫中所有表格的外鍵。 yii\db\ConstraintFinderTrait
getSchemaIndexes() 傳回資料庫中所有表格的索引。 yii\db\ConstraintFinderTrait
getSchemaNames() 傳回資料庫中所有結構描述名稱,系統結構描述除外。 yii\db\Schema
getSchemaPrimaryKeys() 傳回資料庫中所有表格的主鍵。 yii\db\ConstraintFinderTrait
getSchemaUniques() 傳回資料庫中所有表格的唯一約束。 yii\db\ConstraintFinderTrait
getServerVersion() 傳回伺服器版本字串,可使用 \version_compare() 進行比較。 yii\db\Schema
getTableChecks() 取得指定表格的檢查約束資訊。 yii\db\ConstraintFinderTrait
getTableDefaultValues() 取得指定表格的預設值約束資訊。 yii\db\ConstraintFinderTrait
getTableForeignKeys() 取得指定表格的外鍵資訊。 yii\db\ConstraintFinderTrait
getTableIndexes() 取得指定表格的索引資訊。 yii\db\ConstraintFinderTrait
getTableNames() 傳回資料庫中所有表格名稱。 yii\db\Schema
getTablePrimaryKey() 取得指定表格的主鍵。 yii\db\ConstraintFinderTrait
getTableSchema() 取得指定表格的元數據。 yii\db\Schema
getTableSchemas() 傳回資料庫中所有表格的元數據。 yii\db\Schema
getTableUniques() 取得指定表格的唯一約束資訊。 yii\db\ConstraintFinderTrait
hasMethod() 傳回一個值,指示是否已定義方法。 yii\base\BaseObject
hasProperty() 傳回一個值,指示是否已定義屬性。 yii\base\BaseObject
init() 初始化物件。 yii\db\oci\Schema
insert() 執行 INSERT 指令,傳回主鍵值。 yii\db\oci\Schema
isReadQuery() 傳回一個值,指示 SQL 陳述式是否用於讀取目的。 yii\db\Schema
quoteColumnName() 引用資料行名稱,以便在查詢中使用。 yii\db\Schema
quoteSimpleColumnName() 引用簡單資料行名稱,以便在查詢中使用。 yii\db\Schema
quoteSimpleTableName() 引用簡單表格名稱,以便在查詢中使用。 yii\db\oci\Schema
quoteTableName() 引用表格名稱,以便在查詢中使用。 yii\db\Schema
quoteValue() 引用字串值,以便在查詢中使用。 yii\db\Schema
refresh() 重新整理結構描述。 yii\db\Schema
refreshTableSchema() 重新整理特定表格結構描述。 yii\db\Schema
releaseSavepoint() 釋放現有的儲存點。 yii\db\oci\Schema
rollBackSavepoint() 回滾到先前建立的儲存點。 yii\db\Schema
setTransactionIsolationLevel() 設定目前交易的隔離等級。 yii\db\Schema
supportsSavepoint() yii\db\Schema
unquoteSimpleColumnName() 取消引用簡單資料行名稱。 yii\db\Schema
unquoteSimpleTableName() 取消引用簡單表格名稱。 yii\db\Schema

受保護的方法

隱藏繼承的方法

方法 描述 定義於
createColumn() 建立 ColumnSchema 實例。 yii\db\oci\Schema
createColumnSchema() 為資料庫建立資料行結構描述。 yii\db\Schema
extractColumnSize() 從資料行 DB 類型中提取大小、精確度和比例資訊。 yii\db\oci\Schema
extractColumnType() 提取給定資料行的資料類型。 yii\db\oci\Schema
findColumns() 收集表格資料行元數據。 yii\db\oci\Schema
findConstraints() 尋找約束並將其填入傳遞的 TableSchema 物件中。 yii\db\oci\Schema
findSchemaNames() 傳回資料庫中所有結構描述名稱,包括預設結構描述,但不包括系統結構描述。 yii\db\oci\Schema
findTableNames() 傳回資料庫中所有表格名稱。 yii\db\oci\Schema
getCacheKey() 傳回指定表格名稱的快取鍵。 yii\db\Schema
getCacheTag() 傳回快取標籤名稱。 yii\db\Schema
getColumnPhpType() 從抽象 DB 類型中提取 PHP 類型。 yii\db\Schema
getSchemaMetadata() 傳回給定結構描述中所有表格的給定類型元數據。 yii\db\ConstraintFinderTrait
getTableMetadata() 傳回給定表格的給定類型元數據。 yii\db\ConstraintFinderTrait
getTableNameParts() 將完整表格名稱拆分為多個部分 yii\db\Schema
loadTableChecks() yii\db\oci\Schema
loadTableDefaultValues() yii\db\oci\Schema
loadTableForeignKeys() yii\db\oci\Schema
loadTableIndexes() yii\db\oci\Schema
loadTablePrimaryKey() yii\db\oci\Schema
loadTableSchema() 載入指定表格的元數據。 yii\db\oci\Schema
loadTableUniques() yii\db\oci\Schema
normalizePdoRowKeyCase() 如果 PDO 的陣列鍵大小寫設為大寫,則將資料列的陣列鍵大小寫變更為小寫。 yii\db\Schema
resolveTableName() 解析表格名稱和結構描述名稱(如果有的話)。 yii\db\oci\Schema
resolveTableNames() 解析表格名稱和結構描述名稱(如果有的話)。 yii\db\oci\Schema
setTableMetadata() 設定給定表格的給定類型元數據。 yii\db\Schema

常數

隱藏繼承的常數

常數 描述 定義於
SCHEMA_CACHE_VERSION 1 結構描述快取版本,用於偵測快取值的格式變更時,快取值中的不相容性。 yii\db\Schema
TYPE_BIGINT 'bigint' yii\db\Schema
TYPE_BIGPK 'bigpk' yii\db\Schema
TYPE_BINARY 'binary' yii\db\Schema
TYPE_BOOLEAN 'boolean' yii\db\Schema
TYPE_CHAR 'char' yii\db\Schema
TYPE_DATE 'date' yii\db\Schema
TYPE_DATETIME 'datetime' yii\db\Schema
TYPE_DECIMAL 'decimal' yii\db\Schema
TYPE_DOUBLE 'double' yii\db\Schema
TYPE_FLOAT 'float' yii\db\Schema
TYPE_INTEGER 'integer' yii\db\Schema
TYPE_JSON 'json' yii\db\Schema
TYPE_MONEY 'money' yii\db\Schema
TYPE_PK 'pk' yii\db\Schema
TYPE_SMALLINT 'smallint' yii\db\Schema
TYPE_STRING 'string' yii\db\Schema
TYPE_TEXT 'text' yii\db\Schema
TYPE_TIME 'time' yii\db\Schema
TYPE_TIMESTAMP 'timestamp' yii\db\Schema
TYPE_TINYINT 'tinyint' yii\db\Schema
TYPE_UBIGPK 'ubigpk' yii\db\Schema
TYPE_UPK 'upk' yii\db\Schema

屬性詳細資訊

隱藏繼承的屬性

$exceptionMap 公用屬性

DB 錯誤與對應例外狀況的對應表。如果在 DB 錯誤訊息中找到左側部分,則使用右側部分的例外狀況類別。

public array $exceptionMap = [
    
'ORA-00001: unique constraint' => 'yii\db\IntegrityException',
]
$lastInsertID 公用屬性

最後插入的資料列 ID,或從序列物件檢索的最後一個值。

public string $lastInsertID null
$tableQuoteCharacter 受保護的屬性 (自版本 2.0.14 起可用)

用於引用結構描述、表格等名稱的字元。如果開始和結束字元不同,則可以使用 2 個字元的陣列。

方法詳細資訊

隱藏繼承的方法

__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\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() 公用方法

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

傳回物件屬性的值。

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

另請參閱 __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()

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

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

請注意,如果未定義屬性,將傳回 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()

設定物件屬性的值。

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

另請參閱 __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() 公用方法

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

將物件屬性設為 null。

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

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

另請參閱 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() 公用方法

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

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

            
convertException() 公用方法

定義於: yii\db\Schema::convertException()

盡可能將 DB 例外狀況轉換為更具體的例外狀況。

public yii\db\Exception convertException ( Exception $e, $rawSql )
$e 例外
$rawSql string

產生例外狀況的 SQL

                public function convertException(\Exception $e, $rawSql)
{
    if ($e instanceof Exception) {
        return $e;
    }
    $exceptionClass = '\yii\db\Exception';
    foreach ($this->exceptionMap as $error => $class) {
        if (strpos($e->getMessage(), $error) !== false) {
            $exceptionClass = $class;
        }
    }
    $message = $e->getMessage() . "\nThe SQL being executed was: $rawSql";
    $errorInfo = $e instanceof \PDOException ? $e->errorInfo : null;
    return new $exceptionClass($message, $errorInfo, $e->getCode(), $e);
}

            
createColumn() 受保護的方法

建立 ColumnSchema 實例。

protected yii\db\ColumnSchema createColumn ( $column )
$column array

                protected function createColumn($column)
{
    $c = $this->createColumnSchema();
    $c->name = $column['COLUMN_NAME'];
    $c->allowNull = $column['NULLABLE'] === 'Y';
    $c->comment = $column['COLUMN_COMMENT'] === null ? '' : $column['COLUMN_COMMENT'];
    $c->isPrimaryKey = false;
    $this->extractColumnType($c, $column['DATA_TYPE'], $column['DATA_PRECISION'], $column['DATA_SCALE'], $column['DATA_LENGTH']);
    $this->extractColumnSize($c, $column['DATA_TYPE'], $column['DATA_PRECISION'], $column['DATA_SCALE'], $column['DATA_LENGTH']);
    $c->phpType = $this->getColumnPhpType($c);
    if (!$c->isPrimaryKey) {
        if (stripos((string) $column['DATA_DEFAULT'], 'timestamp') !== false) {
            $c->defaultValue = null;
        } else {
            $defaultValue = (string) $column['DATA_DEFAULT'];
            if ($c->type === 'timestamp' && $defaultValue === 'CURRENT_TIMESTAMP') {
                $c->defaultValue = new Expression('CURRENT_TIMESTAMP');
            } else {
                if ($defaultValue !== null) {
                    if (
                        strlen($defaultValue) > 2
                        && strncmp($defaultValue, "'", 1) === 0
                        && substr($defaultValue, -1) === "'"
                    ) {
                        $defaultValue = substr($defaultValue, 1, -1);
                    } else {
                        $defaultValue = trim($defaultValue);
                    }
                }
                $c->defaultValue = $c->phpTypecast($defaultValue);
            }
        }
    }
    return $c;
}

            
createColumnSchema() 受保護的方法

定義於: yii\db\Schema::createColumnSchema()

為資料庫建立資料行結構描述。

子類別可以覆寫此方法以建立 DBMS 特定的資料行結構描述。

protected yii\db\ColumnSchema createColumnSchema ( )
return yii\db\ColumnSchema

資料行結構描述實例。

throws yii\base\InvalidConfigException

如果無法建立資料行結構描述類別。

                protected function createColumnSchema()
{
    return Yii::createObject($this->columnSchemaClass);
}

            
createColumnSchemaBuilder() 公用方法 (自版本 2.0.6 起可用)

建立資料行結構描述產生器實例,並指定類型和值精確度。

子類別可以覆寫此方法以建立 DBMS 特定的資料行結構描述產生器。

public yii\db\ColumnSchemaBuilder createColumnSchemaBuilder ( $type, $length null )
$type string

資料行的類型。請參閱 yii\db\oci\ColumnSchemaBuilder::$type

$length integer|string|array|null

資料行的長度或精確度。請參閱 yii\db\oci\ColumnSchemaBuilder::$length

return yii\db\ColumnSchemaBuilder

資料行結構描述產生器實例

                public function createColumnSchemaBuilder($type, $length = null)
{
    return Yii::createObject(ColumnSchemaBuilder::className(), [$type, $length]);
}

            
createQueryBuilder() 公用方法

為資料庫建立查詢產生器。

子類別可以覆寫此方法以建立 DBMS 特定的查詢產生器。

public yii\db\QueryBuilder createQueryBuilder ( )
return yii\db\QueryBuilder

查詢產生器實例

                public function createQueryBuilder()
{
    return Yii::createObject(QueryBuilder::className(), [$this->db]);
}

            
createSavepoint() 公用方法

定義於: yii\db\Schema::createSavepoint()

建立新的儲存點。

public void createSavepoint ( $name )
$name string

儲存點名稱

                public function createSavepoint($name)
{
    $this->db->createCommand("SAVEPOINT $name")->execute();
}

            
extractColumnSize() 受保護的方法

從資料行 DB 類型中提取大小、精確度和比例資訊。

protected void extractColumnSize ( $column, $dbType, $precision, $scale, $length )
$column yii\db\ColumnSchema
$dbType string

資料行的 DB 類型

$precision string

總位數。此參數自版本 2.0.4 起可用。

$scale string

小數點分隔符號右側的位數。此參數自版本 2.0.4 起可用。

$length string

字元類型的長度。此參數自版本 2.0.4 起可用。

                protected function extractColumnSize($column, $dbType, $precision, $scale, $length)
{
    $column->size = trim((string) $length) === '' ? null : (int) $length;
    $column->precision = trim((string) $precision) === '' ? null : (int) $precision;
    $column->scale = trim((string) $scale) === '' ? null : (int) $scale;
}

            
extractColumnType() 受保護的方法

提取給定資料行的資料類型。

protected void extractColumnType ( $column, $dbType, $precision, $scale, $length )
$column yii\db\ColumnSchema
$dbType string

DB 類型

$precision string

總位數。此參數自版本 2.0.4 起可用。

$scale string

小數點分隔符號右側的位數。此參數自版本 2.0.4 起可用。

$length string

字元類型的長度。此參數自版本 2.0.4 起可用。

                protected function extractColumnType($column, $dbType, $precision, $scale, $length)
{
    $column->dbType = $dbType;
    if (strpos($dbType, 'FLOAT') !== false || strpos($dbType, 'DOUBLE') !== false) {
        $column->type = 'double';
    } elseif (strpos($dbType, 'NUMBER') !== false) {
        if ($scale === null || $scale > 0) {
            $column->type = 'decimal';
        } else {
            $column->type = 'integer';
        }
    } elseif (strpos($dbType, 'INTEGER') !== false) {
        $column->type = 'integer';
    } elseif (strpos($dbType, 'BLOB') !== false) {
        $column->type = 'binary';
    } elseif (strpos($dbType, 'CLOB') !== false) {
        $column->type = 'text';
    } elseif (strpos($dbType, 'TIMESTAMP') !== false) {
        $column->type = 'timestamp';
    } else {
        $column->type = 'string';
    }
}

            
findColumns() protected method

收集表格資料行元數據。

protected boolean findColumns ( $table )
$table yii\db\TableSchema

資料表結構描述

return boolean

資料表是否存在

                protected function findColumns($table)
{
    $sql = <<<'SQL'
CT
A.COLUMN_NAME,
A.DATA_TYPE,
A.DATA_PRECISION,
A.DATA_SCALE,
(
  CASE A.CHAR_USED WHEN 'C' THEN A.CHAR_LENGTH
    ELSE A.DATA_LENGTH
  END
) AS DATA_LENGTH,
A.NULLABLE,
A.DATA_DEFAULT,
COM.COMMENTS AS COLUMN_COMMENT
 ALL_TAB_COLUMNS A
INNER JOIN ALL_OBJECTS B ON B.OWNER = A.OWNER AND LTRIM(B.OBJECT_NAME) = LTRIM(A.TABLE_NAME)
LEFT JOIN ALL_COL_COMMENTS COM ON (A.OWNER = COM.OWNER AND A.TABLE_NAME = COM.TABLE_NAME AND A.COLUMN_NAME = COM.COLUMN_NAME)
E
A.OWNER = :schemaName
AND B.OBJECT_TYPE IN ('TABLE', 'VIEW', 'MATERIALIZED VIEW')
AND B.OBJECT_NAME = :tableName
R BY A.COLUMN_ID

    try {
        $columns = $this->db->createCommand($sql, [
            ':tableName' => $table->name,
            ':schemaName' => $table->schemaName,
        ])->queryAll();
    } catch (\Exception $e) {
        return false;
    }
    if (empty($columns)) {
        return false;
    }
    foreach ($columns as $column) {
        if ($this->db->slavePdo->getAttribute(\PDO::ATTR_CASE) === \PDO::CASE_LOWER) {
            $column = array_change_key_case($column, CASE_UPPER);
        }
        $c = $this->createColumn($column);
        $table->columns[$c->name] = $c;
    }
    return true;
}

            
findConstraints() protected method

尋找約束並將其填入傳遞的 TableSchema 物件中。

protected void findConstraints ( $table )
$table yii\db\TableSchema

                protected function findConstraints($table)
{
    $sql = <<<'SQL'
CT
/*+ PUSH_PRED(C) PUSH_PRED(D) PUSH_PRED(E) */
D.CONSTRAINT_NAME,
D.CONSTRAINT_TYPE,
C.COLUMN_NAME,
C.POSITION,
D.R_CONSTRAINT_NAME,
E.TABLE_NAME AS TABLE_REF,
F.COLUMN_NAME AS COLUMN_REF,
C.TABLE_NAME
 ALL_CONS_COLUMNS C
INNER JOIN ALL_CONSTRAINTS D ON D.OWNER = C.OWNER AND D.CONSTRAINT_NAME = C.CONSTRAINT_NAME
LEFT JOIN ALL_CONSTRAINTS E ON E.OWNER = D.R_OWNER AND E.CONSTRAINT_NAME = D.R_CONSTRAINT_NAME
LEFT JOIN ALL_CONS_COLUMNS F ON F.OWNER = E.OWNER AND F.CONSTRAINT_NAME = E.CONSTRAINT_NAME AND F.POSITION = C.POSITION
E
C.OWNER = :schemaName
AND C.TABLE_NAME = :tableName
R BY D.CONSTRAINT_NAME, C.POSITION

    $command = $this->db->createCommand($sql, [
        ':tableName' => $table->name,
        ':schemaName' => $table->schemaName,
    ]);
    $constraints = [];
    foreach ($command->queryAll() as $row) {
        if ($this->db->slavePdo->getAttribute(\PDO::ATTR_CASE) === \PDO::CASE_LOWER) {
            $row = array_change_key_case($row, CASE_UPPER);
        }
        if ($row['CONSTRAINT_TYPE'] === 'P') {
            $table->columns[$row['COLUMN_NAME']]->isPrimaryKey = true;
            $table->primaryKey[] = $row['COLUMN_NAME'];
            if (empty($table->sequenceName)) {
                $table->sequenceName = $this->getTableSequenceName($table->name);
            }
        }
        if ($row['CONSTRAINT_TYPE'] !== 'R') {
            // this condition is not checked in SQL WHERE because of an Oracle Bug:
            // see https://github.com/yiisoft/yii2/pull/8844
            continue;
        }
        $name = $row['CONSTRAINT_NAME'];
        if (!isset($constraints[$name])) {
            $constraints[$name] = [
                'tableName' => $row['TABLE_REF'],
                'columns' => [],
            ];
        }
        $constraints[$name]['columns'][$row['COLUMN_NAME']] = $row['COLUMN_REF'];
    }
    foreach ($constraints as $constraint) {
        $name = current(array_keys($constraint));
        $table->foreignKeys[$name] = array_merge([$constraint['tableName']], $constraint['columns']);
    }
}

            
findSchemaNames() protected method (available since version 2.0.4)

傳回資料庫中所有結構描述名稱,包括預設結構描述,但不包括系統結構描述。

為了支援此功能,子類別應覆寫此方法,因為預設實作只會拋出例外。

另請參閱 https://docs.oracle.com/cd/B28359_01/server.111/b28337/tdpsg_user_accounts.htm

protected array findSchemaNames ( )
return array

資料庫中所有結構描述名稱,系統結構描述除外。

throws yii\base\NotSupportedException

如果 DBMS 不支援此方法。

                protected function findSchemaNames()
{
    static $sql = <<<'SQL'
CT "u"."USERNAME"
 "DBA_USERS" "u"
E "u"."DEFAULT_TABLESPACE" NOT IN ('SYSTEM', 'SYSAUX')
R BY "u"."USERNAME" ASC

    return $this->db->createCommand($sql)->queryColumn();
}

            
findTableNames() protected method

傳回資料庫中所有表格名稱。

為了支援此功能,子類別應覆寫此方法,因為預設實作只會拋出例外。

protected array findTableNames ( $schema '' )
$schema string

資料表的結構描述。預設為空字串,表示目前的或預設的結構描述。

return array

資料庫中的所有資料表名稱。名稱不帶結構描述名稱前綴。

throws yii\base\NotSupportedException

如果 DBMS 不支援此方法。

                protected function findTableNames($schema = '')
{
    if ($schema === '') {
        $sql = <<<'SQL'
CT
TABLE_NAME
 USER_TABLES
N ALL
CT
VIEW_NAME AS TABLE_NAME
 USER_VIEWS
N ALL
CT
MVIEW_NAME AS TABLE_NAME
 USER_MVIEWS
R BY TABLE_NAME

        $command = $this->db->createCommand($sql);
    } else {
        $sql = <<<'SQL'
CT
OBJECT_NAME AS TABLE_NAME
 ALL_OBJECTS
E
OBJECT_TYPE IN ('TABLE', 'VIEW', 'MATERIALIZED VIEW')
AND OWNER = :schema
R BY OBJECT_NAME

        $command = $this->db->createCommand($sql, [':schema' => $schema]);
    }
    $rows = $command->queryAll();
    $names = [];
    foreach ($rows as $row) {
        if ($this->db->slavePdo->getAttribute(\PDO::ATTR_CASE) === \PDO::CASE_LOWER) {
            $row = array_change_key_case($row, CASE_UPPER);
        }
        $names[] = $row['TABLE_NAME'];
    }
    return $names;
}

            
findUniqueIndexes() public method (available since version 2.0.4)

傳回指定表格的所有唯一索引。

每個陣列元素都具有以下結構:。

[
    'IndexName1' => ['col1' [, ...]],
    'IndexName2' => ['col2' [, ...]],
]
public array findUniqueIndexes ( $table )
$table yii\db\TableSchema

資料表的中繼資料

return array

給定資料表的所有唯一索引。

                public function findUniqueIndexes($table)
{
    $query = <<<'SQL'
CT
DIC.INDEX_NAME,
DIC.COLUMN_NAME
 ALL_INDEXES DI
INNER JOIN ALL_IND_COLUMNS DIC ON DI.TABLE_NAME = DIC.TABLE_NAME AND DI.INDEX_NAME = DIC.INDEX_NAME
E
DI.UNIQUENESS = 'UNIQUE'
AND DIC.TABLE_OWNER = :schemaName
AND DIC.TABLE_NAME = :tableName
R BY DIC.TABLE_NAME, DIC.INDEX_NAME, DIC.COLUMN_POSITION

    $result = [];
    $command = $this->db->createCommand($query, [
        ':tableName' => $table->name,
        ':schemaName' => $table->schemaName,
    ]);
    foreach ($command->queryAll() as $row) {
        $result[$row['INDEX_NAME']][] = $row['COLUMN_NAME'];
    }
    return $result;
}

            
getCacheKey() protected method

定義於: yii\db\Schema::getCacheKey()

傳回指定表格名稱的快取鍵。

protected mixed getCacheKey ( $name )
$name string

資料表名稱。

return mixed

快取鍵。

                protected function getCacheKey($name)
{
    return [
        __CLASS__,
        $this->db->dsn,
        $this->db->username,
        $this->getRawTableName($name),
    ];
}

            
getCacheTag() protected method

定義於: yii\db\Schema::getCacheTag()

傳回快取標籤名稱。

這允許 refresh() 使所有快取的資料表結構描述失效。

protected string getCacheTag ( )
return string

快取標籤名稱

                protected function getCacheTag()
{
    return md5(serialize([
        __CLASS__,
        $this->db->dsn,
        $this->db->username,
    ]));
}

            
getColumnPhpType() protected method

定義於: yii\db\Schema::getColumnPhpType()

從抽象 DB 類型中提取 PHP 類型。

protected string getColumnPhpType ( $column )
$column yii\db\ColumnSchema

資料行結構描述資訊

return string

PHP 型別名稱

                protected function getColumnPhpType($column)
{
    static $typeMap = [
        // abstract type => php type
        self::TYPE_TINYINT => 'integer',
        self::TYPE_SMALLINT => 'integer',
        self::TYPE_INTEGER => 'integer',
        self::TYPE_BIGINT => 'integer',
        self::TYPE_BOOLEAN => 'boolean',
        self::TYPE_FLOAT => 'double',
        self::TYPE_DOUBLE => 'double',
        self::TYPE_BINARY => 'resource',
        self::TYPE_JSON => 'array',
    ];
    if (isset($typeMap[$column->type])) {
        if ($column->type === 'bigint') {
            return PHP_INT_SIZE === 8 && !$column->unsigned ? 'integer' : 'string';
        } elseif ($column->type === 'integer') {
            return PHP_INT_SIZE === 4 && $column->unsigned ? 'string' : 'integer';
        }
        return $typeMap[$column->type];
    }
    return 'string';
}

            
getLastInsertID() public method

另請參閱 https://php.dev.org.tw/manual/en/function.PDO-lastInsertId.php -> Oracle 不支援此功能。傳回最後插入的資料列或序列值 ID。

public string getLastInsertID ( $sequenceName '' )
$sequenceName string

序列物件的名稱 (某些 DBMS 需要)

return string

最後插入的資料列的資料列 ID,或從序列物件擷取的最後一個值

throws yii\base\InvalidCallException

如果 DB 連線未啟用

                public function getLastInsertID($sequenceName = '')
{
    if ($this->db->isActive) {
        // get the last insert id from the master connection
        $sequenceName = $this->quoteSimpleTableName($sequenceName);
        return $this->db->useMaster(function (Connection $db) use ($sequenceName) {
            return $db->createCommand("SELECT {$sequenceName}.CURRVAL FROM DUAL")->queryScalar();
        });
    } else {
        throw new InvalidCallException('DB Connection is not active.');
    }
}

            
getPdoType() public method

定義於: yii\db\Schema::getPdoType()

判斷給定 PHP 資料值的 PDO 類型。

另請參閱 https://php.dev.org.tw/manual/en/pdo.constants.php

public integer getPdoType ( $data )
$data mixed

要判斷 PDO 型別的資料

return integer

PDO 型別

                public function getPdoType($data)
{
    static $typeMap = [
        // php type => PDO type
        'boolean' => \PDO::PARAM_BOOL,
        'integer' => \PDO::PARAM_INT,
        'string' => \PDO::PARAM_STR,
        'resource' => \PDO::PARAM_LOB,
        'NULL' => \PDO::PARAM_NULL,
    ];
    $type = gettype($data);
    return isset($typeMap[$type]) ? $typeMap[$type] : \PDO::PARAM_STR;
}

            
getQueryBuilder() public method
public yii\db\QueryBuilder getQueryBuilder ( )
return yii\db\QueryBuilder

此連線的查詢產生器。

                public function getQueryBuilder()
{
    if ($this->_builder === null) {
        $this->_builder = $this->createQueryBuilder();
    }
    return $this->_builder;
}

            
getRawTableName() public method

定義於: yii\db\Schema::getRawTableName()

傳回給定表格名稱的實際名稱。

此方法將從給定的資料表名稱中去除大括號,並將百分比字元 '%' 替換為 yii\db\Connection::$tablePrefix

public string getRawTableName ( $name )
$name string

要轉換的資料表名稱

return string

給定資料表名稱的實際名稱

                public function getRawTableName($name)
{
    if (strpos($name, '{{') !== false) {
        $name = preg_replace('/\\{\\{(.*?)\\}\\}/', '\1', $name);
        return str_replace('%', $this->db->tablePrefix, $name);
    }
    return $name;
}

            
getSchemaChecks() public method

定義於: yii\db\ConstraintFinderTrait::getSchemaChecks()

傳回資料庫中所有表格的檢查約束。

public \yii\db\CheckConstraint[][] getSchemaChecks ( $schema '', $refresh false )
$schema string

資料表的結構描述。預設為空字串,表示目前的或預設的結構描述名稱。

$refresh boolean

是否擷取最新的可用資料表結構描述。如果為 false,則可能會傳回快取的資料 (如果有的話)。

return \yii\db\CheckConstraint[][]

資料庫中所有資料表的檢查約束。每個陣列元素都是 yii\db\CheckConstraint 或其子類別的陣列。

                public function getSchemaChecks($schema = '', $refresh = false)
{
    return $this->getSchemaMetadata($schema, 'checks', $refresh);
}

            
getSchemaDefaultValues() public method

定義於: yii\db\ConstraintFinderTrait::getSchemaDefaultValues()

傳回資料庫中所有表格的預設值約束。

public yii\db\DefaultValueConstraint[] getSchemaDefaultValues ( $schema '', $refresh false )
$schema string

資料表的結構描述。預設為空字串,表示目前的或預設的結構描述名稱。

$refresh boolean

是否擷取最新的可用資料表結構描述。如果為 false,則可能會傳回快取的資料 (如果有的話)。

return yii\db\DefaultValueConstraint[]

資料庫中所有資料表的預設值約束。每個陣列元素都是 yii\db\DefaultValueConstraint 或其子類別的陣列。

                public function getSchemaDefaultValues($schema = '', $refresh = false)
{
    return $this->getSchemaMetadata($schema, 'defaultValues', $refresh);
}

            
getSchemaForeignKeys() public method

定義於: yii\db\ConstraintFinderTrait::getSchemaForeignKeys()

傳回資料庫中所有表格的外鍵。

public \yii\db\ForeignKeyConstraint[][] getSchemaForeignKeys ( $schema '', $refresh false )
$schema string

資料表的結構描述。預設為空字串,表示目前的或預設的結構描述名稱。

$refresh boolean

是否擷取最新的可用資料表結構描述。如果為 false,則可能會傳回快取的資料 (如果有的話)。

return \yii\db\ForeignKeyConstraint[][]

資料庫中所有資料表的外來鍵。每個陣列元素都是 yii\db\ForeignKeyConstraint 或其子類別的陣列。

                public function getSchemaForeignKeys($schema = '', $refresh = false)
{
    return $this->getSchemaMetadata($schema, 'foreignKeys', $refresh);
}

            
getSchemaIndexes() public method

定義於: yii\db\ConstraintFinderTrait::getSchemaIndexes()

傳回資料庫中所有表格的索引。

public \yii\db\IndexConstraint[][] getSchemaIndexes ( $schema '', $refresh false )
$schema string

資料表的結構描述。預設為空字串,表示目前的或預設的結構描述名稱。

$refresh boolean

是否擷取最新的可用資料表結構描述。如果為 false,則可能會傳回快取的資料 (如果有的話)。

return \yii\db\IndexConstraint[][]

資料庫中所有資料表的索引。每個陣列元素都是 yii\db\IndexConstraint 或其子類別的陣列。

                public function getSchemaIndexes($schema = '', $refresh = false)
{
    return $this->getSchemaMetadata($schema, 'indexes', $refresh);
}

            
getSchemaMetadata() protected abstract method

定義於: yii\db\ConstraintFinderTrait::getSchemaMetadata()

傳回給定結構描述中所有表格的給定類型元數據。

protected abstract array getSchemaMetadata ( $schema, $type, $refresh )
$schema string

中繼資料的結構描述。預設為空字串,表示目前的或預設的結構描述名稱。

$type string

中繼資料型別。

$refresh boolean

是否擷取最新的可用資料表結構描述。如果為 false,則可能會傳回快取的資料 (如果有的話)。

return array

中繼資料陣列。

                abstract protected function getSchemaMetadata($schema, $type, $refresh);

            
getSchemaNames() public method (available since version 2.0.4)

定義於: yii\db\Schema::getSchemaNames()

傳回資料庫中所有結構描述名稱,系統結構描述除外。

public string[] getSchemaNames ( $refresh false )
$refresh boolean

是否擷取最新的可用結構描述名稱。如果為 false,則會傳回先前擷取的結構描述名稱 (如果有的話)。

return string[]

資料庫中所有結構描述名稱,系統結構描述除外。

                public function getSchemaNames($refresh = false)
{
    if ($this->_schemaNames === null || $refresh) {
        $this->_schemaNames = $this->findSchemaNames();
    }
    return $this->_schemaNames;
}

            
getSchemaPrimaryKeys() public method

定義於: yii\db\ConstraintFinderTrait::getSchemaPrimaryKeys()

傳回資料庫中所有表格的主鍵。

public yii\db\Constraint[] getSchemaPrimaryKeys ( $schema '', $refresh false )
$schema string

資料表的結構描述。預設為空字串,表示目前的或預設的結構描述名稱。

$refresh boolean

是否擷取最新的可用資料表結構描述。如果為 false,則可能會傳回快取的資料 (如果有的話)。

return yii\db\Constraint[]

資料庫中所有資料表的主鍵。每個陣列元素都是 yii\db\Constraint 或其子類別的實例。

                public function getSchemaPrimaryKeys($schema = '', $refresh = false)
{
    return $this->getSchemaMetadata($schema, 'primaryKey', $refresh);
}

            
getSchemaUniques() public method

定義於: yii\db\ConstraintFinderTrait::getSchemaUniques()

傳回資料庫中所有表格的唯一約束。

public \yii\db\Constraint[][] getSchemaUniques ( $schema '', $refresh false )
$schema string

資料表的結構描述。預設為空字串,表示目前的或預設的結構描述名稱。

$refresh boolean

是否擷取最新的可用資料表結構描述。如果為 false,則可能會傳回快取的資料 (如果有的話)。

return \yii\db\Constraint[][]

資料庫中所有資料表的唯一約束。每個陣列元素都是 yii\db\Constraint 或其子類別的陣列。

                public function getSchemaUniques($schema = '', $refresh = false)
{
    return $this->getSchemaMetadata($schema, 'uniques', $refresh);
}

            
getServerVersion() public method (available since version 2.0.14)

定義於: yii\db\Schema::getServerVersion()

傳回伺服器版本字串,可使用 \version_compare() 進行比較。

public string getServerVersion ( )
return string

伺服器版本字串。

                public function getServerVersion()
{
    if ($this->_serverVersion === null) {
        $this->_serverVersion = $this->db->getSlavePdo(true)->getAttribute(\PDO::ATTR_SERVER_VERSION);
    }
    return $this->_serverVersion;
}

            
getTableChecks() public method

定義於: yii\db\ConstraintFinderTrait::getTableChecks()

取得指定表格的檢查約束資訊。

public yii\db\CheckConstraint[] getTableChecks ( $name, $refresh false )
$name string

資料表名稱。資料表名稱可以包含結構描述名稱 (如果有的話)。請勿引用資料表名稱。

$refresh boolean

即使在快取中找到資訊,是否重新載入資訊。

return yii\db\CheckConstraint[]

資料表檢查約束。

                public function getTableChecks($name, $refresh = false)
{
    return $this->getTableMetadata($name, 'checks', $refresh);
}

            
getTableDefaultValues() public method

定義於: yii\db\ConstraintFinderTrait::getTableDefaultValues()

取得指定表格的預設值約束資訊。

public yii\db\DefaultValueConstraint[] getTableDefaultValues ( $name, $refresh false )
$name string

資料表名稱。資料表名稱可以包含結構描述名稱 (如果有的話)。請勿引用資料表名稱。

$refresh boolean

即使在快取中找到資訊,是否重新載入資訊。

return yii\db\DefaultValueConstraint[]

資料表預設值約束。

                public function getTableDefaultValues($name, $refresh = false)
{
    return $this->getTableMetadata($name, 'defaultValues', $refresh);
}

            
getTableForeignKeys() public method

定義於: yii\db\ConstraintFinderTrait::getTableForeignKeys()

取得指定表格的外鍵資訊。

public yii\db\ForeignKeyConstraint[] getTableForeignKeys ( $name, $refresh false )
$name string

資料表名稱。資料表名稱可以包含結構描述名稱 (如果有的話)。請勿引用資料表名稱。

$refresh boolean

即使在快取中找到資訊,是否重新載入資訊。

return yii\db\ForeignKeyConstraint[]

資料表外來鍵。

                public function getTableForeignKeys($name, $refresh = false)
{
    return $this->getTableMetadata($name, 'foreignKeys', $refresh);
}

            
getTableIndexes() public method

定義於: yii\db\ConstraintFinderTrait::getTableIndexes()

取得指定表格的索引資訊。

public yii\db\IndexConstraint[] getTableIndexes ( $name, $refresh false )
$name string

資料表名稱。資料表名稱可以包含結構描述名稱 (如果有的話)。請勿引用資料表名稱。

$refresh boolean

即使在快取中找到資訊,是否重新載入資訊。

return yii\db\IndexConstraint[]

資料表索引。

                public function getTableIndexes($name, $refresh = false)
{
    return $this->getTableMetadata($name, 'indexes', $refresh);
}

            
getTableMetadata() protected abstract method

定義於: yii\db\ConstraintFinderTrait::getTableMetadata()

傳回給定表格的給定類型元數據。

protected abstract mixed getTableMetadata ( $name, $type, $refresh )
$name string

資料表名稱。資料表名稱可以包含結構描述名稱 (如果有的話)。請勿引用資料表名稱。

$type string

中繼資料型別。

$refresh boolean

即使在快取中找到資料表中繼資料,是否重新載入。

return mixed

中繼資料。

                abstract protected function getTableMetadata($name, $type, $refresh);

            
getTableNameParts() protected method (available since version 2.0.22)

定義於: yii\db\Schema::getTableNameParts()

將完整表格名稱拆分為多個部分

protected array getTableNameParts ( $name )
$name string

                protected function getTableNameParts($name)
{
    return explode('.', $name);
}

            
getTableNames() public method

定義於: yii\db\Schema::getTableNames()

傳回資料庫中所有表格名稱。

public string[] getTableNames ( $schema '', $refresh false )
$schema string

資料表的結構描述。預設為空字串,表示目前的或預設的結構描述名稱。如果非空,則傳回的資料表名稱將會加上結構描述名稱前綴。

$refresh boolean

是否擷取最新的可用資料表名稱。如果為 false,則會傳回先前擷取的資料表名稱 (如果有的話)。

return string[]

資料庫中所有表格名稱。

                public function getTableNames($schema = '', $refresh = false)
{
    if (!isset($this->_tableNames[$schema]) || $refresh) {
        $this->_tableNames[$schema] = $this->findTableNames($schema);
    }
    return $this->_tableNames[$schema];
}

            
getTablePrimaryKey() public method

定義於: yii\db\ConstraintFinderTrait::getTablePrimaryKey()

取得指定表格的主鍵。

public yii\db\Constraint|null getTablePrimaryKey ( $name, $refresh false )
$name string

資料表名稱。資料表名稱可以包含結構描述名稱 (如果有的話)。請勿引用資料表名稱。

$refresh boolean

即使在快取中找到資訊,是否重新載入資訊。

return yii\db\Constraint|null

資料表主鍵;如果資料表沒有主鍵,則為 null

                public function getTablePrimaryKey($name, $refresh = false)
{
    return $this->getTableMetadata($name, 'primaryKey', $refresh);
}

            
getTableSchema() public method

定義於: yii\db\Schema::getTableSchema()

取得指定表格的元數據。

public yii\db\TableSchema|null getTableSchema ( $name, $refresh false )
$name string

資料表名稱。資料表名稱可以包含結構描述名稱 (如果有的話)。請勿引用資料表名稱。

$refresh boolean

即使在快取中找到表格結構描述,是否仍要重新載入。

return yii\db\TableSchema|null

表格中繼資料。如果指定的表格不存在,則為 null

                public function getTableSchema($name, $refresh = false)
{
    return $this->getTableMetadata($name, 'schema', $refresh);
}

            
getTableSchemas() public method

定義於: yii\db\Schema::getTableSchemas()

傳回資料庫中所有表格的元數據。

public yii\db\TableSchema[] getTableSchemas ( $schema '', $refresh false )
$schema string

資料表的結構描述。預設為空字串,表示目前的或預設的結構描述名稱。

$refresh boolean

是否擷取最新的可用資料表結構描述。如果為 false,則可能會傳回快取的資料 (如果有的話)。

return yii\db\TableSchema[]

資料庫中所有表格的中繼資料。每個陣列元素都是 yii\db\TableSchema 或其子類別的實例。

                public function getTableSchemas($schema = '', $refresh = false)
{
    return $this->getSchemaMetadata($schema, 'schema', $refresh);
}

            
getTableUniques() public method

定義於: yii\db\ConstraintFinderTrait::getTableUniques()

取得指定表格的唯一約束資訊。

public yii\db\Constraint[] getTableUniques ( $name, $refresh false )
$name string

資料表名稱。資料表名稱可以包含結構描述名稱 (如果有的話)。請勿引用資料表名稱。

$refresh boolean

即使在快取中找到資訊,是否重新載入資訊。

return yii\db\Constraint[]

表格唯一約束。

                public function getTableUniques($name, $refresh = false)
{
    return $this->getTableMetadata($name, 'uniques', $refresh);
}

            
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

初始化物件。

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

public void init ( )

                public function init()
{
    parent::init();
    if ($this->defaultSchema === null) {
        $username = $this->db->username;
        if (empty($username)) {
            $username = isset($this->db->masters[0]['username']) ? $this->db->masters[0]['username'] : '';
        }
        $this->defaultSchema = strtoupper($username);
    }
}

            
insert() public method (自版本 2.0.4 起可用)

執行 INSERT 指令,傳回主鍵值。

public array|false insert ( $table, $columns )
$table string

新資料列將插入的表格。

$columns array

要插入表格的欄位資料(名稱 => 值)。

return array|false

如果指令失敗,則傳回主鍵值或 false

                public function insert($table, $columns)
{
    $params = [];
    $returnParams = [];
    $sql = $this->db->getQueryBuilder()->insert($table, $columns, $params);
    $tableSchema = $this->getTableSchema($table);
    $returnColumns = $tableSchema->primaryKey;
    if (!empty($returnColumns)) {
        $columnSchemas = $tableSchema->columns;
        $returning = [];
        foreach ((array) $returnColumns as $name) {
            $phName = QueryBuilder::PARAM_PREFIX . (count($params) + count($returnParams));
            $returnParams[$phName] = [
                'column' => $name,
                'value' => '',
            ];
            if (!isset($columnSchemas[$name]) || $columnSchemas[$name]->phpType !== 'integer') {
                $returnParams[$phName]['dataType'] = \PDO::PARAM_STR;
            } else {
                $returnParams[$phName]['dataType'] = \PDO::PARAM_INT;
            }
            $returnParams[$phName]['size'] = isset($columnSchemas[$name]->size) ? $columnSchemas[$name]->size : -1;
            $returning[] = $this->quoteColumnName($name);
        }
        $sql .= ' RETURNING ' . implode(', ', $returning) . ' INTO ' . implode(', ', array_keys($returnParams));
    }
    $command = $this->db->createCommand($sql, $params);
    $command->prepare(false);
    foreach ($returnParams as $name => &$value) {
        $command->pdoStatement->bindParam($name, $value['value'], $value['dataType'], $value['size']);
    }
    if (!$command->execute()) {
        return false;
    }
    $result = [];
    foreach ($returnParams as $value) {
        $result[$value['column']] = $value['value'];
    }
    return $result;
}

            
isReadQuery() public method

定義於: yii\db\Schema::isReadQuery()

傳回一個值,指示 SQL 陳述式是否用於讀取目的。

public boolean isReadQuery ( $sql )
$sql string

SQL 陳述式

return boolean

SQL 陳述式是否用於讀取目的。

                public function isReadQuery($sql)
{
    $pattern = '/^\s*(SELECT|SHOW|DESCRIBE)\b/i';
    return preg_match($pattern, $sql) > 0;
}

            
loadTableChecks() protected method

protected void loadTableChecks ( $tableName )
$tableName

                protected function loadTableChecks($tableName)
{
    return $this->loadTableConstraints($tableName, 'checks');
}

            
loadTableDefaultValues() protected method

protected void loadTableDefaultValues ( $tableName )
$tableName
throws yii\base\NotSupportedException

如果呼叫此方法。

                protected function loadTableDefaultValues($tableName)
{
    throw new NotSupportedException('Oracle does not support default value constraints.');
}

            
loadTableForeignKeys() protected method

protected void loadTableForeignKeys ( $tableName )
$tableName

                protected function loadTableForeignKeys($tableName)
{
    return $this->loadTableConstraints($tableName, 'foreignKeys');
}

            
loadTableIndexes() protected method

protected void loadTableIndexes ( $tableName )
$tableName

                protected function loadTableIndexes($tableName)
{
    static $sql = <<<'SQL'
CT
/*+ PUSH_PRED("ui") PUSH_PRED("uicol") PUSH_PRED("uc") */
"ui"."INDEX_NAME" AS "name",
"uicol"."COLUMN_NAME" AS "column_name",
CASE "ui"."UNIQUENESS" WHEN 'UNIQUE' THEN 1 ELSE 0 END AS "index_is_unique",
CASE WHEN "uc"."CONSTRAINT_NAME" IS NOT NULL THEN 1 ELSE 0 END AS "index_is_primary"
 "SYS"."USER_INDEXES" "ui"
 JOIN "SYS"."USER_IND_COLUMNS" "uicol"
ON "uicol"."INDEX_NAME" = "ui"."INDEX_NAME"
 JOIN "SYS"."USER_CONSTRAINTS" "uc"
ON "uc"."OWNER" = "ui"."TABLE_OWNER" AND "uc"."CONSTRAINT_NAME" = "ui"."INDEX_NAME" AND "uc"."CONSTRAINT_TYPE" = 'P'
E "ui"."TABLE_OWNER" = :schemaName AND "ui"."TABLE_NAME" = :tableName
R BY "uicol"."COLUMN_POSITION" ASC

    $resolvedName = $this->resolveTableName($tableName);
    $indexes = $this->db->createCommand($sql, [
        ':schemaName' => $resolvedName->schemaName,
        ':tableName' => $resolvedName->name,
    ])->queryAll();
    $indexes = $this->normalizePdoRowKeyCase($indexes, true);
    $indexes = ArrayHelper::index($indexes, null, 'name');
    $result = [];
    foreach ($indexes as $name => $index) {
        $result[] = new IndexConstraint([
            'isPrimary' => (bool) $index[0]['index_is_primary'],
            'isUnique' => (bool) $index[0]['index_is_unique'],
            'name' => $name,
            'columnNames' => ArrayHelper::getColumn($index, 'column_name'),
        ]);
    }
    return $result;
}

            
loadTablePrimaryKey() protected method

protected void loadTablePrimaryKey ( $tableName )
$tableName

                protected function loadTablePrimaryKey($tableName)
{
    return $this->loadTableConstraints($tableName, 'primaryKey');
}

            
loadTableSchema() protected method

載入指定表格的元數據。

protected yii\db\TableSchema|null loadTableSchema ( $name )
$name string

表格名稱

return yii\db\TableSchema|null

與 DBMS 相關的表格中繼資料,如果表格不存在,則為 null

                protected function loadTableSchema($name)
{
    $table = new TableSchema();
    $this->resolveTableNames($table, $name);
    if ($this->findColumns($table)) {
        $this->findConstraints($table);
        return $table;
    }
    return null;
}

            
loadTableUniques() protected method

protected void loadTableUniques ( $tableName )
$tableName

                protected function loadTableUniques($tableName)
{
    return $this->loadTableConstraints($tableName, 'uniques');
}

            
normalizePdoRowKeyCase() protected method (自版本 2.0.13 起可用)

定義於: yii\db\Schema::normalizePdoRowKeyCase()

如果 PDO 的陣列鍵大小寫設為大寫,則將資料列的陣列鍵大小寫變更為小寫。

protected array normalizePdoRowKeyCase ( array $row, $multiple )
$row array

資料列陣列或資料列陣列的陣列。

$multiple boolean

是否傳遞多個資料列或單個資料列。

return array

標準化的資料列或多個資料列。

                protected function normalizePdoRowKeyCase(array $row, $multiple)
{
    if ($this->db->getSlavePdo(true)->getAttribute(\PDO::ATTR_CASE) !== \PDO::CASE_UPPER) {
        return $row;
    }
    if ($multiple) {
        return array_map(function (array $row) {
            return array_change_key_case($row, CASE_LOWER);
        }, $row);
    }
    return array_change_key_case($row, CASE_LOWER);
}

            
quoteColumnName() public method

定義於: yii\db\Schema::quoteColumnName()

引用資料行名稱,以便在查詢中使用。

如果欄位名稱包含前綴,則前綴也會被正確地加上引號。如果欄位名稱已經加上引號或包含 '('、'[[' 或 '{{',則此方法將不會執行任何操作。

另請參閱 quoteSimpleColumnName()

public string quoteColumnName ( $name )
$name string

欄位名稱

return string

正確加上引號的欄位名稱

                public function quoteColumnName($name)
{
    if (strpos($name, '(') !== false || strpos($name, '[[') !== false) {
        return $name;
    }
    if (($pos = strrpos($name, '.')) !== false) {
        $prefix = $this->quoteTableName(substr($name, 0, $pos)) . '.';
        $name = substr($name, $pos + 1);
    } else {
        $prefix = '';
    }
    if (strpos($name, '{{') !== false) {
        return $name;
    }
    return $prefix . $this->quoteSimpleColumnName($name);
}

            
quoteSimpleColumnName() public method

定義於: yii\db\Schema::quoteSimpleColumnName()

引用簡單資料行名稱,以便在查詢中使用。

簡單欄位名稱應僅包含欄位名稱,不含任何前綴。如果欄位名稱已加上引號或是星號字元 '*',則此方法將不會執行任何操作。

public string quoteSimpleColumnName ( $name )
$name string

欄位名稱

return string

正確加上引號的欄位名稱

                public function quoteSimpleColumnName($name)
{
    if (is_string($this->columnQuoteCharacter)) {
        $startingCharacter = $endingCharacter = $this->columnQuoteCharacter;
    } else {
        list($startingCharacter, $endingCharacter) = $this->columnQuoteCharacter;
    }
    return $name === '*' || strpos($name, $startingCharacter) !== false ? $name : $startingCharacter . $name . $endingCharacter;
}

            
quoteSimpleTableName() public method

引用簡單表格名稱,以便在查詢中使用。

簡單表格名稱應僅包含表格名稱,不含任何結構描述前綴。如果表格名稱已加上引號,則此方法將不會執行任何操作。

public string quoteSimpleTableName ( $name )
$name string

表格名稱

return string

正確加上引號的表格名稱

                public function quoteSimpleTableName($name)
{
    return strpos($name, '"') !== false ? $name : '"' . $name . '"';
}

            
quoteTableName() public method

定義於: yii\db\Schema::quoteTableName()

引用表格名稱,以便在查詢中使用。

如果表格名稱包含結構描述前綴,則前綴也會被正確地加上引號。如果表格名稱已經加上引號或包含 '(' 或 '{{',則此方法將不會執行任何操作。

另請參閱 quoteSimpleTableName()

public string quoteTableName ( $name )
$name string

表格名稱

return string

正確加上引號的表格名稱

                public function quoteTableName($name)
{
    if (strncmp($name, '(', 1) === 0 && strpos($name, ')') === strlen($name) - 1) {
        return $name;
    }
    if (strpos($name, '{{') !== false) {
        return $name;
    }
    if (strpos($name, '.') === false) {
        return $this->quoteSimpleTableName($name);
    }
    $parts = $this->getTableNameParts($name);
    foreach ($parts as $i => $part) {
        $parts[$i] = $this->quoteSimpleTableName($part);
    }
    return implode('.', $parts);
}

            
quoteValue() public method

定義於: yii\db\Schema::quoteValue()

引用字串值,以便在查詢中使用。

請注意,如果參數不是字串,則會傳回而不做任何變更。

另請參閱 https://php.dev.org.tw/manual/en/function.PDO-quote.php

public string quoteValue ( $str )
$str string

要加上引號的字串

return string

正確加上引號的字串

                public function quoteValue($str)
{
    if (!is_string($str)) {
        return $str;
    }
    if (mb_stripos((string)$this->db->dsn, 'odbc:') === false && ($value = $this->db->getSlavePdo(true)->quote($str)) !== false) {
        return $value;
    }
    // the driver doesn't support quote (e.g. oci)
    return "'" . addcslashes(str_replace("'", "''", $str), "\000\n\r\\\032") . "'";
}

            
refresh() public method

定義於: yii\db\Schema::refresh()

重新整理結構描述。

此方法會清除所有快取的表格結構描述,以便稍後可以重新建立它們以反映資料庫結構描述的變更。

public void refresh ( )

                public function refresh()
{
    /* @var $cache CacheInterface */
    $cache = is_string($this->db->schemaCache) ? Yii::$app->get($this->db->schemaCache, false) : $this->db->schemaCache;
    if ($this->db->enableSchemaCache && $cache instanceof CacheInterface) {
        TagDependency::invalidate($cache, $this->getCacheTag());
    }
    $this->_tableNames = [];
    $this->_tableMetadata = [];
}

            
refreshTableSchema() public method (自版本 2.0.6 起可用)

定義於: yii\db\Schema::refreshTableSchema()

重新整理特定表格結構描述。

此方法會清除快取的表格結構描述,以便稍後可以重新建立它以反映資料庫結構描述的變更。

public void refreshTableSchema ( $name )
$name string

表格名稱。

                public function refreshTableSchema($name)
{
    $rawName = $this->getRawTableName($name);
    unset($this->_tableMetadata[$rawName]);
    $this->_tableNames = [];
    /* @var $cache CacheInterface */
    $cache = is_string($this->db->schemaCache) ? Yii::$app->get($this->db->schemaCache, false) : $this->db->schemaCache;
    if ($this->db->enableSchemaCache && $cache instanceof CacheInterface) {
        $cache->delete($this->getCacheKey($rawName));
    }
}

            
releaseSavepoint() public method

釋放現有的儲存點。

public void releaseSavepoint ( $name )
$name string

儲存點名稱

                public function releaseSavepoint($name)
{
    // does nothing as Oracle does not support this
}

            
resolveTableName() protected method (自版本 2.0.13 起可用)

解析表格名稱和結構描述名稱(如果有的話)。

protected yii\db\TableSchema resolveTableName ( $name )
$name string

表格名稱

return yii\db\TableSchema

具有已解析表格、結構描述等名稱的 yii\db\TableSchema

throws yii\base\NotSupportedException

如果 DBMS 不支援此方法。

                protected function resolveTableName($name)
{
    $resolvedName = new TableSchema();
    $parts = explode('.', str_replace('"', '', $name));
    if (isset($parts[1])) {
        $resolvedName->schemaName = $parts[0];
        $resolvedName->name = $parts[1];
    } else {
        $resolvedName->schemaName = $this->defaultSchema;
        $resolvedName->name = $name;
    }
    $resolvedName->fullName = ($resolvedName->schemaName !== $this->defaultSchema ? $resolvedName->schemaName . '.' : '') . $resolvedName->name;
    return $resolvedName;
}

            
resolveTableNames() protected method

解析表格名稱和結構描述名稱(如果有的話)。

protected void resolveTableNames ( $table, $name )
$table yii\db\TableSchema

表格中繼資料物件

$name string

表格名稱

                protected function resolveTableNames($table, $name)
{
    $parts = explode('.', str_replace('"', '', $name));
    if (isset($parts[1])) {
        $table->schemaName = $parts[0];
        $table->name = $parts[1];
    } else {
        $table->schemaName = $this->defaultSchema;
        $table->name = $name;
    }
    $table->fullName = $table->schemaName !== $this->defaultSchema ? $table->schemaName . '.' . $table->name : $table->name;
}

            
rollBackSavepoint() public method

定義於: yii\db\Schema::rollBackSavepoint()

回滾到先前建立的儲存點。

public void rollBackSavepoint ( $name )
$name string

儲存點名稱

                public function rollBackSavepoint($name)
{
    $this->db->createCommand("ROLLBACK TO SAVEPOINT $name")->execute();
}

            
setTableMetadata() protected method (自版本 2.0.13 起可用)

定義於: yii\db\Schema::setTableMetadata()

設定給定表格的給定類型元數據。

protected void setTableMetadata ( $name, $type, $data )
$name string

表格名稱。

$type string

中繼資料型別。

$data mixed

中繼資料。

                protected function setTableMetadata($name, $type, $data)
{
    $this->_tableMetadata[$this->getRawTableName($name)][$type] = $data;
}

            
setTransactionIsolationLevel() public method
public void setTransactionIsolationLevel ( $level )
$level string

此交易要使用的交易隔離等級。這可以是 yii\db\Transaction::READ_UNCOMMITTEDyii\db\Transaction::READ_COMMITTEDyii\db\Transaction::REPEATABLE_READyii\db\Transaction::SERIALIZABLE 的其中之一,也可以是包含 DBMS 特定語法的字串,用於 SET TRANSACTION ISOLATION LEVEL 之後。

                public function setTransactionIsolationLevel($level)
{
    $this->db->createCommand("SET TRANSACTION ISOLATION LEVEL $level")->execute();
}

            
supportsSavepoint() public method
public boolean supportsSavepoint ( )
return boolean

此 DBMS 是否支援儲存點

                public function supportsSavepoint()
{
    return $this->db->enableSavepoint;
}

            
unquoteSimpleColumnName() public method (自版本 2.0.14 起可用)

定義於: yii\db\Schema::unquoteSimpleColumnName()

取消引用簡單資料行名稱。

簡單欄位名稱應僅包含欄位名稱,不含任何前綴。如果欄位名稱未加上引號或是星號字元 '*',則此方法將不會執行任何操作。

public string unquoteSimpleColumnName ( $name )
$name string

欄位名稱。

return string

未加上引號的欄位名稱。

                public function unquoteSimpleColumnName($name)
{
    if (is_string($this->columnQuoteCharacter)) {
        $startingCharacter = $this->columnQuoteCharacter;
    } else {
        $startingCharacter = $this->columnQuoteCharacter[0];
    }
    return strpos($name, $startingCharacter) === false ? $name : substr($name, 1, -1);
}

            
unquoteSimpleTableName() public method (自版本 2.0.14 起可用)

定義於: yii\db\Schema::unquoteSimpleTableName()

取消引用簡單表格名稱。

簡單表格名稱應僅包含表格名稱,不含任何結構描述前綴。如果表格名稱未加上引號,則此方法將不會執行任何操作。

public string unquoteSimpleTableName ( $name )
$name string

表格名稱。

return string

未加上引號的表格名稱。

                public function unquoteSimpleTableName($name)
{
    if (is_string($this->tableQuoteCharacter)) {
        $startingCharacter = $this->tableQuoteCharacter;
    } else {
        $startingCharacter = $this->tableQuoteCharacter[0];
    }
    return strpos($name, $startingCharacter) === false ? $name : substr($name, 1, -1);
}