Schema
class Schema extends Schema (View source)
SQLite implementation of \Drupal\Core\Database\Schema.
Properties
| protected Connection | $connection | The database connection. |
from Schema |
| protected int | $placeholder | The placeholder counter. |
from Schema |
| protected string | $defaultSchema | Override DatabaseSchema::$defaultSchema |
|
| protected string | $uniqueIdentifier | A unique identifier for this query object. |
from Schema |
Methods
Get information about the table name and schema from the prefix.
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.
Set the default value for a field.
Set a field to have no default value.
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.
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.
Generate SQL to create a new table from a Drupal schema definition.
Build the SQL expression for indexes.
Build the SQL expression for creating columns.
Build the SQL expression for keys.
Set database-engine specific properties for a field.
Create an SQL string for a field to be used in table creation or alteration.
Create a table with a new schema containing the old content.
Find out the schema of a table.
Utility method: rename columns in an index definition according to a new mapping.
Details
in
Schema at line 46
__construct($connection)
No description
in
Schema at line 54
__clone()
Implements the magic __clone function.
in
Schema at line 61
uniqueIdentifier()
Returns a unique identifier for this object.
in
Schema at line 68
The
nextPlaceholder()
Returns the next placeholder ID for the query.
in
Schema at line 84
protected A
getPrefixInfo($table = 'default', $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($table, $column)
Check if a column exists in the given table.
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.
renameTable($table, $new_name)
Rename a table.
true
dropTable($table)
Drop a table.
addField($table, $field, $specification, $keys_new = [])
Add a new field to a table.
true
dropField($table, $field)
Drop a field.
fieldSetDefault($table, $field, $default)
Set the default value for a field.
fieldSetNoDefault($table, $field)
Set a field to have no default value.
true
indexExists($table, $name)
Checks if an index exists in the given table.
addPrimaryKey($table, $fields)
Add a primary key.
true
dropPrimaryKey($table)
Drop the primary key.
protected string[]|false
findPrimaryKeyColumns(string $table)
Finds the primary key columns of a table, from the database.
addUniqueKey($table, $name, $fields)
Add a unique key.
true
dropUniqueKey($table, $name)
Drop a unique key.
addIndex($table, $name, $fields, array $spec)
Add an index.
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.
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.
An
createTableSql($name, $table)
Generate SQL to create a new table from a Drupal schema definition.
protected
createIndexSql($tablename, $schema)
Build the SQL expression for indexes.
protected
createColumnsSql($tablename, $schema)
Build the SQL expression for creating columns.
protected
createKeySql($fields)
Build the SQL expression for keys.
protected
processField($field)
Set database-engine specific properties for a field.
protected
createFieldSql($name, $spec)
Create an SQL string for a field to be used in table creation or alteration.
Before passing a field out of a schema definition into this function it has to be processed by self::processField().
protected
alterTable($table, $old_schema, $new_schema, array $mapping = [])
Create a table with a new schema containing the old content.
As SQLite does not support ALTER TABLE (with a few exceptions) it is necessary to create a new table and copy over the old content.
protected An
introspectSchema($table)
Find out the schema of a table.
This function uses introspection methods provided by the database to create a schema array. This is useful, for example, during update when the old schema is not available.
protected
mapKeyDefinition(array $key_definition, array $mapping)
Utility method: rename columns in an index definition according to a new mapping.