drupal_get_schema

  1. drupal
    1. drupal6 common.inc
    2. drupal7
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

▾ 13 functions call drupal_get_schema()

DatabaseInsertDefaultsTestCase::testDefaultInsert in modules/simpletest/tests/database_test.test
Test that we can run a query that is "default values for everything".
DatabaseInsertDefaultsTestCase::testDefaultInsertWithFields in modules/simpletest/tests/database_test.test
Test that we can insert fields with values and defaults in the same query.
DatabaseTestCase::ensureSampleDataNull in modules/simpletest/tests/database_test.test
Set up tables for NULL handling.
DatabaseTestCase::setUp in modules/simpletest/tests/database_test.test
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.
field_cache_clear in modules/field/field.module
Clear the cached information; called in several places when field information is changed.
install_tasks in ./install.php
Tasks performed after the database is initialized.
profile_field_form_validate in modules/profile/profile.admin.inc
Validate profile_field_form submissions.
setUp in modules/simpletest/drupal_web_test_case.php
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix.…
tearDown in modules/simpletest/drupal_web_test_case.php
Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix.
user_save in modules/user/user.module
Save changes to a user account or add a new user.
user_user_validate in modules/user/user.module
Implementation of hook_user_validate().

Code

includes/bootstrap.inc, line 1591

<?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.
      // On some databases this function may be called before bootstrap has
      // been completed, so we force the functions we need to load just in case.
      if (drupal_function_exists('module_load_all_includes')) {

        // There is currently a bug in module_list() where it caches what it
        // was last called with, which is not always what you want.
        // module_load_all_includes() calls module_list(), but if this function
        // is called very early in the bootstrap process then it will be
        // uninitialized and therefore return no modules. Instead, we have to
        // "prime" module_list() here to to values we want, specifically
        // "yes rebuild the list and don't limit to bootstrap".
        // TODO: Remove this call after http://drupal.org/node/222109 is fixed.
        module_list(TRUE);
        module_load_all_includes('install');
      }

      require_once DRUPAL_ROOT . '/includes/common.inc';
      // Invoke hook_schema for all modules.
      foreach (module_implements('schema') as $module) {
        $current = module_invoke($module, 'schema');
        if (drupal_function_exists('_drupal_initialize_schema')) {
          _drupal_initialize_schema($module, $current);
        }

        $schema = array_merge($schema, $current);
      }

      if (drupal_function_exists('drupal_alter')) {
        drupal_alter('schema', $schema);
      }

      // If the schema is empty, avoid saving it: some database engines require
      // the schema to perform queries, and this could lead to infinite loops.
      if (!empty($schema) && (drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL)) {
        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