6.x common.inc drupal_get_schema($table = NULL, $rebuild = FALSE)
7.x bootstrap.inc drupal_get_schema($table = NULL, $rebuild = FALSE)

Gets 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(). To get the schema without modifications, use drupal_get_schema_unprocessed().

Parameters

$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.

Related topics

27 calls to 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.
DatabaseSelectComplexTestCase2::setUp in modules/simpletest/tests/database_test.test
Sets up a Drupal site for running functional and integration tests.
DatabaseTestCase::ensureSampleDataNull in modules/simpletest/tests/database_test.test
Set up tables for NULL handling.
DatabaseTestCase::setUp in modules/simpletest/tests/database_test.test
Sets up a Drupal site for running functional and integration tests.

... See full list

File

includes/bootstrap.inc, line 3254
Functions that need to be loaded on every Drupal request.

Code

function drupal_get_schema($table = NULL, $rebuild = FALSE) {
  static $schema;
  if ($rebuild || !isset($table)) {
    $schema = drupal_get_complete_schema($rebuild);
  }
  elseif (!isset($schema)) {
    $schema = new SchemaCache();
  }
  if (!isset($table)) {
    return $schema;
  }
  if (isset($schema[$table])) {
    return $schema[$table];
  }
  else {
    return FALSE;
  }
}

Comments

Lang Wu Jane’s picture

Curious on why not returning the column description with other information at the same time?
In my cases, I'd like to update the column description. Now I have to copy and paste the description T_T

Lang Wu Jane’s picture

It seems in my cases, I'd better to use drupal_get_schema_unprocessed to get exactly what's come up from hook_schema and hook_schema_alter

Renorram’s picture

drupal_write_record calls drupal_get_schema to know wich fields are gonna be inserted, if you use drupal_write_record and try do add a field that is not on your module hook_schema drupal_write_record will ignore it. In my case i added a new field via db_add_field in a hook_update_N and had to change my calls of drupal_write_record to db_insert.