A Drupal schema definition is an array structure representing one or more tables and their related keys and indexes. A schema is defined by hook_schema(), which usually lives in a modulename.install file.
By implementing hook_schema() and specifying the tables your module declares, you can easily create and drop these tables on all supported database engines. You don't have to deal with the different SQL dialects for table creation and alteration of the supported database engines.
hook_schema() should return an array with a key for each table that the module defines.
The following keys are defined:
Not all sizes are available for all data types. See db_type_map() for possible combinations.
All parameters apart from 'type' are optional except that type 'numeric' columns must specify 'precision' and 'scale'.
A key column specifier is either a string naming a column or an array of two elements, column name and length, specifying a prefix of the named column.
As an example, here is a SUBSET of the schema definition for Drupal's 'node' table. It show four fields (nid, vid, type, and title), the primary key on field 'nid', a unique key named 'vid' on field 'vid', and two indexes, one named 'nid' on field 'nid' and one named 'node_title_type' on the field 'title' and the first four bytes of the field 'type':
<?php
$schema['node'] = array(
'fields' => array(
'nid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'type' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
'title' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
),
'primary key' => array('nid'),
'unique keys' => array(
'vid' => array('vid')
),
'foreign keys' => array(
'uid' => array('users' => 'uid'),
)
'indexes' => array(
'nid' => array('nid'),
'node_title_type' => array('title', array('type', 4)),
),
);
?>
| Name | Beschreibung |
|---|---|
| DatabaseSchema | |
| DatabaseSchema_mysql | |
| DatabaseSchema_pgsql | |
| DatabaseSchema_sqlite |
| Name | Beschreibung |
|---|---|
| addField | Add a new field to a table. |
| addIndex | Add an index. |
| addPrimaryKey | Add a primary key. |
| addUniqueKey | Add a unique key. |
| buildTableNameCondition | Build a condition to match a table name against a standard information_schema. |
| changeField | Change a field definition. |
| columnExists | Check if a column exists in the given table. |
| createTable | Create a new table from a Drupal table definition. |
| dropField | Drop a field. |
| dropIndex | Drop an index. |
| dropPrimaryKey | Drop the primary key. |
| dropTable | Drop a table. |
| dropUniqueKey | Drop a unique key. |
| fieldNames | Return an array of field names from an array of key/index column specifiers. |
| fieldSetDefault | Set the default value for a field. |
| fieldSetNoDefault | Set a field to have no default value. |
| findTables | Find all tables that are like the specified base table name. |
| getFieldTypeMap | This maps a generic data type in combination with its data size to the engine-specific data type. |
| prepareComment | Prepare a table or column comment for database query. |
| renameTable | Rename a table. |
| tableExists | Check if a table exists. |
| __construct | |
| addField | |
| addIndex | |
| addPrimaryKey | |
| addUniqueKey | |
| buildTableNameCondition | Build a condition to match a table name against a standard information_schema. |
| changeField | |
| createFieldSql | Create an SQL string for a field to be used in table creation or alteration. |
| createKeySql | |
| createKeysSql | |
| createKeysSqlHelper | |
| createTableSql | Generate SQL to create a new table from a Drupal schema definition. |
| dropField | |
| dropIndex | |
| dropPrimaryKey | |
| dropTable | |
| dropUniqueKey | |
| fieldSetDefault | |
| fieldSetNoDefault | |
| getComment | Retrieve a table or column comment. |
| getFieldTypeMap | |
| prepareComment | |
| processField | Set database-engine specific properties for a field. |
| renameTable | |
| addField | Add a new field to a table. |
| addIndex | Add an index. |
| addPrimaryKey | Add a primary key. |
| addUniqueKey | Add a unique key. |
| changeField | Change a field definition. |
| createFieldSql | Create an SQL string for a field to be used in table creation or alteration. |
| createTableSql | Generate SQL to create a new table from a Drupal schema definition. |
| dropField | Drop a field. |
| dropIndex | Drop an index. |
| dropPrimaryKey | Drop the primary key. |
| dropTable | Drop a table. |
| dropUniqueKey | Drop a unique key. |
| fieldSetDefault | Set the default value for a field. |
| fieldSetNoDefault | Set a field to have no default value. |
| getComment | Retrieve a table or column comment. |
| getFieldTypeMap | This maps a generic data type in combination with its data size to the engine-specific data type. |
| processField | Set database-engine specific properties for a field. |
| queryTableInformation | Fetch the list of blobs and sequences used on a table. |
| renameTable | Rename a table. |
| _createIndexSql | |
| _createKeys | |
| _createKeySql | |
| addField | Add a new field to a table. |
| addIndex | Add an index. |
| addPrimaryKey | Add a primary key. |
| addUniqueKey | Add a unique key. |
| alterTable | Create a table with a new schema containing the old content. |
| changeField | Change a field definition. |
| columnExists | |
| createColumsSql | Build the SQL expression for creating columns. |
| createFieldSql | Create an SQL string for a field to be used in table creation or alteration. |
| createIndexSql | Build the SQL expression for indexes. |
| createKeySql | Build the SQL expression for keys. |
| createTableSql | Generate SQL to create a new table from a Drupal schema definition. |
| dropField | Drop a field. |
| dropIndex | Drop an index. |
| dropPrimaryKey | Drop the primary key. |
| dropTable | Drop a table. |
| dropUniqueKey | Drop a unique key. |
| fieldSetDefault | Set the default value for a field. |
| fieldSetNoDefault | Set a field to have no default value. |
| findTables | Find all tables that are like the specified base table name. |
| getFieldTypeMap | This maps a generic data type in combination with its data size to the engine-specific data type. |
| introspectSchema | Find out the schema of a table. |
| processField | Set database-engine specific properties for a field. |
| renameTable | Rename a table. |
| tableExists | |
| db_add_field | Add a new field to a table. |
| db_add_index | Add an index. |
| db_add_primary_key | Add a primary key. |
| db_add_unique_key | Add a unique key. |
| db_change_field | |
| db_column_exists | Check if a column exists in the given table. |
| db_create_table | Create a new table from a Drupal table definition. |
| db_drop_field | Drop a field. |
| db_drop_index | Drop an index. |
| db_drop_primary_key | Drop the primary key. |
| db_drop_table | Drop a table. |
| db_drop_unique_key | Drop a unique key. |
| db_field_names | Return an array of field names from an array of key/index column specifiers. |
| db_field_set_default | Set the default value for a field. |
| db_field_set_no_default | Set a field to have no default value. |
| db_find_tables | Find all tables that are like the specified base table name. |
| db_rename_table | Rename a table. |
| db_table_exists | Check if a table exists. |
| db_type_map | This maps a generic data type in combination with its data size to the engine-specific data type. |
| db_type_placeholder | Given a Schema API field type, return the correct %-placeholder. |
| drupal_get_schema | Get the schema definition of a table, or the whole database schema. |
| drupal_get_schema_unprocessed | Returns the unprocessed and unaltered version of a module's schema. |
| drupal_install_schema | Create all tables that a module defines in its hook_schema(). |
| drupal_schema_fields_sql | Retrieve a list of fields from a table schema. The list is suitable for use in a SQL query. |
| drupal_uninstall_schema | Remove all tables that a module defines in its hook_schema(). |
| drupal_write_record | Save a record to the database based upon the schema. |
| _db_create_keys_sql | |
| _drupal_initialize_schema | Fill in required default values for table definitions returned by hook_schema(). |
| Name | Beschreibung |
|---|---|
| protected $connection | |
| /** * A cache of information about blob columns and sequences of tables. * * This is collected by DatabaseConnection_pgsql->queryTableInformation(), * by introspecting the database. * * @see DatabaseConnection_pgsql->queryTableInformation() * @var | A cache of information about blob columns and sequences of tables. |
| Name | Beschreibung |
|---|---|
| Maximum length of a column comment in MySQL. |
includes/
Kommentare
Kommentar hinzufügen