PHP Класс yii\db\Schema

Schema represents the database schema information that is DBMS specific.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends yii\base\Object
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$columnSchemaClass column schema class
$db the database connection
$defaultSchema the default schema name used for the current session.
$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.

Открытые методы

Метод Описание
convertException ( Exception $e, string $rawSql ) : Exception Converts a DB exception to a more concrete one if possible.
createColumnSchemaBuilder ( string $type, integer | string | array $length = null ) : ColumnSchemaBuilder Create a column schema builder instance giving the type and value precision.
createQueryBuilder ( ) : QueryBuilder Creates a query builder for the database.
createSavepoint ( string $name ) Creates a new savepoint.
findUniqueIndexes ( yii\db\TableSchema $table ) : array Returns all unique indexes for the given table.
getLastInsertID ( string $sequenceName = '' ) : string Returns the ID of the last inserted row or sequence value.
getPdoType ( mixed $data ) : integer Determines the PDO type for the given PHP data value.
getQueryBuilder ( ) : QueryBuilder
getRawTableName ( string $name ) : string Returns the actual name of a given table name.
getSchemaNames ( boolean $refresh = false ) : string[] Returns all schema names in the database, except system schemas.
getTableNames ( string $schema = '', boolean $refresh = false ) : string[] Returns all table names in the database.
getTableSchema ( string $name, boolean $refresh = false ) : null | yii\db\TableSchema Obtains the metadata for the named table.
getTableSchemas ( string $schema = '', boolean $refresh = false ) : yii\db\TableSchema[] Returns the metadata for all tables in the database.
insert ( string $table, array $columns ) : array | false Executes the INSERT command, returning primary key values.
isReadQuery ( string $sql ) : boolean Returns a value indicating whether a SQL statement is for read purpose.
quoteColumnName ( string $name ) : string Quotes a column name for use in a query.
quoteSimpleColumnName ( string $name ) : string Quotes a simple column name for use in a query.
quoteSimpleTableName ( string $name ) : string Quotes a simple table name for use in a query.
quoteTableName ( string $name ) : string Quotes a table name for use in a query.
quoteValue ( string $str ) : string Quotes a string value for use in a query.
refresh ( ) Refreshes the schema.
refreshTableSchema ( string $name ) Refreshes the particular table schema.
releaseSavepoint ( string $name ) Releases an existing savepoint.
rollBackSavepoint ( string $name ) Rolls back to a previously created savepoint.
setTransactionIsolationLevel ( string $level ) Sets the isolation level of the current transaction.
supportsSavepoint ( ) : boolean

Защищенные методы

Метод Описание
createColumnSchema ( ) : ColumnSchema
findSchemaNames ( ) : array Returns all schema names in the database, including the default one but not system schemas.
findTableNames ( string $schema = '' ) : array Returns all table names in the database.
getCacheKey ( string $name ) : mixed Returns the cache key for the specified table name.
getCacheTag ( ) : string Returns the cache tag name.
getColumnPhpType ( ColumnSchema $column ) : string Extracts the PHP type from abstract DB type.
loadTableSchema ( string $name ) : null | yii\db\TableSchema Loads the metadata for the specified table.

Описание методов

convertException() публичный Метод

Converts a DB exception to a more concrete one if possible.
public convertException ( Exception $e, string $rawSql ) : Exception
$e Exception
$rawSql string SQL that produced exception
Результат Exception

createColumnSchema() защищенный Метод

protected createColumnSchema ( ) : ColumnSchema
Результат ColumnSchema

createColumnSchemaBuilder() публичный Метод

This method may be overridden by child classes to create a DBMS-specific column schema builder.
С версии: 2.0.6
public createColumnSchemaBuilder ( string $type, integer | string | array $length = null ) : ColumnSchemaBuilder
$type string type of the column. See [[ColumnSchemaBuilder::$type]].
$length integer | string | array length or precision of the column. See [[ColumnSchemaBuilder::$length]].
Результат ColumnSchemaBuilder column schema builder instance

createQueryBuilder() публичный Метод

This method may be overridden by child classes to create a DBMS-specific query builder.
public createQueryBuilder ( ) : QueryBuilder
Результат QueryBuilder query builder instance

createSavepoint() публичный Метод

Creates a new savepoint.
public createSavepoint ( string $name )
$name string the savepoint name

findSchemaNames() защищенный Метод

This method should be overridden by child classes in order to support this feature because the default implementation simply throws an exception.
С версии: 2.0.4
protected findSchemaNames ( ) : array
Результат array all schema names in the database, except system schemas

findTableNames() защищенный Метод

This method should be overridden by child classes in order to support this feature because the default implementation simply throws an exception.
protected findTableNames ( string $schema = '' ) : array
$schema string the schema of the tables. Defaults to empty string, meaning the current or default schema.
Результат array all table names in the database. The names have NO schema name prefix.

findUniqueIndexes() публичный Метод

