Schema
extends BaseObject
in package
Schema is the base class for concrete DBMS-specific schema classes.
Schema represents the database schema information that is DBMS specific.
Tags
Table of Contents
Constants
- SCHEMA_CACHE_VERSION = 1
- Schema cache version, to detect incompatibilities in cached values when the data format of the cache changes.
- TYPE_BIGINT = 'bigint'
- TYPE_BIGPK = 'bigpk'
- TYPE_BINARY = 'binary'
- TYPE_BOOLEAN = 'boolean'
- TYPE_CHAR = 'char'
- TYPE_DATE = 'date'
- TYPE_DATETIME = 'datetime'
- TYPE_DECIMAL = 'decimal'
- TYPE_DOUBLE = 'double'
- TYPE_FLOAT = 'float'
- TYPE_INTEGER = 'integer'
- TYPE_JSON = 'json'
- TYPE_MONEY = 'money'
- TYPE_PK = 'pk'
- TYPE_SMALLINT = 'smallint'
- TYPE_STRING = 'string'
- TYPE_TEXT = 'text'
- TYPE_TIME = 'time'
- TYPE_TIMESTAMP = 'timestamp'
- TYPE_TINYINT = 'tinyint'
- TYPE_UBIGPK = 'ubigpk'
- TYPE_UPK = 'upk'
Properties
- $columnSchemaClass : string|array<string|int, mixed>
- $db : Connection
- $defaultSchema : string
- $exceptionMap : array<string|int, mixed>
- $lastInsertID : string
- $queryBuilder : QueryBuilder
- $schemaNames : array<string|int, string>
- $serverVersion : string
- $tableNames : array<string|int, string>
- $tableSchemas : array<string|int, TableSchema>
- $transactionIsolationLevel : string
- $columnQuoteCharacter : string|array<string|int, string>
- $tableQuoteCharacter : string|array<string|int, string>
- $_builder : QueryBuilder
- $_schemaNames : array<string|int, mixed>
- $_serverVersion : string
- $_tableMetadata : array<string|int, mixed>
- $_tableNames : array<string|int, mixed>
Methods
- __call() : mixed
- Calls the named method which is not a class method.
- __construct() : mixed
- Constructor.
- __get() : mixed
- Returns the value of an object property.
- __isset() : bool
- Checks if a property is set, i.e. defined and not null.
- __set() : mixed
- Sets value of an object property.
- __unset() : mixed
- Sets an object property to null.
- canGetProperty() : bool
- Returns a value indicating whether a property can be read.
- canSetProperty() : bool
- Returns a value indicating whether a property can be set.
- className() : string
- Returns the fully qualified name of this class.
- convertException() : Exception
- Converts a DB exception to a more concrete one if possible.
- createColumnSchemaBuilder() : ColumnSchemaBuilder
- Create a column schema builder instance giving the type and value precision.
- createQueryBuilder() : QueryBuilder
- Creates a query builder for the database.
- createSavepoint() : mixed
- Creates a new savepoint.
- findUniqueIndexes() : array<string|int, mixed>
- Returns all unique indexes for the given table.
- getLastInsertID() : string
- Returns the ID of the last inserted row or sequence value.
- getPdoType() : int
- Determines the PDO type for the given PHP data value.
- getQueryBuilder() : QueryBuilder
- getRawTableName() : string
- Returns the actual name of a given table name.
- getSchemaNames() : array<string|int, string>
- Returns all schema names in the database, except system schemas.
- getServerVersion() : string
- Returns a server version as a string comparable by [[\version_compare()]].
- getTableNames() : array<string|int, string>
- Returns all table names in the database.
- getTableSchema() : TableSchema|null
- Obtains the metadata for the named table.
- getTableSchemas() : array<string|int, TableSchema>
- Returns the metadata for all tables in the database.
- hasMethod() : bool
- Returns a value indicating whether a method is defined.
- hasProperty() : bool
- Returns a value indicating whether a property is defined.
- init() : mixed
- Initializes the object.
- insert() : array<string|int, mixed>|false
- Executes the INSERT command, returning primary key values.
- isReadQuery() : bool
- Returns a value indicating whether a SQL statement is for read purpose.
- quoteColumnName() : string
- Quotes a column name for use in a query.
- quoteSimpleColumnName() : string
- Quotes a simple column name for use in a query.
- quoteSimpleTableName() : string
- Quotes a simple table name for use in a query.
- quoteTableName() : string
- Quotes a table name for use in a query.
- quoteValue() : string
- Quotes a string value for use in a query.
- refresh() : mixed
- Refreshes the schema.
- refreshTableSchema() : mixed
- Refreshes the particular table schema.
- releaseSavepoint() : mixed
- Releases an existing savepoint.
- rollBackSavepoint() : mixed
- Rolls back to a previously created savepoint.
- setTransactionIsolationLevel() : mixed
- Sets the isolation level of the current transaction.
- supportsSavepoint() : bool
- unquoteSimpleColumnName() : string
- Unquotes a simple column name.
- unquoteSimpleTableName() : string
- Unquotes a simple table name.
- createColumnSchema() : ColumnSchema
- Creates a column schema for the database.
- findSchemaNames() : array<string|int, mixed>
- Returns all schema names in the database, including the default one but not system schemas.
- findTableNames() : array<string|int, mixed>
- Returns all table names in the database.
- getCacheKey() : mixed
- Returns the cache key for the specified table name.
- getCacheTag() : string
- Returns the cache tag name.
- getColumnPhpType() : string
- Extracts the PHP type from abstract DB type.
- getSchemaMetadata() : array<string|int, mixed>
- Returns the metadata of the given type for all tables in the given schema.
- getTableMetadata() : mixed
- Returns the metadata of the given type for the given table.
- getTableNameParts() : array<string|int, mixed>
- Splits full table name into parts
- loadTableSchema() : TableSchema|null
- Loads the metadata for the specified table.
- normalizePdoRowKeyCase() : array<string|int, mixed>
- Changes row's array key case to lower if PDO's one is set to uppercase.
- resolveTableName() : TableSchema
- Resolves the table name and schema name (if any).
- setTableMetadata() : mixed
- Sets the metadata of the given type for the given table.
- loadTableMetadataFromCache() : mixed
- Tries to load and populate table metadata from cache.
- saveTableMetadataToCache() : mixed
- Saves table metadata to cache.
Constants
SCHEMA_CACHE_VERSION
Schema cache version, to detect incompatibilities in cached values when the data format of the cache changes.
public
mixed
SCHEMA_CACHE_VERSION
= 1
TYPE_BIGINT
public
mixed
TYPE_BIGINT
= 'bigint'
TYPE_BIGPK
public
mixed
TYPE_BIGPK
= 'bigpk'
TYPE_BINARY
public
mixed
TYPE_BINARY
= 'binary'
TYPE_BOOLEAN
public
mixed
TYPE_BOOLEAN
= 'boolean'
TYPE_CHAR
public
mixed
TYPE_CHAR
= 'char'
TYPE_DATE
public
mixed
TYPE_DATE
= 'date'
TYPE_DATETIME
public
mixed
TYPE_DATETIME
= 'datetime'
TYPE_DECIMAL
public
mixed
TYPE_DECIMAL
= 'decimal'
TYPE_DOUBLE
public
mixed
TYPE_DOUBLE
= 'double'
TYPE_FLOAT
public
mixed
TYPE_FLOAT
= 'float'
TYPE_INTEGER
public
mixed
TYPE_INTEGER
= 'integer'
TYPE_JSON
public
mixed
TYPE_JSON
= 'json'
TYPE_MONEY
public
mixed
TYPE_MONEY
= 'money'
TYPE_PK
public
mixed
TYPE_PK
= 'pk'
TYPE_SMALLINT
public
mixed
TYPE_SMALLINT
= 'smallint'
TYPE_STRING
public
mixed
TYPE_STRING
= 'string'
TYPE_TEXT
public
mixed
TYPE_TEXT
= 'text'
TYPE_TIME
public
mixed
TYPE_TIME
= 'time'
TYPE_TIMESTAMP
public
mixed
TYPE_TIMESTAMP
= 'timestamp'
TYPE_TINYINT
public
mixed
TYPE_TINYINT
= 'tinyint'
TYPE_UBIGPK
public
mixed
TYPE_UBIGPK
= 'ubigpk'
TYPE_UPK
public
mixed
TYPE_UPK
= 'upk'
Properties
$columnSchemaClass
public
string|array<string|int, mixed>
$columnSchemaClass
= 'yii\db\ColumnSchema'
column schema class or class config
Tags
$db
public
Connection
$db
the database connection
$defaultSchema
public
string
$defaultSchema
the default schema name used for the current session.
$exceptionMap
public
array<string|int, mixed>
$exceptionMap
= ['SQLSTATE[23' => 'yii\db\IntegrityException']
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 read-only
public
string
$lastInsertID
The row ID of the last row inserted, or the last value retrieved from the sequence object.
$queryBuilder read-only
public
QueryBuilder
$queryBuilder
The query builder for this connection.
$schemaNames read-only
public
array<string|int, string>
$schemaNames
All schema names in the database, except system schemas.
$serverVersion read-only
public
string
$serverVersion
Server version as a string.
$tableNames read-only
public
array<string|int, string>
$tableNames
All table names in the database.
$tableSchemas read-only
public
array<string|int, TableSchema>
$tableSchemas
The metadata for all tables in the database. Each array element is an instance of [[TableSchema]] or its child class.
$transactionIsolationLevel write-only
public
string
$transactionIsolationLevel
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
.
$columnQuoteCharacter
protected
string|array<string|int, string>
$columnQuoteCharacter
= '"'
character used to quote column names. An array of 2 characters can be used in case starting and ending characters are different.
Tags
$tableQuoteCharacter
protected
string|array<string|int, string>
$tableQuoteCharacter
= "'"
character used to quote schema, table, etc. names. An array of 2 characters can be used in case starting and ending characters are different.
Tags
$_builder
private
QueryBuilder
$_builder
the query builder for this database
$_schemaNames
private
array<string|int, mixed>
$_schemaNames
list of ALL schema names in the database, except system schemas
$_serverVersion
private
string
$_serverVersion
server version as a string.
$_tableMetadata
private
array<string|int, mixed>
$_tableMetadata
= []
list of loaded table metadata (table name => metadata type => metadata).
$_tableNames
private
array<string|int, mixed>
$_tableNames
= []
list of ALL table names in the database
Methods
__call()
Calls the named method which is not a class method.
public
__call(string $name, array<string|int, mixed> $params) : mixed
Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.
Parameters
- $name : string
-
the method name
- $params : array<string|int, mixed>
-
method parameters
Tags
Return values
mixed —the method return value
__construct()
Constructor.
public
__construct([array<string|int, mixed> $config = [] ]) : mixed
The default implementation does two things:
- Initializes the object with the given configuration
$config
. - Call [[init()]].
If this method is overridden in a child class, it is recommended that
- the last parameter of the constructor is a configuration array, like
$config
here. - call the parent implementation at the end of the constructor.
Parameters
- $config : array<string|int, mixed> = []
-
name-value pairs that will be used to initialize the object properties
__get()
Returns the value of an object property.
public
__get(string $name) : mixed
Do not call this method directly as it is a PHP magic method that
will be implicitly called when executing $value = $object->property;
.
Parameters
- $name : string
-
the property name
Tags
Return values
mixed —the property value
__isset()
Checks if a property is set, i.e. defined and not null.
public
__isset(string $name) : bool
Do not call this method directly as it is a PHP magic method that
will be implicitly called when executing isset($object->property)
.
Note that if the property is not defined, false will be returned.
Parameters
- $name : string
-
the property name or the event name
Tags
Return values
bool —whether the named property is set (not null).
__set()
Sets value of an object property.
public
__set(string $name, mixed $value) : mixed
Do not call this method directly as it is a PHP magic method that
will be implicitly called when executing $object->property = $value;
.
Parameters
- $name : string
-
the property name or the event name
- $value : mixed
-
the property value
Tags
__unset()
Sets an object property to null.
public
__unset(string $name) : mixed
Do not call this method directly as it is a PHP magic method that
will be implicitly called when executing unset($object->property)
.
Note that if the property is not defined, this method will do nothing. If the property is read-only, it will throw an exception.
Parameters
- $name : string
-
the property name
Tags
canGetProperty()
Returns a value indicating whether a property can be read.
public
canGetProperty(string $name[, bool $checkVars = true ]) : bool
A property is readable if:
- the class has a getter method associated with the specified name (in this case, property name is case-insensitive);
- the class has a member variable with the specified name (when
$checkVars
is true);
Parameters
- $name : string
-
the property name
- $checkVars : bool = true
-
whether to treat member variables as properties
Tags
Return values
bool —whether the property can be read
canSetProperty()
Returns a value indicating whether a property can be set.
public
canSetProperty(string $name[, bool $checkVars = true ]) : bool
A property is writable if:
- the class has a setter method associated with the specified name (in this case, property name is case-insensitive);
- the class has a member variable with the specified name (when
$checkVars
is true);
Parameters
- $name : string
-
the property name
- $checkVars : bool = true
-
whether to treat member variables as properties
Tags
Return values
bool —whether the property can be written
className()
Returns the fully qualified name of this class.
public
static className() : string
Tags
Return values
string —the fully qualified name of this class.
convertException()
Converts a DB exception to a more concrete one if possible.
public
convertException(Exception $e, string $rawSql) : Exception
Parameters
- $e : Exception
- $rawSql : string
-
SQL that produced exception
Return values
ExceptioncreateColumnSchemaBuilder()
Create a column schema builder instance giving the type and value precision.
public
createColumnSchemaBuilder(string $type[, int|string|array<string|int, mixed>|null $length = null ]) : ColumnSchemaBuilder
This method may be overridden by child classes to create a DBMS-specific column schema builder.
Parameters
- $type : string
-
type of the column. See [[ColumnSchemaBuilder::$type]].
- $length : int|string|array<string|int, mixed>|null = null
-
length or precision of the column. See [[ColumnSchemaBuilder::$length]].
Tags
Return values
ColumnSchemaBuilder —column schema builder instance
createQueryBuilder()
Creates a query builder for the database.
public
createQueryBuilder() : QueryBuilder
This method may be overridden by child classes to create a DBMS-specific query builder.
Return values
QueryBuilder —query builder instance
createSavepoint()
Creates a new savepoint.
public
createSavepoint(string $name) : mixed
Parameters
- $name : string
-
the savepoint name
findUniqueIndexes()
Returns all unique indexes for the given table.
public
findUniqueIndexes(TableSchema $table) : array<string|int, mixed>
Each array element is of the following structure:
[
'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
Parameters
- $table : TableSchema
-
the table metadata
Tags
Return values
array<string|int, mixed> —all unique indexes for the given table.
getLastInsertID()
Returns the ID of the last inserted row or sequence value.
public
getLastInsertID([string $sequenceName = '' ]) : string
Parameters
- $sequenceName : string = ''
-
name of the sequence object (required by some DBMS)
Tags
Return values
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.
public
getPdoType(mixed $data) : int
Parameters
- $data : mixed
-
the data whose PDO type is to be determined
Tags
Return values
int —the PDO type
getQueryBuilder()
public
getQueryBuilder() : QueryBuilder
Return values
QueryBuilder —the query builder for this connection.
getRawTableName()
Returns the actual name of a given table name.
public
getRawTableName(string $name) : string
This method will strip off curly brackets from the given table name and replace the percentage character '%' with [[Connection::tablePrefix]].
Parameters
- $name : string
-
the table name to be converted
Return values
string —the real name of the given table name
getSchemaNames()
Returns all schema names in the database, except system schemas.
public
getSchemaNames([bool $refresh = false ]) : array<string|int, string>
Parameters
- $refresh : bool = false
-
whether to fetch the latest available schema names. If this is false, schema names fetched previously (if available) will be returned.
Tags
Return values
array<string|int, string> —all schema names in the database, except system schemas.
getServerVersion()
Returns a server version as a string comparable by [[\version_compare()]].
public
getServerVersion() : string
Tags
Return values
string —server version as a string.
getTableNames()
Returns all table names in the database.
public
getTableNames([string $schema = '' ][, bool $refresh = false ]) : array<string|int, string>
Parameters
- $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 : bool = false
-
whether to fetch the latest available table names. If this is false, table names fetched previously (if available) will be returned.
Return values
array<string|int, string> —all table names in the database.
getTableSchema()
Obtains the metadata for the named table.
public
getTableSchema(string $name[, bool $refresh = false ]) : TableSchema|null
Parameters
- $name : string
-
table name. The table name may contain schema name if any. Do not quote the table name.
- $refresh : bool = false
-
whether to reload the table schema even if it is found in the cache.
Return values
TableSchema|null —table metadata. null
if the named table does not exist.
getTableSchemas()
Returns the metadata for all tables in the database.
public
getTableSchemas([string $schema = '' ][, bool $refresh = false ]) : array<string|int, TableSchema>
Parameters
- $schema : string = ''
-
the schema of the tables. Defaults to empty string, meaning the current or default schema name.
- $refresh : bool = false
-
whether to fetch the latest available table schemas. If this is
false
, cached data may be returned if available.
Return values
array<string|int, TableSchema> —the metadata for all tables in the database. Each array element is an instance of [[TableSchema]] or its child class.
hasMethod()
Returns a value indicating whether a method is defined.
public
hasMethod(string $name) : bool
The default implementation is a call to php function method_exists()
.
You may override this method when you implemented the php magic method __call()
.
Parameters
- $name : string
-
the method name
Return values
bool —whether the method is defined
hasProperty()
Returns a value indicating whether a property is defined.
public
hasProperty(string $name[, bool $checkVars = true ]) : bool
A property is defined if:
- the class has a getter or setter method associated with the specified name (in this case, property name is case-insensitive);
- the class has a member variable with the specified name (when
$checkVars
is true);
Parameters
- $name : string
-
the property name
- $checkVars : bool = true
-
whether to treat member variables as properties
Tags
Return values
bool —whether the property is defined
init()
Initializes the object.
public
init() : mixed
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
insert()
Executes the INSERT command, returning primary key values.
public
insert(string $table, array<string|int, mixed> $columns) : array<string|int, mixed>|false
Parameters
- $table : string
-
the table that new rows will be inserted into.
- $columns : array<string|int, mixed>
-
the column data (name => value) to be inserted into the table.
Tags
Return values
array<string|int, mixed>|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) : bool
Parameters
- $sql : string
-
the SQL statement
Return values
bool —whether a SQL statement is for read purpose.
quoteColumnName()
Quotes a column name for use in a query.
public
quoteColumnName(string $name) : string
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.
Parameters
- $name : string
-
column name
Tags
Return values
string —the properly quoted column name
quoteSimpleColumnName()
Quotes a simple column name for use in a query.
public
quoteSimpleColumnName(string $name) : string
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.
Parameters
- $name : string
-
column name
Return values
string —the properly quoted column name
quoteSimpleTableName()
Quotes a simple table name for use in a query.
public
quoteSimpleTableName(string $name) : string
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.
Parameters
- $name : string
-
table name
Return values
string —the properly quoted table name
quoteTableName()
Quotes a table name for use in a query.
public
quoteTableName(string $name) : string
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.
Parameters
- $name : string
-
table name
Tags
Return values
string —the properly quoted table name
quoteValue()
Quotes a string value for use in a query.
public
quoteValue(string $str) : string
Note that if the parameter is not a string, it will be returned without change.
Parameters
- $str : string
-
string to be quoted
Tags
Return values
string —the properly quoted string
refresh()
Refreshes the schema.
public
refresh() : mixed
This method cleans up all cached table schemas so that they can be re-created later to reflect the database schema change.
refreshTableSchema()
Refreshes the particular table schema.
public
refreshTableSchema(string $name) : mixed
This method cleans up cached table schema so that it can be re-created later to reflect the database schema change.
Parameters
- $name : string
-
table name.
Tags
releaseSavepoint()
Releases an existing savepoint.
public
releaseSavepoint(string $name) : mixed
Parameters
- $name : string
-
the savepoint name
rollBackSavepoint()
Rolls back to a previously created savepoint.
public
rollBackSavepoint(string $name) : mixed
Parameters
- $name : string
-
the savepoint name
setTransactionIsolationLevel()
Sets the isolation level of the current transaction.
public
setTransactionIsolationLevel(string $level) : mixed
Parameters
- $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
.
Tags
supportsSavepoint()
public
supportsSavepoint() : bool
Return values
bool —whether this DBMS supports savepoint.
unquoteSimpleColumnName()
Unquotes a simple column name.
public
unquoteSimpleColumnName(string $name) : string
A simple column name should contain the column name only without any prefix. If the column name is not quoted or is the asterisk character '*', this method will do nothing.
Parameters
- $name : string
-
column name.
Tags
Return values
string —unquoted column name.
unquoteSimpleTableName()
Unquotes a simple table name.
public
unquoteSimpleTableName(string $name) : string
A simple table name should contain the table name only without any schema prefix. If the table name is not quoted, this method will do nothing.
Parameters
- $name : string
-
table name.
Tags
Return values
string —unquoted table name.
createColumnSchema()
Creates a column schema for the database.
protected
createColumnSchema() : ColumnSchema
This method may be overridden by child classes to create a DBMS-specific column schema.
Tags
Return values
ColumnSchema —column schema instance.
findSchemaNames()
Returns all schema names in the database, including the default one but not system schemas.
protected
findSchemaNames() : array<string|int, mixed>
This method should be overridden by child classes in order to support this feature because the default implementation simply throws an exception.
Tags
Return values
array<string|int, mixed> —all schema names in the database, except system schemas.
findTableNames()
Returns all table names in the database.
protected
findTableNames([string $schema = '' ]) : array<string|int, mixed>
This method should be overridden by child classes in order to support this feature because the default implementation simply throws an exception.
Parameters
- $schema : string = ''
-
the schema of the tables. Defaults to empty string, meaning the current or default schema.
Tags
Return values
array<string|int, mixed> —all table names in the database. The names have NO schema name prefix.
getCacheKey()
Returns the cache key for the specified table name.
protected
getCacheKey(string $name) : mixed
Parameters
- $name : string
-
the table name.
Return values
mixed —the cache key.
getCacheTag()
Returns the cache tag name.
protected
getCacheTag() : string
This allows [[refresh()]] to invalidate all cached table schemas.
Return values
string —the cache tag name
getColumnPhpType()
Extracts the PHP type from abstract DB type.
protected
getColumnPhpType(ColumnSchema $column) : string
Parameters
- $column : ColumnSchema
-
the column schema information
Return values
string —PHP type name
getSchemaMetadata()
Returns the metadata of the given type for all tables in the given schema.
protected
getSchemaMetadata(string $schema, string $type, bool $refresh) : array<string|int, mixed>
This method will call a 'getTable' . ucfirst($type)
named method with the table name
and the refresh flag to obtain the metadata.
Parameters
- $schema : string
-
the schema of the metadata. Defaults to empty string, meaning the current or default schema name.
- $type : string
-
metadata type.
- $refresh : bool
-
whether to fetch the latest available table metadata. If this is
false
, cached data may be returned if available.
Tags
Return values
array<string|int, mixed> —array of metadata.
getTableMetadata()
Returns the metadata of the given type for the given table.
protected
getTableMetadata(string $name, string $type, bool $refresh) : mixed
If there's no metadata in the cache, this method will call
a 'loadTable' . ucfirst($type)
named method with the table name to obtain the metadata.
Parameters
- $name : string
-
table name. The table name may contain schema name if any. Do not quote the table name.
- $type : string
-
metadata type.
- $refresh : bool
-
whether to reload the table metadata even if it is found in the cache.
Tags
Return values
mixed —metadata.
getTableNameParts()
Splits full table name into parts
protected
getTableNameParts(string $name) : array<string|int, mixed>
Parameters
- $name : string
Tags
Return values
array<string|int, mixed>loadTableSchema()
Loads the metadata for the specified table.
protected
abstract loadTableSchema(string $name) : TableSchema|null
Parameters
- $name : string
-
table name
Return values
TableSchema|null —DBMS-dependent table metadata, null
if the table does not exist.
normalizePdoRowKeyCase()
Changes row's array key case to lower if PDO's one is set to uppercase.
protected
normalizePdoRowKeyCase(array<string|int, mixed> $row, bool $multiple) : array<string|int, mixed>
Parameters
- $row : array<string|int, mixed>
-
row's array or an array of row's arrays.
- $multiple : bool
-
whether multiple rows or a single row passed.
Tags
Return values
array<string|int, mixed> —normalized row or rows.
resolveTableName()
Resolves the table name and schema name (if any).
protected
resolveTableName(string $name) : TableSchema
Parameters
- $name : string
-
the table name
Tags
Return values
TableSchema —[[TableSchema]] with resolved table, schema, etc. names.
setTableMetadata()
Sets the metadata of the given type for the given table.
protected
setTableMetadata(string $name, string $type, mixed $data) : mixed
Parameters
- $name : string
-
table name.
- $type : string
-
metadata type.
- $data : mixed
-
metadata.
Tags
loadTableMetadataFromCache()
Tries to load and populate table metadata from cache.
private
loadTableMetadataFromCache(Cache|null $cache, string $name) : mixed
Parameters
- $cache : Cache|null
- $name : string
saveTableMetadataToCache()
Saves table metadata to cache.
private
saveTableMetadataToCache(Cache|null $cache, string $name) : mixed
Parameters
- $cache : Cache|null
- $name : string