drupal_schema_get_field_value

drupal_schema_get_field_value(array $info, $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

Schema API
API to handle database schemas.

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 = (float) $value;
    }
    elseif (!is_array($value)) {
      $value = (string) $value;
    }
  }
  return $value;
}
doc_Drupal
2016-10-29 09:03:20
Comments
Leave a Comment

Please login to continue.