没有命名空间的类 yii yii\base yii\behaviors yii\caching yii\captcha yii\console yii\console\controllers yii\console\widgets yii\data yii\db yii\db\conditions yii\db\cubrid yii\db\cubrid\conditions yii\db\mssql yii\db\mssql\conditions yii\db\mysql yii\db\oci yii\db\oci\conditions yii\db\pgsql yii\db\sqlite yii\db\sqlite\conditions yii\di yii\filters yii\filters\auth yii\grid yii\helpers yii\i18n yii\log yii\mail yii\mutex yii\rbac yii\rest yii\test yii\validators yii\web yii\widgets

Abstract Class yii\db\Schema

继承yii\db\Schema » yii\base\BaseObject
实现yii\base\Configurable
子类yii\db\cubrid\Schema, yii\db\mssql\Schema, yii\db\mysql\Schema, yii\db\oci\Schema, yii\db\pgsql\Schema, yii\db\sqlite\Schema
可用版本自2.0
源码 https://github.com/yiichina/yii2/blob/api/framework/db/Schema.php

Schema is the base class for concrete DBMS-specific schema classes.

Schema represents the database schema information that is DBMS specific.

公共属性

隐藏继承的属性

属性类型描述被定义在
$columnSchemaClass string|array Column schema class or class config yii\db\Schema
$db yii\db\Connection The database connection yii\db\Schema
$defaultSchema string The default schema name used for the current session. yii\db\Schema
$exceptionMap array Map of DB errors and corresponding exceptions If left part is found in DB error message exception class from the right part is used. yii\db\Schema
$lastInsertID string The row ID of the last row inserted, or the last value retrieved from the sequence object yii\db\Schema
$queryBuilder yii\db\QueryBuilder The query builder for this connection. yii\db\Schema
$schemaNames string[] All schema names in the database, except system schemas. yii\db\Schema
$serverVersion string Server version as a string. yii\db\Schema
$tableNames string[] All table names in the database. yii\db\Schema
$tableSchemas yii\db\TableSchema[] The metadata for all tables in the database. yii\db\Schema
$transactionIsolationLevel string The transaction isolation level to use for this transaction. yii\db\Schema

受保护的属性

隐藏继承的属性

属性类型描述被定义在
$columnQuoteCharacter string|string[] Character used to quote column names. yii\db\Schema
$tableQuoteCharacter string|string[] Character used to quote schema, table, etc. yii\db\Schema

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
convertException() Converts a DB exception to a more concrete one if possible. yii\db\Schema
createColumnSchemaBuilder() Create a column schema builder instance giving the type and value precision. yii\db\Schema
createQueryBuilder() Creates a query builder for the database. yii\db\Schema
createSavepoint() Creates a new savepoint. yii\db\Schema
findUniqueIndexes() Returns all unique indexes for the given table. yii\db\Schema
getLastInsertID() Returns the ID of the last inserted row or sequence value. yii\db\Schema
getPdoType() Determines the PDO type for the given PHP data value. yii\db\Schema
getQueryBuilder() yii\db\Schema
getRawTableName() Returns the actual name of a given table name. yii\db\Schema
getSchemaNames() Returns all schema names in the database, except system schemas. yii\db\Schema
getServerVersion() Returns a server version as a string comparable by \version_compare(). yii\db\Schema
getTableNames() Returns all table names in the database. yii\db\Schema
getTableSchema() Obtains the metadata for the named table. yii\db\Schema
getTableSchemas() Returns the metadata for all tables in the database. yii\db\Schema
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject
insert() Executes the INSERT command, returning primary key values. yii\db\Schema
isReadQuery() Returns a value indicating whether a SQL statement is for read purpose. yii\db\Schema
quoteColumnName() Quotes a column name for use in a query. yii\db\Schema
quoteSimpleColumnName() Quotes a simple column name for use in a query. yii\db\Schema
quoteSimpleTableName() Quotes a simple table name for use in a query. yii\db\Schema
quoteTableName() Quotes a table name for use in a query. yii\db\Schema
quoteValue() Quotes a string value for use in a query. yii\db\Schema
refresh() Refreshes the schema. yii\db\Schema
refreshTableSchema() Refreshes the particular table schema. yii\db\Schema
releaseSavepoint() Releases an existing savepoint. yii\db\Schema
rollBackSavepoint() Rolls back to a previously created savepoint. yii\db\Schema
setTransactionIsolationLevel() Sets the isolation level of the current transaction. yii\db\Schema
supportsSavepoint() yii\db\Schema
unquoteSimpleColumnName() Unquotes a simple column name. yii\db\Schema
unquoteSimpleTableName() Unquotes a simple table name. yii\db\Schema

受保护的方法

隐藏继承的方法

