Schema ​
- Type
- Class
- Namespace
- craft\db\mysql
- Inherits
- craft\db\mysql\Schema » yii\db\mysql\Schema » yii\db\Schema » yii\base\BaseObject
- Implements
- yii\base\Configurable, yii\db\ConstraintFinderInterface
- Uses traits
- yii\db\ConstraintFinderTrait
- Since
- 3.0.0
Public Properties ​
Property | Description |
---|---|
columnSchemaClass | string, array – Column schema class or class config |
db | craft\db\Connection |
defaultBackupCommand | string – The command to execute |
defaultRestoreCommand | string – The command to execute |
defaultSchema | string – The default schema name used for the current session. |
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. |
lastInsertID | string – The row ID of the last row inserted, or the last value retrieved from the sequence object. |
maxObjectNameLength | integer – The maximum length that objects' names can be. |
queryBuilder | yii\db\QueryBuilder – The query builder for this connection. |
schemaChecks | \yii\db\CheckConstraint[][] – Check constraints for all tables in the database. |
schemaDefaultValues | yii\db\DefaultValueConstraint – Default value constraints for all tables in the database. |
schemaForeignKeys | \yii\db\ForeignKeyConstraint[][] – Foreign keys for all tables in the database. |
schemaIndexes | \yii\db\IndexConstraint[][] – Indexes for all tables in the database. |
schemaNames | string[] – All schema names in the database, except system schemas. |
schemaPrimaryKeys | yii\db\Constraint – Primary keys for all tables in the database. |
schemaUniques | \yii\db\IndexConstraint[][] – Unique constraints for all tables in the database. |
serverVersion | string – Server version as a string. |
tableNames | string[] – All table names in the database. |
tableSchemas | yii\db\TableSchema – The metadata for all tables in the database. |
tempMyCnfPath | string, null – The path to the temporary my.cnf file used for backups and restoration. |
transactionIsolationLevel | string – The transaction isolation level to use for this transaction. |
typeMap | array – Mapping from physical column types (keys) to abstract column types (values) |
columnSchemaClass
​
Column schema class or class config
db
​
- Type
- craft\db\Connection
- Default value
null
defaultBackupCommand
​
- Type
- string
- Default value
null
- Access
- Read-only
The command to execute
defaultRestoreCommand
​
- Type
- string
- Default value
null
- Access
- Read-only
The command to execute
maxObjectNameLength
​
- Type
- integer
- Default value
64
The maximum length that objects' names can be.
tempMyCnfPath
​
The path to the temporary my.cnf file used for backups and restoration.
Protected Properties ​
Property | Description |
---|---|
columnQuoteCharacter | string, string[] – Character used to quote column names. |
tableQuoteCharacter | string, string[] – Character used to quote schema, table, etc. |
Public Methods ​
Method | Description |
---|---|
__call() | Calls the named method which is not a class method. |
__construct() | Constructor. |
__get() | Returns the value of an object property. |
__isset() | Checks if a property is set, i.e. defined and not null. |
__set() | Sets value of an object property. |
__unset() | Sets an object property to null. |
canGetProperty() | Returns a value indicating whether a property can be read. |
canSetProperty() | Returns a value indicating whether a property can be set. |
className() | Returns the fully qualified name of this class. |
convertException() | Converts a DB exception to a more concrete one if possible. |
createColumnSchemaBuilder() | Create a column schema builder instance giving the type and value precision. |
createQueryBuilder() | Creates a query builder for the database. |
createSavepoint() | Creates a new savepoint. |
findIndexes() | Returns all indexes for the given table. Each array element is of the following structure: |
findUniqueIndexes() | Returns all unique indexes for the given table. |
getDefaultBackupCommand() | Returns the default backup command to execute. |
getDefaultRestoreCommand() | Returns the default database restore command to execute. |
getLastInsertID() | Returns the ID of the last inserted row or sequence value. |
getPdoType() | Determines the PDO type for the given PHP data value. |
getQueryBuilder() | |
getRawTableName() | Returns the actual name of a given table name. |
getSchemaChecks() | Returns check constraints for all tables in the database. |
getSchemaDefaultValues() | Returns default value constraints for all tables in the database. |
getSchemaForeignKeys() | Returns foreign keys for all tables in the database. |
getSchemaIndexes() | Returns indexes for all tables in the database. |
getSchemaNames() | Returns all schema names in the database, except system schemas. |
getSchemaPrimaryKeys() | Returns primary keys for all tables in the database. |
getSchemaUniques() | Returns unique constraints for all tables in the database. |
getServerVersion() | Returns a server version as a string comparable by \version_compare() . |
getTableChecks() | Obtains the check constraints information for the named table. |
getTableDefaultValues() | Obtains the default value constraints information for the named table. |
getTableForeignKeys() | Obtains the foreign keys information for the named table. |
getTableIndexes() | Obtains the indexes information for the named table. |
getTableNames() | Returns all table names in the database. |
getTablePrimaryKey() | Obtains the primary key for the named table. |
getTableSchema() | Obtains the schema information for the named table. |
getTableSchemas() | Returns the metadata for all tables in the database. |
getTableUniques() | Obtains the unique constraints information for the named table. |
hasMethod() | Returns a value indicating whether a method is defined. |
hasProperty() | Returns a value indicating whether a property is defined. |
init() | Initializes the object. |
insert() | Executes the INSERT command, returning primary key values. |
isReadQuery() | Returns a value indicating whether a SQL statement is for read purpose. |
quoteColumnName() | Quotes a column name for use in a query. |
quoteDatabaseName() | Quotes a database name for use in a query. |
quoteSimpleColumnName() | Quotes a simple column name for use in a query. |
quoteSimpleTableName() | Quotes a simple table name for use in a query. |
quoteTableName() | Quotes a table name for use in a query. |
quoteValue() | Quotes a string value for use in a query. |
refresh() | Refreshes the schema. |
refreshTableSchema() | Refreshes the particular table schema. |
releaseSavepoint() | Releases an existing savepoint. |
rollBackSavepoint() | Rolls back to a previously created savepoint. |
setTransactionIsolationLevel() | Sets the isolation level of the current transaction. |
supportsMb4() | Returns whether a table supports 4-byte characters. |
supportsSavepoint() | |
unquoteSimpleColumnName() | Unquotes a simple column name. |
unquoteSimpleTableName() | Unquotes a simple table name. |
createColumnSchemaBuilder()
​
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.
Arguments ​
$type
(string) – Type of the column. See craft\db\mysql\ColumnSchemaBuilder::$type.$length
(integer, string, array) – Length or precision of the column. See craft\db\mysql\ColumnSchemaBuilder::$length.
Returns ​
craft\db\mysql\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.
Returns ​
craft\db\mysql\QueryBuilder – Query builder instance
findIndexes()
​
Returns all indexes for the given table. Each array element is of the following structure:
[
'IndexName' => [
'columns' => ['col1' [, ...]],
'unique' => false
],
]
Arguments ​
$tableName
(string) – The name of the table to get the indexes for.
Returns ​
array – All indexes for the given table.
Throws ​
getDefaultBackupCommand()
​
Returns the default backup command to execute.
Arguments ​
Returns ​
string – The command to execute
Throws ​
getDefaultRestoreCommand()
​
Returns the default database restore command to execute.
Returns ​
string – The command to execute
Throws ​
getTableSchema()
​
Obtains the schema information for the named table.
Arguments ​
$name
$refresh
Returns ​
craft\db\TableSchema, null –
init()
​
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
quoteDatabaseName()
​
DEPRECATED
Deprecated in 5.4.0
Quotes a database name for use in a query.
Arguments ​
$name
(string)
Returns ​
releaseSavepoint()
​
Releases an existing savepoint.
Arguments ​
$name
(string) – The savepoint name.
Throws ​
rollBackSavepoint()
​
Rolls back to a previously created savepoint.
Arguments ​
$name
(string) – The savepoint name.
Throws ​
supportsMb4()
​
- Since
- 5.0.0
Returns whether a table supports 4-byte characters.
Arguments ​
$table
(string) – The table to check
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if $table is invalid
Protected Methods ​
Method | Description |
---|---|
createColumnSchema() | Creates a column schema for the database. |
findColumns() | Collects the metadata of table columns. |
findConstraints() | Collects extra foreign key information details for the given table. |
findSchemaNames() | Returns all schema names in the database, including the default one but not system schemas. |
findTableNames() | Returns all table names in the database. |
getCacheKey() | Returns the cache key for the specified table name. |
getCacheTag() | Returns the cache tag name. |
getColumnPhpType() | Extracts the PHP type from abstract DB type. |
getCreateTableSql() | Gets the CREATE TABLE sql string. |
getSchemaMetadata() | Returns the metadata of the given type for all tables in the given schema. |
getTableMetadata() | Returns the metadata of the given type for the given table. |
getTableNameParts() | Splits full table name into parts |
isOldMysql() | |
loadColumnSchema() | |
loadTableChecks() | |
loadTableDefaultValues() | |
loadTableForeignKeys() | |
loadTableIndexes() | |
loadTablePrimaryKey() | |
loadTableSchema() | Loads the metadata for the specified table. |
loadTableUniques() | |
normalizePdoRowKeyCase() | Changes row's array key case to lower if PDO's one is set to uppercase. |
resolveTableName() | Resolves the table name and schema name (if any). |
resolveTableNames() | Resolves the table name and schema name (if any). |
setTableMetadata() | Sets the metadata of the given type for the given table. |
supportsColumnStatistics() |
findConstraints()
​
Collects extra foreign key information details for the given table.
Arguments ​
$table
(craft\db\TableSchema) – The table metadata
Throws ​
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.
Arguments ​
$schema
(string) – The schema of the tables. Defaults to empty string, meaning the current or default schema.
Returns ​
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.
loadColumnSchema()
​
Arguments ​
$info
(array)
Returns ​
loadTableSchema()
​
Loads the metadata for the specified table.
Arguments ​
$name
(string) – Table name
Returns ​
craft\db\TableSchema, null – Driver dependent table metadata. Null if the table does not exist.
Throws ​
supportsColumnStatistics()
​
Constants ​
Constant | Description |
---|---|
SCHEMA_CACHE_VERSION | Schema cache version, to detect incompatibilities in cached values when the data format of the cache changes. |
TYPE_BIGINT | |
TYPE_BIGPK | |
TYPE_BINARY | |
TYPE_BOOLEAN | |
TYPE_CHAR | |
TYPE_DATE | |
TYPE_DATETIME | |
TYPE_DECIMAL | |
TYPE_DOUBLE | |
TYPE_ENUM | |
TYPE_FLOAT | |
TYPE_INTEGER | |
TYPE_JSON | |
TYPE_LONGTEXT | |
TYPE_MEDIUMTEXT | |
TYPE_MONEY | |
TYPE_PK | |
TYPE_SMALLINT | |
TYPE_STRING | |
TYPE_TEXT | |
TYPE_TIME | |
TYPE_TIMESTAMP | |
TYPE_TINYINT | |
TYPE_TINYTEXT | |
TYPE_UBIGPK | |
TYPE_UPK |