Each array element is of the following structure: php [ '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 findUniqueIndexes ( yii\db\TableSchema $table ) : array
$table yii\db\TableSchema the table metadata
Результат array all unique indexes for the given table.

getCacheKey() защищенный Метод

Returns the cache key for the specified table name.
protected getCacheKey ( string $name ) : mixed
$name string the table name
Результат mixed the cache key

getCacheTag() защищенный Метод

This allows Schema::refresh to invalidate all cached table schemas.
protected getCacheTag ( ) : string
Результат string the cache tag name

getColumnPhpType() защищенный Метод

Extracts the PHP type from abstract DB type.
protected getColumnPhpType ( ColumnSchema $column ) : string
$column ColumnSchema the column schema information
Результат 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 getLastInsertID ( string $sequenceName = '' ) : string
$sequenceName string name of the sequence object (required by some DBMS)
Результат string the row ID of the last row inserted, or the last value retrieved from the sequence object

getPdoType() публичный Метод

Determines the PDO type for the given PHP data value.
См. также: http://www.php.net/manual/en/pdo.constants.php
public getPdoType ( mixed $data ) : integer
$data mixed the data whose PDO type is to be determined
Результат integer the PDO type

getQueryBuilder() публичный Метод

public getQueryBuilder ( ) : QueryBuilder
Результат QueryBuilder the query builder for this connection.

getRawTableName() публичный Метод

This method will strip off curly brackets from the given table name and replace the percentage character '%' with [[Connection::tablePrefix]].
public getRawTableName ( string $name ) : string
$name string the table name to be converted
Результат string the real name of the given table name

getSchemaNames() публичный Метод

Returns all schema names in the database, except system schemas.
С версии: 2.0.4
public getSchemaNames ( boolean $refresh = false ) : string[]
$refresh boolean whether to fetch the latest available schema names. If this is false, schema names fetched previously (if available) will be returned.
Результат string[] all schema names in the database, except system schemas.

getTableNames() публичный Метод

Returns all table names in the database.
public getTableNames ( string $schema = '', boolean $refresh = false ) : string[]
$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.
Результат string[] all table names in the database.

getTableSchema() публичный Метод

Obtains the metadata for the named table.
public getTableSchema ( string $name, boolean $refresh = false ) : null | yii\db\TableSchema
$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.
Результат null | yii\db\TableSchema table metadata. Null if the named table does not exist.

getTableSchemas() публичный Метод

Returns the metadata for all tables in the database.
public getTableSchemas ( string $schema = '', boolean $refresh = false ) : yii\db\TableSchema[]
$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.
Результат yii\db\TableSchema[] the metadata for all tables in the database. Each array element is an instance of [[TableSchema]] or its child class.

insert() публичный Метод

Executes the INSERT command, returning primary key values.
С версии: 2.0.4
public insert ( string $table, array $columns ) : array | false
$table string the table that new rows will be inserted into.
$columns array the column data (name => value) to be inserted into the table.
Результат 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 isReadQuery ( string $sql ) : boolean
$sql string the SQL statement
Результат boolean whether a SQL statement is for read purpose.

loadTableSchema() абстрактный защищенный Метод

Loads the metadata for the specified table.
abstract protected loadTableSchema ( string $name ) : null | yii\db\TableSchema
$name string table name
Результат null | yii\db\TableSchema DBMS-dependent table metadata, null if the table does not exist.

quoteColumnName() публичный Метод

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 quoteColumnName ( string $name ) : string
$name string column name
Результат string the properly quoted column name

quoteSimpleColumnName() публичный Метод

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 quoteSimpleColumnName ( string $name ) : string
$name string column name
Результат string the properly quoted column name

quoteSimpleTableName() публичный Метод

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 quoteSimpleTableName ( string $name ) : string
$name string table name
Результат string the properly quoted table name

quoteTableName() публичный Метод

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 quoteTableName ( string $name ) : string
$name string table name
Результат string the properly quoted table name

quoteValue() публичный Метод

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 quoteValue ( string $str ) : string
$str string string to be quoted
Результат string the properly quoted string

refresh() публичный Метод

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

refreshTableSchema() публичный Метод

This method cleans up cached table schema so that it can be re-created later to reflect the database schema change.
С версии: 2.0.6
public refreshTableSchema ( string $name )
$name string table name.

releaseSavepoint() публичный Метод

Releases an existing savepoint.
public releaseSavepoint ( string $name )
$name string the savepoint name

rollBackSavepoint() публичный Метод

Rolls back to a previously created savepoint.
public rollBackSavepoint ( string $name )
$name string the savepoint name

setTransactionIsolationLevel() публичный Метод

Sets the isolation level of the current transaction.
См. также: http://en.wikipedia.org/wiki/Isolation_%28database_systems%29#Isolation_levels
public setTransactionIsolationLevel ( string $level )
$level string The transaction isolation level to use for this transaction. This can be one of [[Transaction::READ_UNCOMMITTED]], [[Transaction::READ_COMMITTED]], [[Transaction::REPEATABLE_READ]] and [[Transaction::SERIALIZABLE]] but also a string containing DBMS specific syntax to be used after `SET TRANSACTION ISOLATION LEVEL`.

supportsSavepoint() публичный Метод

public supportsSavepoint ( ) : boolean
Результат boolean whether this DBMS supports [savepoint](http://en.wikipedia.org/wiki/Savepoint).

Описание свойств

$columnSchemaClass публичное свойство

column schema class
С версии: 2.0.11
public $columnSchemaClass

$db публичное свойство

the database connection
public $db

$defaultSchema публичное свойство

the default schema name used for the current session.
public $defaultSchema

$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 $exceptionMap