function 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

2 calls to drupal_schema_get_field_value()
DatabaseStorageControllerNG::mapToDataStorageRecord in drupal/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php
Maps from an entity object to the storage record of the data table.
drupal_write_record in drupal/core/includes/schema.inc
Saves (inserts or updates) a record to the database based upon the schema.

File

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

Code

function drupal_schema_get_field_value(array $info, $value) {
  if ($info['type'] == 'int' || $info['type'] == 'serial') {
    $value = (int) $value;
  }
  elseif ($info['type'] == 'float') {
    $value = (double) $value;
  }
  else {
    $value = (string) $value;
  }
  return $value;
}