Last updated October 22, 2011. Created on August 22, 2010.
Edited by chx, arianek, yched, agentrickard. Log in to edit this page.

The Field SQL Storage module provides data management for the Field module. This module uses the Field API to generate dynamic data tables for entities and fields. While this is a required core module, it may be replaced by other contributed modules that implement The Field Storage API.

Uses

This module is an internal developer API and provides no user interface.

Versions

Drupal 7

The Field SQL Storage module was introduced in Drupal 7.

Details

Default module: Yes
Dependencies: Field
Related Modules: Field
Permissions: None
API Documentation: Field storage API
Database tables:

You might find this information in $field['storage']['details'];. The usage of this array is very strongly discouraged and is known not to work in certain cases, like inside hook_update_N

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

rooby’s picture

If it is recommended to use _field_sql_storage_tablename() & _field_sql_storage_revision_tablename() why are they private functions?

heddn’s picture

I ignored the comment in the above guide without issue. But note, other backends don't have a fully implemented hook_field_storage_details() so this really provide an easy method to gather table & column names on sql backed storage.

  $schema = example_field_schema_7000();
  $fields = field_read_fields(array('type' => 'example_type'));
  $field_info = new FieldInfo();
  foreach ($fields as $field) {
    $prepared = $field_info->prepareField($field);
    foreach ($prepared['storage']['details'] as $storage) {
      // This is known to work with sql storage backend, but not others.
      // For example, mongodb has an empty hook_field_storage_details().
      $age_arguments = array(FIELD_LOAD_CURRENT, FIELD_LOAD_REVISION);
      foreach ($age_arguments as $age) {
        if (empty($storage[$age])) {
          throw new DrupalUpdateException('Unsupported storage backend');
        }
        foreach ($storage[$age] as $table => $columns) {
          foreach ($columns as $name => $column) {
            if (!db_field_exists($table, $column)) {
              db_add_field($table, $column, $schema['columns'][$name]);
            }
          }
        }
      }
    }
  }
Kebz’s picture

I was wondering... can anyone PLEASE help me with this. I am completely locked out of my website. So the only solutions are ... create the "missing" table it is looking for -- or uninstall the "membership" modules - or restore database to how it was before this error came up.

I need to do something because I can't have it sit in this mode and I have people waiting for my site to go live.


How to recover from this ERROR below??
===========================

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dbxxx.xxxfield_data_membership_entity_term_ref' doesn't exist: SELECT t.* FROM {field_data_membership_entity_term_ref} t WHERE (entity_type = :db_condition_placeholder_0) AND (entity_id IN (:db_condition_placeholder_1)) AND (language IN (:db_condition_placeholder_2)) AND (deleted = :db_condition_placeholder_3) ORDER BY delta ASC; Array ( [:db_condition_placeholder_0] => commerce_line_item [:db_condition_placeholder_1] => 1 [:db_condition_placeholder_2] => und [:db_condition_placeholder_3] => 0 ) in field_sql_storage_field_storage_load() (line 392 of .../modules/field/modules/field_sql_storage/field_sql_storage.module).

Backtrace:
PDOStatement->execute(Array) database.inc:2171
DatabaseStatementBase->execute(Array, Array) database.inc:683
DatabaseConnection->query('SELECT t.*
FROM
{field_data_membership_entity_term_ref} t
WHERE (entity_type = :db_condition_placeholder_0) AND (entity_id IN (:db_condition_placeholder_1)) AND (language IN (:db_condition_placeholder_2)) AND (deleted = :db_condition_placeholder_3)
ORDER BY delta ASC', Array, Array) select.inc:1265
SelectQuery->execute() field_sql_storage.module:392
field_sql_storage_field_storage_load('commerce_line_item', Array, 'FIELD_LOAD_CURRENT', Array, Array)
call_user_func_array('field_sql_storage_field_storage_load', Array) module.inc:866
module_invoke('field_sql_storage', 'field_storage_load', 'commerce_line_item', Array, 'FIELD_LOAD_CURRENT', Array, Array) field.attach.inc:709
field_attach_load('commerce_line_item', Array) entity.inc:316
DrupalDefaultEntityController->attachLoad(Array, ) commerce_line_item.controller.inc:114
CommerceLineItemEntityController->attachLoad(Array, ) entitycache.module:108
EntityCacheControllerHelper::entityCacheLoad(Object, Array, Array) commerce_entitycache.line_item.inc:24
CommerceEntityCacheCommerceLineItemEntityController->load(Array, Array) common.inc:7849
entity_load('commerce_line_item', Array) entity.wrapper.inc:715
EntityDrupalWrapper->value() entity.wrapper.inc:660
EntityDrupalWrapper->spotBundleInfo(1) entity.wrapper.inc:640
EntityDrupalWrapper->spotInfo() entity.wrapper.inc:330
EntityStructureWrapper->getPropertyInfo('type') entity.wrapper.inc:392
EntityStructureWrapper->get('type') entity.wrapper.inc:413
EntityStructureWrapper->__get('type') commerce_line_item.module:1434
commerce_line_items_quantity(Object, Array) commerce_cart.module:80
commerce_cart_menu_item_title(1)
call_user_func_array('commerce_cart_menu_item_title', Array) menu.inc:701
_menu_item_localize(Array, Array, 1) menu.inc:931
_menu_link_translate(Array) menu.inc:1512
_menu_tree_check_access(Array) menu.inc:1515
_menu_tree_check_access(Array) menu.inc:1502
menu_tree_check_access(Array, Array) menu.inc:1355
menu_build_tree('user-menu', Array) menu.inc:1147
menu_tree_all_data('user-menu') superfish.module:1548
theme_superfish(Array) override_functions.inc:613
nucleus_superfish(Array) theme.inc:1161
theme('superfish', Array) superfish.module:1003
superfish_contents('1') superfish.module:1075
superfish_block_view('1')
call_user_func_array('superfish_block_view', Array) module.inc:866
module_invoke('superfish', 'block_view', '1') block.module:902
_block_render_blocks(Array) block.module:686
block_list('highlighted') block.module:318
block_get_blocks_by_region('highlighted') block.module:268
block_page_build(Array) common.inc:5784
drupal_render_page(Array) common.inc:2701
drupal_deliver_html_page(Array) common.inc:2589
drupal_deliver_page(Array, '') menu.inc:532
menu_execute_active_handler() index.php:21

~Kebz