方法描述被定义在
createColumnSchema() Creates a column schema for the database. yii\db\Schema
findSchemaNames() Returns all schema names in the database, including the default one but not system schemas. yii\db\Schema
findTableNames() Returns all table names in the database. yii\db\Schema
getCacheKey() Returns the cache key for the specified table name. yii\db\Schema
getCacheTag() Returns the cache tag name. yii\db\Schema
getColumnPhpType() Extracts the PHP type from abstract DB type. yii\db\Schema
getSchemaMetadata() Returns the metadata of the given type for all tables in the given schema. yii\db\Schema
getTableMetadata() Returns the metadata of the given type for the given table. yii\db\Schema
loadTableSchema() Loads the metadata for the specified table. yii\db\Schema
normalizePdoRowKeyCase() Changes row's array key case to lower if PDO's one is set to uppercase. yii\db\Schema
resolveTableName() Resolves the table name and schema name (if any). yii\db\Schema
setTableMetadata() Sets the metadata of the given type for the given table. yii\db\Schema

常量

隐藏继承的常量

常量描述被定义在
SCHEMA_CACHE_VERSION 1 Schema cache version, to detect incompatibilities in cached values when the data format of the cache changes. 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

属性详情

$columnQuoteCharacter 受保护 属性 (自版本 2.0.14 可用)

Character used to quote column names. An array of 2 characters can be used in case starting and ending characters are different.

$columnSchemaClass 公共 属性 (自版本 2.0.11 可用)

Column schema class or class config

public string|array $columnSchemaClass 'yii\db\ColumnSchema'
$db 公共 属性

The database connection

public yii\db\Connection $db null
$defaultSchema 公共 属性

The default schema name used for the current session.

public string $defaultSchema null
$exceptionMap 公共 属性

Map of DB errors and corresponding exceptions If left part is found in DB error message exception class from the right part is used.

public array $exceptionMap = ['SQLSTATE[23' => 'yii\db\IntegrityException']
$lastInsertID 公共 只读 属性

The row ID of the last row inserted, or the last value retrieved from the sequence object

public string getLastInsertID ( $sequenceName '' )
$queryBuilder 公共 只读 属性

The query builder for this connection.

$schemaNames 公共 只读 属性

All schema names in the database, except system schemas.

public string[] getSchemaNames ( $refresh false )
$serverVersion 公共 只读 属性

Server version as a string.

$tableNames 公共 只读 属性

All table names in the database.

public string[] getTableNames ( $schema '', $refresh false )
$tableQuoteCharacter 受保护 属性 (自版本 2.0.14 可用)

Character used to quote schema, table, etc. names. An array of 2 characters can be used in case starting and ending characters are different.

$tableSchemas 公共 只读 属性

The metadata for all tables in the database. Each array element is an instance of yii\db\TableSchema or its child class.

public yii\db\TableSchema[] getTableSchemas ( $schema '', $refresh false )
$transactionIsolationLevel 公共 只写 属性

The transaction isolation level to use for this transaction. This can be one of yii\db\Transaction::READ_UNCOMMITTED, yii\db\Transaction::READ_COMMITTED, yii\db\Transaction::REPEATABLE_READ and yii\db\Transaction::SERIALIZABLE but also a string containing DBMS specific syntax to be used after SET TRANSACTION ISOLATION LEVEL.

public void setTransactionIsolationLevel ( $level )

方法详情

convertException() 公共 方法

Converts a DB exception to a more concrete one if possible.

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

SQL that produced exception

createColumnSchema() 受保护 方法

Creates a column schema for the database.

This method may be overridden by child classes to create a DBMS-specific column schema.

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

Column schema instance.

throws yii\base\InvalidConfigException

if a column schema class cannot be created.

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

Create a column schema builder instance giving the type and value precision.

This method may be overridden by child classes to create a DBMS-specific column schema builder.

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

Type of the column. See yii\db\ColumnSchemaBuilder::$type.

$length integer|string|array

Length or precision of the column. See yii\db\ColumnSchemaBuilder::$length.

return yii\db\ColumnSchemaBuilder

Column schema builder instance

createQueryBuilder() 公共 方法

Creates a query builder for the database.

This method may be overridden by child classes to create a DBMS-specific query builder.

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

Query builder instance

createSavepoint() 公共 方法

Creates a new savepoint.

public void createSavepoint($name)
$name string

The savepoint name

findSchemaNames() 受保护 方法 (自版本 2.0.4 可用)

Returns all schema names in the database, including the default one but not system schemas.

This method should be overridden by child classes in order to support this feature because the default implementation simply throws an exception.

protected array findSchemaNames()
return array

All schema names in the database, except system schemas.

throws yii\base\NotSupportedException

if this method is not supported by the DBMS.

findTableNames() 受保护 方法

Returns all table names in the database.

This method should be overridden by child classes in order to support this feature because the default implementation simply throws an exception.

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

The schema of the tables. Defaults to empty string, meaning the current or default schema.

return array

All table names in the database. The names have NO schema name prefix.

throws yii\base\NotSupportedException

if this method is not supported by the DBMS.

findUniqueIndexes() 公共 方法

Returns all unique indexes for the given table.

Each array element is of the following structure:

[
 'IndexName1' => ['col1' [, ...]],
 'IndexName2' => ['col2' [, ...]],
]

This method should be overridden by child classes in order to support this feature because the default implementation simply throws an exception

public array findUniqueIndexes($table)
$table yii\db\TableSchema

The table metadata

return array

All unique indexes for the given table.

throws yii\base\NotSupportedException

if this method is called

getCacheKey() 受保护 方法

Returns the cache key for the specified table name.

protected mixed getCacheKey($name)
$name string

The table name.

return mixed

The cache key.

getCacheTag() 受保护 方法

Returns the cache tag name.

This allows refresh() to invalidate all cached table schemas.

protected string getCacheTag()
return string

The cache tag name

getColumnPhpType() 受保护 方法

Extracts the PHP type from abstract DB type.

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

The column schema information

return string

PHP type name

getLastInsertID() 公共 方法

Returns the ID of the last inserted row or sequence value.

参见 http://www.php.net/manual/en/function.PDO-lastInsertId.php.

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

Name of the sequence object (required by some DBMS)

return string

The row ID of the last row inserted, or the last value retrieved from the sequence object

throws yii\base\InvalidCallException

if the DB connection is not active

getPdoType() 公共 方法

Determines the PDO type for the given PHP data value.

参见 http://www.php.net/manual/en/pdo.constants.php.

public integer getPdoType($data)
$data mixed

The data whose PDO type is to be determined

return integer

The PDO type

getQueryBuilder() 公共 方法

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

The query builder for this connection.

getRawTableName() 公共 方法

Returns the actual name of a given table name.

This method will strip off curly brackets from the given table name and replace the percentage character '%' with yii\db\Connection::$tablePrefix.

public string getRawTableName($name)
$name string

The table name to be converted

return string

The real name of the given table name

getSchemaMetadata() 受保护 方法 (自版本 2.0.13 可用)

Returns the metadata of the given type for all tables in the given schema.

This method will call a 'getTable' . ucfirst($type) named method with the table name and the refresh flag to obtain the metadata.

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

The schema of the metadata. Defaults to empty string, meaning the current or default schema name.

$type string

Metadata type.

$refresh boolean

Whether to fetch the latest available table metadata. If this is false, cached data may be returned if available.

return array

Array of metadata.

getSchemaNames() 公共 方法 (自版本 2.0.4 可用)

Returns all schema names in the database, except system schemas.

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

Whether to fetch the latest available schema names. If this is false, schema names fetched previously (if available) will be returned.

return string[]

All schema names in the database, except system schemas.

getServerVersion() 公共 方法 (自版本 2.0.14 可用)

Returns a server version as a string comparable by \version_compare().

public string getServerVersion()
return string

Server version as a string.

getTableMetadata() 受保护 方法 (自版本 2.0.13 可用)

Returns the metadata of the given type for the given table.

If there's no metadata in the cache, this method will call a 'loadTable' . ucfirst($type) named method with the table name to obtain the metadata.

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

Table name. The table name may contain schema name if any. Do not quote the table name.

$type string

Metadata type.

$refresh boolean

Whether to reload the table metadata even if it is found in the cache.

return mixed

Metadata.

getTableNames() 公共 方法

Returns all table names in the database.

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

The schema of the tables. Defaults to empty string, meaning the current or default schema name. If not empty, the returned table names will be prefixed with the schema name.

$refresh boolean

Whether to fetch the latest available table names. If this is false, table names fetched previously (if available) will be returned.

return string[]

All table names in the database.

getTableSchema() 公共 方法

Obtains the metadata for the named table.

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

Table name. The table name may contain schema name if any. Do not quote the table name.

$refresh boolean

Whether to reload the table schema even if it is found in the cache.

return yii\db\TableSchema|null

Table metadata. null if the named table does not exist.

getTableSchemas() 公共 方法

Returns the metadata for all tables in the database.

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

The schema of the tables. Defaults to empty string, meaning the current or default schema name.

$refresh boolean

Whether to fetch the latest available table schemas. If this is false, cached data may be returned if available.

return yii\db\TableSchema[]

The metadata for all tables in the database. Each array element is an instance of yii\db\TableSchema or its child class.

insert() 公共 方法 (自版本 2.0.4 可用)

Executes the INSERT command, returning primary key values.

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

The table that new rows will be inserted into.

$columns array

The column data (name => value) to be inserted into the table.

return array|false

Primary key values or false if the command fails

