Schema
- Type
- Class
- Namespace
- craft\db\mysql
- Inherits
- craft\db\mysql\Schema » yii\db\mysql\Schema (opens new window) » yii\db\Schema (opens new window) » yii\base\BaseObject (opens new window)
- Implements
- yii\base\Configurable (opens new window), yii\db\ConstraintFinderInterface (opens new window)
- Uses traits
- yii\db\ConstraintFinderTrait (opens new window)
- Since
- 3.0.0
View source (opens new window)
# Public Properties
Property | Description |
---|---|
columnSchemaClass | string (opens new window), array (opens new window) – Column schema class or class config |
db | craft\db\Connection |
defaultBackupCommand | string (opens new window) – The command to execute |
defaultRestoreCommand | string (opens new window) – The command to execute |
defaultSchema (opens new window) | string (opens new window) – The default schema name used for the current session. |
exceptionMap (opens new window) | array (opens new window) – 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 (opens new window) | string (opens new window) – The row ID of the last row inserted, or the last value retrieved from the sequence object. |
maxObjectNameLength | integer (opens new window) – The maximum length that objects' names can be. |
queryBuilder (opens new window) | yii\db\QueryBuilder (opens new window) – The query builder for this connection. |
schemaChecks (opens new window) | \yii\db\CheckConstraint[][] – Check constraints for all tables in the database. |
schemaDefaultValues (opens new window) | yii\db\DefaultValueConstraint (opens new window) – Default value constraints for all tables in the database. |
schemaForeignKeys (opens new window) | \yii\db\ForeignKeyConstraint[][] – Foreign keys for all tables in the database. |
schemaIndexes (opens new window) | \yii\db\IndexConstraint[][] – Indexes for all tables in the database. |
schemaNames (opens new window) | string (opens new window)[] – All schema names in the database, except system schemas. |
schemaPrimaryKeys (opens new window) | yii\db\Constraint (opens new window) – Primary keys for all tables in the database. |
schemaUniques (opens new window) | \yii\db\IndexConstraint[][] – Unique constraints for all tables in the database. |
serverVersion (opens new window) | string (opens new window) – Server version as a string. |
tableNames (opens new window) | string (opens new window)[] – All table names in the database. |
tableSchemas (opens new window) | yii\db\TableSchema (opens new window) – The metadata for all tables in the database. |
tempMyCnfPath | string (opens new window), null (opens new window) – The path to the temporary my. |
transactionIsolationLevel (opens new window) | string (opens new window) – The transaction isolation level to use for this transaction. |
typeMap (opens new window) | array (opens new window) – Mapping from physical column types (keys) to abstract column types (values) |
# columnSchemaClass
- Type
- string (opens new window), array (opens new window)
- Default value
\craft\db\mysql\ColumnSchema::class
Column schema class or class config
View source (opens new window)
# db
- Type
- craft\db\Connection
- Default value
null
View source (opens new window)
# defaultBackupCommand
- Type
- string (opens new window)
- Default value
null
- Access
- Read-only
The command to execute
View source (opens new window)
# defaultRestoreCommand
- Type
- string (opens new window)
- Default value
null
- Access
- Read-only
The command to execute
View source (opens new window)
# maxObjectNameLength
- Type
- integer (opens new window)
- Default value
64
The maximum length that objects' names can be.
View source (opens new window)
# tempMyCnfPath
- Type
- string (opens new window), null (opens new window)
- Default value
null
The path to the temporary my.cnf file used for backups and restoration.
View source (opens new window)
# Protected Properties
Property | Description |
---|---|
columnQuoteCharacter (opens new window) | string (opens new window), string (opens new window)[] – Character used to quote column names. |
tableQuoteCharacter (opens new window) | string (opens new window), string (opens new window)[] – Character used to quote schema, table, etc. |
# Public Methods
Method | Description |
---|---|
__call() (opens new window) | Calls the named method which is not a class method. |
__construct() (opens new window) | Constructor. |
__get() (opens new window) | Returns the value of an object property. |
__isset() (opens new window) | Checks if a property is set, i.e. defined and not null. |
__set() (opens new window) | Sets value of an object property. |
__unset() (opens new window) | Sets an object property to null. |
canGetProperty() (opens new window) | Returns a value indicating whether a property can be read. |
canSetProperty() (opens new window) | Returns a value indicating whether a property can be set. |
className() (opens new window) | Returns the fully qualified name of this class. |
convertException() (opens new window) | 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() (opens new window) | Creates a new savepoint. |
findIndexes() | Returns all indexes for the given table. Each array element is of the following structure: |
findUniqueIndexes() (opens new window) | 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() (opens new window) | Returns the ID of the last inserted row or sequence value. |
getPdoType() (opens new window) | Determines the PDO type for the given PHP data value. |
getQueryBuilder() (opens new window) | |
getRawTableName() (opens new window) | Returns the actual name of a given table name. |
getSchemaChecks() (opens new window) | Returns check constraints for all tables in the database. |
getSchemaDefaultValues() (opens new window) | Returns default value constraints for all tables in the database. |
getSchemaForeignKeys() (opens new window) | Returns foreign keys for all tables in the database. |
getSchemaIndexes() (opens new window) | Returns indexes for all tables in the database. |
getSchemaNames() (opens new window) | Returns all schema names in the database, except system schemas. |
getSchemaPrimaryKeys() (opens new window) | Returns primary keys for all tables in the database. |
getSchemaUniques() (opens new window) | Returns unique constraints for all tables in the database. |
getServerVersion() (opens new window) | Returns a server version as a string comparable by \version_compare() . |
getTableChecks() (opens new window) | Obtains the check constraints information for the named table. |
getTableDefaultValues() (opens new window) | Obtains the default value constraints information for the named table. |
getTableForeignKeys() (opens new window) | Obtains the foreign keys information for the named table. |
getTableIndexes() (opens new window) | Obtains the indexes information for the named table. |
getTableNames() (opens new window) | Returns all table names in the database. |
getTablePrimaryKey() (opens new window) | Obtains the primary key for the named table. |
getTableSchema() | Obtains the schema information for the named table. |
getTableSchemas() (opens new window) | Returns the metadata for all tables in the database. |
getTableUniques() (opens new window) | Obtains the unique constraints information for the named table. |
hasMethod() (opens new window) | Returns a value indicating whether a method is defined. |
hasProperty() (opens new window) | Returns a value indicating whether a property is defined. |
init() | Initializes the object. |
insert() (opens new window) | Executes the INSERT command, returning primary key values. |
isReadQuery() (opens new window) | Returns a value indicating whether a SQL statement is for read purpose. |
quoteColumnName() (opens new window) | Quotes a column name for use in a query. |
quoteDatabaseName() | Quotes a database name for use in a query. |
quoteSimpleColumnName() (opens new window) | Quotes a simple column name for use in a query. |
quoteSimpleTableName() (opens new window) | Quotes a simple table name for use in a query. |
quoteTableName() (opens new window) | Quotes a table name for use in a query. |
quoteValue() (opens new window) | Quotes a string value for use in a query. |
refresh() (opens new window) | Refreshes the schema. |
refreshTableSchema() (opens new window) | Refreshes the particular table schema. |
releaseSavepoint() | Releases an existing savepoint. |
rollBackSavepoint() | Rolls back to a previously created savepoint. |
setTransactionIsolationLevel() (opens new window) | Sets the isolation level of the current transaction. |
supportsSavepoint() (opens new window) | |
unquoteSimpleColumnName() (opens new window) | Unquotes a simple column name. |
unquoteSimpleTableName() (opens new window) | 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 (opens new window)
Arguments
$type
(string (opens new window)) – Type of the column. See craft\db\mysql\ColumnSchemaBuilder::$type (opens new window).$length
(integer (opens new window), string (opens new window), array (opens new window)) – Length or precision of the column. See craft\db\mysql\ColumnSchemaBuilder::$length (opens new window).
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 (opens new window)
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
],
]
View source (opens new window)
Arguments
$tableName
(string (opens new window)) – The name of the table to get the indexes for.
Returns
array (opens new window) – All indexes for the given table.
Throws
# getDefaultBackupCommand()
Returns the default backup command to execute.
View source (opens new window)
Arguments
$ignoreTables
(string (opens new window)[], null (opens new window)) – The table names whose data should be excluded from the backup
Returns
string (opens new window) – The command to execute
Throws
# getDefaultRestoreCommand()
Returns the default database restore command to execute.
View source (opens new window)
Returns
string (opens new window) – The command to execute
Throws
# getTableSchema()
Obtains the schema information for the named table.
View source (opens new window)
Arguments
$name
$refresh
Returns
craft\db\TableSchema, null (opens new window) –
# 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 (opens new window)
# quoteDatabaseName()
Quotes a database name for use in a query.
View source (opens new window)
Arguments
$name
(string (opens new window))
Returns
# releaseSavepoint()
Releases an existing savepoint.
View source (opens new window)
Arguments
$name
(string (opens new window)) – The savepoint name.
Throws
# rollBackSavepoint()
Rolls back to a previously created savepoint.
View source (opens new window)
Arguments
$name
(string (opens new window)) – The savepoint name.
Throws
# Protected Methods
Method | Description |
---|---|
createColumnSchema() (opens new window) | Creates a column schema for the database. |
findColumns() (opens new window) | Collects the metadata of table columns. |
findConstraints() | Collects extra foreign key information details for the given table. |
findSchemaNames() (opens new window) | Returns all schema names in the database, including the default one but not system schemas. |
findTableNames() (opens new window) | Returns all table names in the database. |
getCacheKey() (opens new window) | Returns the cache key for the specified table name. |
getCacheTag() (opens new window) | Returns the cache tag name. |
getColumnPhpType() (opens new window) | Extracts the PHP type from abstract DB type. |
getCreateTableSql() (opens new window) | Gets the CREATE TABLE sql string. |
getSchemaMetadata() (opens new window) | Returns the metadata of the given type for all tables in the given schema. |
getTableMetadata() (opens new window) | Returns the metadata of the given type for the given table. |
getTableNameParts() (opens new window) | Splits full table name into parts |
isOldMysql() (opens new window) | |
loadColumnSchema() (opens new window) | Loads the column information into a yii\db\mysql\ColumnSchema (opens new window) object. |
loadTableChecks() (opens new window) | Loads all check constraints for the given table. |
loadTableDefaultValues() (opens new window) | Loads all default value constraints for the given table. |
loadTableForeignKeys() (opens new window) | Loads all foreign keys for the given table. |
loadTableIndexes() (opens new window) | Loads all indexes for the given table. |
loadTablePrimaryKey() (opens new window) | Loads a primary key for the given table. |
loadTableSchema() | Loads the metadata for the specified table. |
loadTableUniques() (opens new window) | Loads all unique constraints for the given table. |
normalizePdoRowKeyCase() (opens new window) | Changes row's array key case to lower if PDO's one is set to uppercase. |
resolveTableName() (opens new window) | Resolves the table name and schema name (if any). |
resolveTableNames() (opens new window) | Resolves the table name and schema name (if any). |
setTableMetadata() (opens new window) | Sets the metadata of the given type for the given table. |
# findConstraints()
Collects extra foreign key information details for the given table.
View source (opens new window)
Arguments
$table
(craft\db\TableSchema) – The table metadata
Throws
# loadTableSchema()
Loads the metadata for the specified table.
View source (opens new window)
Arguments
$name
(string (opens new window)) – Table name
Returns
craft\db\TableSchema, null (opens new window) – Driver dependent table metadata. Null if the table does not exist.
Throws
# 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 |