PHP Class yii\db\Schema

Schema represents the database schema information that is DBMS specific.
Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends yii\base\Object
Afficher le fichier Open project: yiisoft/yii2 Class Usage Examples

Méthodes publiques

Свойство Type Description
$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.

Méthodes publiques

Méthode Description
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

Méthodes protégées

Méthode Description
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.

Method Details

convertException() public méthode

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
Résultat Exception

createColumnSchema() protected méthode

protected createColumnSchema ( ) : ColumnSchema
Résultat ColumnSchema

createColumnSchemaBuilder() public méthode

This method may be overridden by child classes to create a DBMS-specific column schema builder.
Since: 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]].
Résultat ColumnSchemaBuilder column schema builder instance

createQueryBuilder() public méthode

This method may be overridden by child classes to create a DBMS-specific query builder.
public createQueryBuilder ( ) : QueryBuilder
Résultat QueryBuilder query builder instance

createSavepoint() public méthode

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

findSchemaNames() protected méthode

This method should be overridden by child classes in order to support this feature because the default implementation simply throws an exception.
Since: 2.0.4
protected findSchemaNames ( ) : array
Résultat array all schema names in the database, except system schemas

findTableNames() protected méthode

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.
Résultat array all table names in the database. The names have NO schema name prefix.

findUniqueIndexes() public méthode

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
Résultat array all unique indexes for the given table.

getCacheKey() protected méthode

Returns the cache key for the specified table name.
protected getCacheKey ( string $name ) : mixed
$name string the table name
Résultat mixed the cache key

getCacheTag() protected méthode

This allows Schema::refresh to invalidate all cached table schemas.
protected getCacheTag ( ) : string
Résultat string the cache tag name

getColumnPhpType() protected méthode

Extracts the PHP type from abstract DB type.
protected getColumnPhpType ( ColumnSchema $column ) : string
$column ColumnSchema the column schema information
Résultat string PHP type name

getLastInsertID() public méthode

Returns the ID of the last inserted row or sequence value.
See also: 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)
Résultat string the row ID of the last row inserted, or the last value retrieved from the sequence object

getPdoType() public méthode

Determines the PDO type for the given PHP data value.
See also: 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
Résultat integer the PDO type

getQueryBuilder() public méthode

public getQueryBuilder ( ) : QueryBuilder
Résultat QueryBuilder the query builder for this connection.

getRawTableName() public méthode

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
Résultat string the real name of the given table name

getSchemaNames() public méthode

Returns all schema names in the database, except system schemas.
Since: 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.
Résultat string[] all schema names in the database, except system schemas.

getTableNames() public méthode

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.
Résultat string[] all table names in the database.

getTableSchema() public méthode

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.
Résultat null | yii\db\TableSchema table metadata. Null if the named table does not exist.

getTableSchemas() public méthode

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.
Résultat yii\db\TableSchema[] the metadata for all tables in the database. Each array element is an instance of [[TableSchema]] or its child class.

insert() public méthode

Executes the INSERT command, returning primary key values.
Since: 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.
Résultat array | false primary key values or false if the command fails

isReadQuery() public méthode

Returns a value indicating whether a SQL statement is for read purpose.
public isReadQuery ( string $sql ) : boolean
$sql string the SQL statement
Résultat boolean whether a SQL statement is for read purpose.

loadTableSchema() abstract protected méthode

Loads the metadata for the specified table.
abstract protected loadTableSchema ( string $name ) : null | yii\db\TableSchema
$name string table name
Résultat null | yii\db\TableSchema DBMS-dependent table metadata, null if the table does not exist.

quoteColumnName() public méthode

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.
See also: quoteSimpleColumnName()
public quoteColumnName ( string $name ) : string
$name string column name
Résultat string the properly quoted column name

quoteSimpleColumnName() public méthode

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
Résultat string the properly quoted column name

quoteSimpleTableName() public méthode

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
Résultat string the properly quoted table name

quoteTableName() public méthode

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.
See also: quoteSimpleTableName()
public quoteTableName ( string $name ) : string
$name string table name
Résultat string the properly quoted table name

quoteValue() public méthode

Note that if the parameter is not a string, it will be returned without change.
See also: http://www.php.net/manual/en/function.PDO-quote.php
public quoteValue ( string $str ) : string
$str string string to be quoted
Résultat string the properly quoted string

refresh() public méthode

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() public méthode

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

releaseSavepoint() public méthode

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

rollBackSavepoint() public méthode

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

setTransactionIsolationLevel() public méthode

Sets the isolation level of the current transaction.
See also: 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 méthode

public supportsSavepoint ( ) : boolean
Résultat boolean whether this DBMS supports [savepoint](http://en.wikipedia.org/wiki/Savepoint).

Property Details

$columnSchemaClass public_oe property

column schema class
Since: 2.0.11
public $columnSchemaClass

$db public_oe property

the database connection
public $db

$defaultSchema public_oe property

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

$exceptionMap public_oe property

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