isReadQuery() 公共 方法

Returns a value indicating whether a SQL statement is for read purpose.

public boolean isReadQuery($sql)
$sql string

The SQL statement

return boolean

Whether a SQL statement is for read purpose.

loadTableSchema() 受保护 抽象 方法

Loads the metadata for the specified table.

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

Table name

return yii\db\TableSchema|null

DBMS-dependent table metadata, null if the table does not exist.

normalizePdoRowKeyCase() 受保护 方法 (自版本 2.0.13 可用)

Changes row's array key case to lower if PDO's one is set to uppercase.

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

Row's array or an array of row's arrays.

$multiple boolean

Whether multiple rows or a single row passed.

return array

Normalized row or rows.

quoteColumnName() 公共 方法

Quotes a column name for use in a query.

If the column name contains prefix, the prefix will also be properly quoted. If the column name is already quoted or contains '(', '[[' or '{{', then this method will do nothing.

参见 quoteSimpleColumnName().

public string quoteColumnName($name)
$name string

Column name

return string

The properly quoted column name

quoteSimpleColumnName() 公共 方法

Quotes a simple column name for use in a query.

A simple column name should contain the column name only without any prefix. If the column name is already quoted or is the asterisk character '*', this method will do nothing.

public string quoteSimpleColumnName($name)
$name string

Column name

return string

The properly quoted column name

quoteSimpleTableName() 公共 方法

Quotes a simple table name for use in a query.

A simple table name should contain the table name only without any schema prefix. If the table name is already quoted, this method will do nothing.

public string quoteSimpleTableName($name)
$name string

Table name

return string

The properly quoted table name

quoteTableName() 公共 方法

Quotes a table name for use in a query.

If the table name contains schema prefix, the prefix will also be properly quoted. If the table name is already quoted or contains '(' or '{{', then this method will do nothing.

参见 quoteSimpleTableName().

public string quoteTableName($name)
$name string

Table name

return string

The properly quoted table name

quoteValue() 公共 方法

Quotes a string value for use in a query.

Note that if the parameter is not a string, it will be returned without change.

参见 http://www.php.net/manual/en/function.PDO-quote.php.

public string quoteValue($str)
$str string

String to be quoted

return string

The properly quoted string

refresh() 公共 方法

Refreshes the schema.

This method cleans up all cached table schemas so that they can be re-created later to reflect the database schema change.

public void refresh()
refreshTableSchema() 公共 方法 (自版本 2.0.6 可用)

Refreshes the particular table schema.

This method cleans up cached table schema so that it can be re-created later to reflect the database schema change.

public void refreshTableSchema($name)
$name string

Table name.

releaseSavepoint() 公共 方法

Releases an existing savepoint.

public void releaseSavepoint($name)
$name string

The savepoint name

resolveTableName() 受保护 方法 (自版本 2.0.13 可用)

Resolves the table name and schema name (if any).

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

The table name

return yii\db\TableSchema

yii\db\TableSchema with resolved table, schema, etc. names.

throws yii\base\NotSupportedException

if this method is not supported by the DBMS.

rollBackSavepoint() 公共 方法

Rolls back to a previously created savepoint.

public void rollBackSavepoint($name)
$name string

The savepoint name

setTableMetadata() 受保护 方法 (自版本 2.0.13 可用)

Sets the metadata of the given type for the given table.

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

Table name.

$type string

Metadata type.

$data mixed

Metadata.

setTransactionIsolationLevel() 公共 方法

Sets the isolation level of the current transaction.

参见 http://en.wikipedia.org/wiki/Isolation_(database_systems)#Isolation_levels.

public void setTransactionIsolationLevel($level)
$level string

The transaction isolation level to use for this transaction. This can be one of yii\db\Transaction::READ_UNCOMMITTED, yii\db\Transaction::READ_COMMITTED, yii\db\Transaction::REPEATABLE_READ and yii\db\Transaction::SERIALIZABLE but also a string containing DBMS specific syntax to be used after SET TRANSACTION ISOLATION LEVEL.

supportsSavepoint() 公共 方法

public boolean supportsSavepoint()
return boolean

Whether this DBMS supports savepoint.

unquoteSimpleColumnName() 公共 方法 (自版本 2.0.14 可用)

Unquotes a simple column name.

A simple column name should contain the column name only without any prefix. If the column name is not quoted or is the asterisk character '*', this method will do nothing.

public string unquoteSimpleColumnName($name)
$name string

Column name.

return string

Unquoted column name.

unquoteSimpleTableName() 公共 方法 (自版本 2.0.14 可用)

Unquotes a simple table name.

A simple table name should contain the table name only without any schema prefix. If the table name is not quoted, this method will do nothing.

public string unquoteSimpleTableName($name)
$name string

Table name.

return string

Unquoted table name.