public function DataHandler::delete in Data 6
Same name and namespace in other branches
- 8 includes/DataHandler.inc \DataHandler::delete()
- 7 includes/DataHandler.inc \DataHandler::delete()
Delete one or more records from the table.
Parameters
$clause: An array where the keys are columns in the data table and the values are the values to filter on. This array will be turned into the where clause of the delete query.
Example:
array( 'feed_nid' => 10, 'timestamp' => array( '<', 1255623780, ), );
File
- includes/
DataHandler.inc, line 152 - Definition of DataHandler class.
Class
- DataHandler
- Simple access methods to table data. Can be used on any table, not just Data managed tables.
Code
public function delete($clause) {
$query = new DataQuery($this->table);
$schema = drupal_get_schema($this->table);
$fields = $schema['fields'];
foreach ($clause as $key => $value) {
$operator = '=';
if (is_array($value)) {
$operator = array_shift($value);
$value = array_shift($value);
}
$query
->addWhere(db_escape_table($this->table) . '.' . db_escape_string($key) . " " . $operator . " " . db_type_placeholder($fields[$key]['type']), $value);
}
drupal_alter('data_delete_query', $query, $this->table);
if (!empty($query->where)) {
$query
->execute();
}
return db_affected_rows();
}