Schema
abstract class Schema implements PlaceholderInterface (View source)
Provides a base implementation for Database Schema.
Properties
| protected Connection | $connection | The database connection. |
|
| protected int | $placeholder | The placeholder counter. |
|
| protected string | $defaultSchema | Definition of prefixInfo array structure. |
|
| protected string | $uniqueIdentifier | A unique identifier for this query object. |
Methods
No description
Implements the magic __clone function.
Returns a unique identifier for this object.
Returns the next placeholder ID for the query.
Get information about the table name and schema from the prefix.
Create names for indexes, primary keys and constraints.
Build a condition to match a table name against a standard information_schema.
Check if a table exists.
Finds all tables that are like the specified base table name.
Check if a column exists in the given table.
Returns a mapping of Drupal schema field names to DB-native field types.
Rename a table.
Drop a table.
Add a new field to a table.
Drop a field.
Checks if an index exists in the given table.
Add a primary key.
Drop the primary key.
Finds the primary key columns of a table, from the database.
Add a unique key.
Drop a unique key.
Add an index.
Drop an index.
Finds the columns for the primary key, unique keys and indexes of a table.
Change a field definition.
Create a new table from a Drupal table definition.
Return an array of field names from an array of key/index column specifiers.
Prepare a table or column comment for database query.
Return an escaped version of its parameter to be used as a default value on a column.
Ensures that all the primary key fields are correctly defined.
Details
__construct($connection)
No description
__clone()
Implements the magic __clone function.
uniqueIdentifier()
Returns a unique identifier for this object.
The
nextPlaceholder()
Returns the next placeholder ID for the query.
protected array
getPrefixInfo(string $table = 'default', bool $add_prefix = TRUE)
Get information about the table name and schema from the prefix.
prefixNonTable($table)
Create names for indexes, primary keys and constraints.
This prevents using } around non-table names like indexes and keys.
protected Condition
buildTableNameCondition($table_name, $operator = '=', $add_prefix = TRUE)
Build a condition to match a table name against a standard information_schema.
The information_schema is a SQL standard that provides information about the database server and the databases, schemas, tables, columns and users within it. This makes information_schema a useful tool to use across the drupal database drivers and is used by a few different functions. The function below describes the conditions to be meet when querying information_schema.tables for drupal tables or information associated with drupal tables. Even though this is the standard method, not all databases follow standards and so this method should be overwritten by a database driver if the database provider uses alternate methods. Because information_schema.tables is used in a few different functions, a database driver will only need to override this function to make all the others work. For example see core/includes/databases/mysql/schema.inc.
true
tableExists($table)
Check if a table exists.
array
findTables(string $table_expression)
Finds all tables that are like the specified base table name.
true
fieldExists(string $table, string $column)
Check if a column exists in the given table.
abstract array
getFieldTypeMap()
Returns a mapping of Drupal schema field names to DB-native field types.
Because different field types do not map 1:1 between databases, Drupal has its own normalized field type names. This function returns a driver-specific mapping table from Drupal names to the native names for each database.
abstract
renameTable($table, $new_name)
Rename a table.
abstract true
dropTable($table)
Drop a table.
abstract
addField($table, $field, $spec, $keys_new = [])
Add a new field to a table.
abstract true
dropField($table, $field)
Drop a field.
abstract true
indexExists($table, $name)
Checks if an index exists in the given table.
abstract
addPrimaryKey($table, $fields)
Add a primary key.
abstract true
dropPrimaryKey($table)
Drop the primary key.
protected string[]|false
findPrimaryKeyColumns(string $table)
Finds the primary key columns of a table, from the database.
abstract
addUniqueKey($table, $name, $fields)
Add a unique key.
abstract true
dropUniqueKey($table, $name)
Drop a unique key.
abstract
addIndex($table, $name, $fields, array $spec)
Add an index.
abstract true
dropIndex($table, $name)
Drop an index.
protected array
introspectIndexSchema(string $table)
Finds the columns for the primary key, unique keys and indexes of a table.
abstract
changeField($table, $field, $field_new, $spec, $keys_new = [])
Change a field definition.
IMPORTANT NOTE: To maintain database portability, you have to explicitly recreate all indices and primary keys that are using the changed field.
That means that you have to drop all affected keys and indexes with Schema::dropPrimaryKey(), Schema::dropUniqueKey(), or Schema::dropIndex() before calling ::changeField(). To recreate the keys and indices, pass the key definitions as the optional $keys_new argument directly to ::changeField().
For example, suppose you have:
createTable($name, $table)
Create a new table from a Drupal table definition.
An
fieldNames($fields)
Return an array of field names from an array of key/index column specifiers.
This is usually an identity function but if a key/index uses a column prefix specification, this function extracts just the name.
The
prepareComment($comment, $length = NULL)
Prepare a table or column comment for database query.
protected string|int|float
escapeDefaultValue(mixed $value)
Return an escaped version of its parameter to be used as a default value on a column.
protected
ensureNotNullPrimaryKey(array $primary_key, array $fields)
Ensures that all the primary key fields are correctly defined.