You are here

function drupal_schema_get_field_value in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/includes/schema.inc \drupal_schema_get_field_value()

Typecasts values to proper datatypes.

MySQL PDO silently casts, e.g. FALSE and '' to 0, when inserting the value into an integer column, but PostgreSQL PDO does not. Look up the schema information and use that to correctly typecast the value.

Parameters

array $info: An array describing the schema field info.

mixed $value: The value to be converted.

Return value

mixed The converted value.

Related topics

1 call to drupal_schema_get_field_value()
SqlContentEntityStorage::mapToStorageRecord in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
Maps from an entity object to the storage record.

File

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

Code

function drupal_schema_get_field_value(array $info, $value) {

  // Preserve legal NULL values.
  if (isset($value) || !empty($info['not null'])) {
    if ($info['type'] == 'int' || $info['type'] == 'serial') {
      $value = (int) $value;
    }
    elseif ($info['type'] == 'float') {
      $value = (double) $value;
    }
    elseif (!is_array($value)) {
      $value = (string) $value;
    }
  }
  return $value;
}