function drupal_schema_fields_sql

Retrieves a list of fields from a table schema.

The returned list is suitable for use in an SQL query.

Parameters

string $table: The name of the table from which to retrieve fields.

string $prefix: An optional prefix to to all fields.

Return value

array An array of fields.

Related topics

8 calls to drupal_schema_fields_sql()
DatabaseStorageController::buildQuery in drupal/core/lib/Drupal/Core/Entity/DatabaseStorageController.php
Builds the query to load the entity.
DatabaseStorageControllerNG::attachPropertyData in drupal/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php
Attaches property data in all languages for translatable properties.
DatabaseStorageControllerNG::buildQuery in drupal/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php
Builds the query to load the entity.
DatabaseStorageControllerNG::mapToDataStorageRecord in drupal/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php
Maps from an entity object to the storage record of the data table.
DatabaseStorageControllerNG::mapToRevisionStorageRecord in drupal/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php
Maps from an entity object to the storage record of the revision table.

... See full list

File

drupal/core/includes/schema.inc, line 333
Schema API handling functions.

Code

function drupal_schema_fields_sql($table, $prefix = NULL) {
  if (!($schema = drupal_get_schema($table))) {
    return array();
  }
  $fields = array_keys($schema['fields']);
  if ($prefix) {
    $columns = array();
    foreach ($fields as $field) {
      $columns[] = "{$prefix}.{$field}";
    }
    return $columns;
  }
  else {
    return $fields;
  }
}