You are here

function merci_delete_record in MERCI (Manage Equipment Reservations, Checkout and Inventory) 6.2

Same name and namespace in other branches
  1. 7.2 includes/database.inc \merci_delete_record()
3 calls to merci_delete_record()
merci_delete in ./merci.module
Implementation of hook_delete().
merci_node_delete in ./merci.module
merci_node_revision_delete in ./merci.module

File

includes/database.inc, line 123
MERCI - Managed Equipment Reservation Checkout and Inventory

Code

function merci_delete_record($table, &$object, $update = array()) {

  // Standardize $update to an array.
  if (is_string($update)) {
    $update = array(
      $update,
    );
  }
  $schema = drupal_get_schema($table);
  if (empty($schema)) {
    return FALSE;
  }

  // Convert to an object if needed.
  if (is_array($object)) {
    $object = (object) $object;
    $array = TRUE;
  }
  else {
    $array = FALSE;
  }
  $fields = $values = array();

  // Build the SQL.
  $query = '';
  foreach ($update as $key) {
    $conditions[] = "{$key} = " . db_type_placeholder($schema['fields'][$key]['type']);
    $values[] = $object->{$key};
  }
  $query = "DELETE FROM {" . $table . "} WHERE " . implode(' AND ', $conditions);

  // Execute the SQL.
  if (db_query($query, $values)) {
    $return = true;
  }
  else {
    $return = FALSE;
  }

  // If we began with an array, convert back so we don't surprise the caller.
  if ($array) {
    $object = (array) $object;
  }
  return $return;
}