General class for an abstracted DELETE operation.
Expanded class hierarchy of Delete
class Delete extends Query implements ConditionInterface {
/**
* The table from which to delete.
*
* @var string
*/
protected $table;
/**
* The condition object for this query.
*
* Condition handling is handled via composition.
*
* @var Condition
*/
protected $condition;
/**
* Constructs a Delete object.
*
* @param Drupal\Core\Database\Connection $connection
* A DatabaseConnection object.
* @param string $table
* Name of the table to associate with this query.
* @param array $options
* Array of database options.
*/
public function __construct(Connection $connection, $table, array $options = array()) {
$options['return'] = Database::RETURN_AFFECTED;
parent::__construct($connection, $options);
$this->table = $table;
$this->condition = new Condition('AND');
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::condition().
*/
public function condition($field, $value = NULL, $operator = NULL) {
$this->condition
->condition($field, $value, $operator);
return $this;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::isNull().
*/
public function isNull($field) {
$this->condition
->isNull($field);
return $this;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::isNotNull().
*/
public function isNotNull($field) {
$this->condition
->isNotNull($field);
return $this;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::exists().
*/
public function exists(SelectInterface $select) {
$this->condition
->exists($select);
return $this;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::notExists().
*/
public function notExists(SelectInterface $select) {
$this->condition
->notExists($select);
return $this;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::conditions().
*/
public function &conditions() {
return $this->condition
->conditions();
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::arguments().
*/
public function arguments() {
return $this->condition
->arguments();
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::where().
*/
public function where($snippet, $args = array()) {
$this->condition
->where($snippet, $args);
return $this;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::compile().
*/
public function compile(Connection $connection, PlaceholderInterface $queryPlaceholder) {
return $this->condition
->compile($connection, $queryPlaceholder);
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::compiled().
*/
public function compiled() {
return $this->condition
->compiled();
}
/**
* Executes the DELETE query.
*
* @return
* The return value is dependent on the database connection.
*/
public function execute() {
$values = array();
if (count($this->condition)) {
$this->condition
->compile($this->connection, $this);
$values = $this->condition
->arguments();
}
return $this->connection
->query((string) $this, $values, $this->queryOptions);
}
/**
* Implements PHP magic __toString method to convert the query to a string.
*
* @return string
* The prepared statement.
*/
public function __toString() {
// Create a sanitized comment string to prepend to the query.
$comments = $this->connection
->makeComment($this->comments);
$query = $comments . 'DELETE FROM {' . $this->connection
->escapeTable($this->table) . '} ';
if (count($this->condition)) {
$this->condition
->compile($this->connection, $this);
$query .= "\nWHERE " . $this->condition;
}
return $query;
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Delete:: |
protected | property | The condition object for this query. | |
Delete:: |
protected | property | The table from which to delete. | |
Delete:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::arguments(). Overrides ConditionInterface:: |
|
Delete:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::compile(). Overrides ConditionInterface:: |
|
Delete:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::compiled(). Overrides ConditionInterface:: |
|
Delete:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::condition(). Overrides ConditionInterface:: |
|
Delete:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::conditions(). Overrides ConditionInterface:: |
|
Delete:: |
public | function |
Executes the DELETE query. Overrides Query:: |
1 |
Delete:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::exists(). Overrides ConditionInterface:: |
|
Delete:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::isNotNull(). Overrides ConditionInterface:: |
|
Delete:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::isNull(). Overrides ConditionInterface:: |
|
Delete:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::notExists(). Overrides ConditionInterface:: |
|
Delete:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::where(). Overrides ConditionInterface:: |
|
Delete:: |
public | function |
Constructs a Delete object. Overrides Query:: |
|
Delete:: |
public | function |
Implements PHP magic __toString method to convert the query to a string. Overrides Query:: |
|
Query:: |
protected | property | An array of comments that can be prepended to a query. | |
Query:: |
protected | property | The connection object on which to run this query. | |
Query:: |
protected | property | The key of the connection object. | |
Query:: |
protected | property | The target of the connection object. | |
Query:: |
protected | property | The placeholder counter. | |
Query:: |
protected | property | The query options to pass on to the connection object. | |
Query:: |
protected | property | A unique identifier for this query object. | |
Query:: |
public | function | Adds a comment to the query. | |
Query:: |
public | function | Returns a reference to the comments array for the query. | |
Query:: |
public | function |
Gets the next placeholder value for this query object. Overrides PlaceholderInterface:: |
|
Query:: |
public | function |
Returns a unique identifier for this object. Overrides PlaceholderInterface:: |
|
Query:: |
public | function | Implements the magic __clone function. | 1 |
Query:: |
public | function | Implements the magic __sleep function to disconnect from the database. | |
Query:: |
public | function | Implements the magic __wakeup function to reconnect to the database. |