drupal_get_schema

  1. drupal
    1. drupal6
    2. drupal7 bootstrap.inc
Versionen
drupal6 – drupal7 drupal_get_schema($table = NULL, $rebuild = FALSE)

Get the schema definition of a table, or the whole database schema.

The returned schema will include any modifications made by any module that implements hook_schema_alter().

Übergabeparameter

$table The name of the table. If not given, the schema of all tables is returned.

$rebuild If true, the schema will be rebuilt instead of retrieved from the cache.

Verwandte Themen

▾ 2 functions call drupal_get_schema()

drupal_schema_fields_sql in includes/common.inc
Retrieve a list of fields from a table schema. The list is suitable for use in a SQL query.
drupal_write_record in includes/common.inc
Save a record to the database based upon the schema.

Code

includes/common.inc, line 3259

<?php
function drupal_get_schema($table = NULL, $rebuild = FALSE) {
  static $schema = array();

  if (empty($schema) || $rebuild) {
    // Try to load the schema from cache.
    if (!$rebuild && $cached = cache_get('schema')) {
      $schema = $cached->data;
    }
    // Otherwise, rebuild the schema cache.
    else {
      $schema = array();
      // Load the .install files to get hook_schema.
      module_load_all_includes('install');

      // Invoke hook_schema for all modules.
      foreach (module_implements('schema') as $module) {
        // Cast the result of hook_schema() to an array, as a NULL return value
        // would cause array_merge() to set the $schema variable to NULL as well.
        // That would break modules which use $schema further down the line.
        $current = (array) module_invoke($module, 'schema');
        _drupal_initialize_schema($module, $current);
        $schema = array_merge($schema, $current);
      }

      drupal_alter('schema', $schema);
      cache_set('schema', $schema);
    }
  }

  if (!isset($table)) {
    return $schema;
  }
  elseif (isset($schema[$table])) {
    return $schema[$table];
  }
  else {
    return FALSE;
  }
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen