class DeleteQuery
General class for an abstracted DELETE operation.
Hierarchy
- class \Query implements QueryPlaceholderInterface
- class \DeleteQuery implements QueryConditionInterface
Expanded class hierarchy of DeleteQuery
Related topics
1 string reference to 'DeleteQuery'
- DatabaseConnection::delete in drupal-7.x/
includes/ database/ database.inc - Prepares and returns a DELETE query object.
File
- drupal-7.x/
includes/ database/ query.inc, line 733 - Non-specific Database query code. Used by all engines.
View source
class DeleteQuery extends Query implements QueryConditionInterface {
/**
* The table from which to delete.
*
* @var string
*/
protected $table;
/**
* The condition object for this query.
*
* Condition handling is handled via composition.
*
* @var DatabaseCondition
*/
protected $condition;
/**
* Constructs a DeleteQuery object.
*
* @param DatabaseConnection $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(DatabaseConnection $connection, $table, array $options = array()) {
$options['return'] = Database::RETURN_AFFECTED;
parent::__construct($connection, $options);
$this->table = $table;
$this->condition = new DatabaseCondition('AND');
}
/**
* Implements QueryConditionInterface::condition().
*/
public function condition($field, $value = NULL, $operator = NULL) {
$this->condition->condition($field, $value, $operator);
return $this;
}
/**
* Implements QueryConditionInterface::isNull().
*/
public function isNull($field) {
$this->condition->isNull($field);
return $this;
}
/**
* Implements QueryConditionInterface::isNotNull().
*/
public function isNotNull($field) {
$this->condition->isNotNull($field);
return $this;
}
/**
* Implements QueryConditionInterface::exists().
*/
public function exists(SelectQueryInterface $select) {
$this->condition->exists($select);
return $this;
}
/**
* Implements QueryConditionInterface::notExists().
*/
public function notExists(SelectQueryInterface $select) {
$this->condition->notExists($select);
return $this;
}
/**
* Implements QueryConditionInterface::conditions().
*/
public function &conditions() {
return $this->condition->conditions();
}
/**
* Implements QueryConditionInterface::arguments().
*/
public function arguments() {
return $this->condition->arguments();
}
/**
* Implements QueryConditionInterface::where().
*/
public function where($snippet, $args = array()) {
$this->condition->where($snippet, $args);
return $this;
}
/**
* Implements QueryConditionInterface::compile().
*/
public function compile(DatabaseConnection $connection, QueryPlaceholderInterface $queryPlaceholder) {
return $this->condition->compile($connection, $queryPlaceholder);
}
/**
* Implements QueryConditionInterface::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;
}
}
Members
Name | Modifiers | Type | Description |
---|---|---|---|
DeleteQuery:: |
protected | property | The condition object for this query. |
DeleteQuery:: |
protected | property | The table from which to delete. |
DeleteQuery:: |
public | function |
Implements QueryConditionInterface::arguments(). Overrides QueryConditionInterface:: |
DeleteQuery:: |
public | function |
Implements QueryConditionInterface::compile(). Overrides QueryConditionInterface:: |
DeleteQuery:: |
public | function |
Implements QueryConditionInterface::compiled(). Overrides QueryConditionInterface:: |
DeleteQuery:: |
public | function |
Implements QueryConditionInterface::condition(). Overrides QueryConditionInterface:: |
DeleteQuery:: |
public | function |
Implements QueryConditionInterface::conditions(). Overrides QueryConditionInterface:: |
DeleteQuery:: |
public | function |
Executes the DELETE query. Overrides Query:: |
DeleteQuery:: |
public | function |
Implements QueryConditionInterface::exists(). Overrides QueryConditionInterface:: |
DeleteQuery:: |
public | function |
Implements QueryConditionInterface::isNotNull(). Overrides QueryConditionInterface:: |
DeleteQuery:: |
public | function |
Implements QueryConditionInterface::isNull(). Overrides QueryConditionInterface:: |
DeleteQuery:: |
public | function |
Implements QueryConditionInterface::notExists(). Overrides QueryConditionInterface:: |
DeleteQuery:: |
public | function |
Implements QueryConditionInterface::where(). Overrides QueryConditionInterface:: |
DeleteQuery:: |
public | function |
Constructs a DeleteQuery object. Overrides Query:: |
DeleteQuery:: |
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 QueryPlaceholderInterface:: |
Query:: |
public | function |
Returns a unique identifier for this object. Overrides QueryPlaceholderInterface:: |
Query:: |
public | function | Implements the magic __clone function. |
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. |