Skip to content

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

View source

Public Properties ​

PropertyDescription
columnSchemaClassstring, array – Column schema class or class config
dbcraft\db\Connection
defaultBackupCommandstring – The command to execute
defaultRestoreCommandstring – The command to execute
defaultSchemastring – The default schema name used for the current session.
exceptionMaparray – Map of DB errors and corresponding exceptions If left part is found in DB error message exception class from the right part is used.
lastInsertIDstring – The row ID of the last row inserted, or the last value retrieved from the sequence object.
maxObjectNameLengthinteger – The maximum length that objects' names can be.
queryBuilderyii\db\QueryBuilder – The query builder for this connection.
schemaChecks\yii\db\CheckConstraint[][] – Check constraints for all tables in the database.
schemaDefaultValuesyii\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.
schemaNamesstring[] – All schema names in the database, except system schemas.
schemaPrimaryKeysyii\db\Constraint – Primary keys for all tables in the database.
schemaUniques\yii\db\IndexConstraint[][] – Unique constraints for all tables in the database.
serverVersionstring – Server version as a string.
tableNamesstring[] – All table names in the database.
tableSchemasyii\db\TableSchema – The metadata for all tables in the database.
tempMyCnfPathstring, null – The path to the temporary my.cnf file used for backups and restoration.
transactionIsolationLevelstring – The transaction isolation level to use for this transaction.
typeMaparray – Mapping from physical column types (keys) to abstract column types (values)

columnSchemaClass ​

Type
string, array
Default value
\craft\db\mysql\ColumnSchema::class

Column schema class or class config

View source

db ​

Type
craft\db\Connection
Default value
null

View source

defaultBackupCommand ​

Type
string
Default value
null
Access
Read-only

The command to execute

View source

defaultRestoreCommand ​

Type
string
Default value
null
Access
Read-only

The command to execute

View source

maxObjectNameLength ​

Type
integer
Default value
64

The maximum length that objects' names can be.

View source

tempMyCnfPath ​

Type
string, null
Default value
null

The path to the temporary my.cnf file used for backups and restoration.

View source

Protected Properties ​

PropertyDescription
columnQuoteCharacterstring, string[] – Character used to quote column names.
tableQuoteCharacterstring, string[] – Character used to quote schema, table, etc.

Public Methods ​

MethodDescription
__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.
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.

View source

Arguments ​

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.

View source

Returns ​

craft\db\mysql\QueryBuilder – Query builder instance

findIndexes() ​

Returns all indexes for the given table. Each array element is of the following structure:

php
[
    'IndexName' => [
        'columns' => ['col1' [, ...]],
        'unique' => false
    ],
]

View source

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.

View source

Arguments ​

  • $ignoreTables

Returns ​

string – The command to execute

Throws ​

getDefaultRestoreCommand() ​

Returns the default database restore command to execute.

View source

Returns ​

string – The command to execute

Throws ​

getTableSchema() ​

Obtains the schema information for the named table.

View source

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.

View source

quoteDatabaseName() ​

Quotes a database name for use in a query.

View source

Arguments ​

Returns ​

string

releaseSavepoint() ​

Releases an existing savepoint.

View source

Arguments ​

  • $name (string) – The savepoint name.

Throws ​

rollBackSavepoint() ​

Rolls back to a previously created savepoint.

View source

Arguments ​

  • $name (string) – The savepoint name.

Throws ​

Protected Methods ​

MethodDescription
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()Loads the column information into a yii\db\mysql\ColumnSchema object.
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.

findConstraints() ​

Collects extra foreign key information details for the given table.

View source

Arguments ​

Throws ​

loadTableSchema() ​

Loads the metadata for the specified table.

View source

Arguments ​

  • $name (string) – Table name

Returns ​

craft\db\TableSchema, null – Driver dependent table metadata. Null if the table does not exist.

Throws ​

Constants ​

ConstantDescription
SCHEMA_CACHE_VERSIONSchema 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