class Delete

Same name in this branch

General class for an abstracted DELETE operation.

Hierarchy

Expanded class hierarchy of Delete

3 files declare their use of Delete
Delete.php in drupal/core/lib/Drupal/Core/Database/Driver/mysql/Delete.php
Definition of Drupal\Core\Database\Driver\mysql\Delete
Delete.php in drupal/core/lib/Drupal/Core/Database/Driver/sqlite/Delete.php
Definition of Drupal\Core\Database\Driver\sqlite\Delete
Delete.php in drupal/core/lib/Drupal/Core/Database/Driver/pgsql/Delete.php
Definition of Drupal\Core\Database\Driver\pgsql\Delete
91 string references to 'Delete'
action_admin_delete_form in drupal/core/modules/action/action.admin.inc
Creates the form for confirmation of deleting an action.
AggregatorTestBase::deleteFeed in drupal/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorTestBase.php
Delete an aggregator feed.
aggregator_form_category in drupal/core/modules/aggregator/aggregator.admin.inc
Form constructor to add/edit/delete aggregator categories.
aggregator_form_category_submit in drupal/core/modules/aggregator/aggregator.admin.inc
Form submission handler for aggregator_form_category().
aggregator_form_feed in drupal/core/modules/aggregator/aggregator.admin.inc
Form constructor for adding and editing feed sources.

... See full list

File

drupal/core/lib/Drupal/Core/Database/Query/Delete.php, line 16
Definition of Drupal\Core\Database\Query\Delete

Namespace

Drupal\Core\Database\Query
View source
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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Delete::$condition protected property The condition object for this query.
Delete::$table protected property The table from which to delete.
Delete::arguments public function Implements Drupal\Core\Database\Query\ConditionInterface::arguments(). Overrides ConditionInterface::arguments
Delete::compile public function Implements Drupal\Core\Database\Query\ConditionInterface::compile(). Overrides ConditionInterface::compile
Delete::compiled public function Implements Drupal\Core\Database\Query\ConditionInterface::compiled(). Overrides ConditionInterface::compiled
Delete::condition public function Implements Drupal\Core\Database\Query\ConditionInterface::condition(). Overrides ConditionInterface::condition
Delete::conditions public function Implements Drupal\Core\Database\Query\ConditionInterface::conditions(). Overrides ConditionInterface::conditions
Delete::execute public function Executes the DELETE query. Overrides Query::execute 1
Delete::exists public function Implements Drupal\Core\Database\Query\ConditionInterface::exists(). Overrides ConditionInterface::exists
Delete::isNotNull public function Implements Drupal\Core\Database\Query\ConditionInterface::isNotNull(). Overrides ConditionInterface::isNotNull
Delete::isNull public function Implements Drupal\Core\Database\Query\ConditionInterface::isNull(). Overrides ConditionInterface::isNull
Delete::notExists public function Implements Drupal\Core\Database\Query\ConditionInterface::notExists(). Overrides ConditionInterface::notExists
Delete::where public function Implements Drupal\Core\Database\Query\ConditionInterface::where(). Overrides ConditionInterface::where
Delete::__construct public function Constructs a Delete object. Overrides Query::__construct
Delete::__toString public function Implements PHP magic __toString method to convert the query to a string. Overrides Query::__toString
Query::$comments protected property An array of comments that can be prepended to a query.
Query::$connection protected property The connection object on which to run this query.
Query::$connectionKey protected property The key of the connection object.
Query::$connectionTarget protected property The target of the connection object.
Query::$nextPlaceholder protected property The placeholder counter.
Query::$queryOptions protected property The query options to pass on to the connection object.
Query::$uniqueIdentifier protected property A unique identifier for this query object.
Query::comment public function Adds a comment to the query.
Query::getComments public function Returns a reference to the comments array for the query.
Query::nextPlaceholder public function Gets the next placeholder value for this query object. Overrides PlaceholderInterface::nextPlaceholder
Query::uniqueIdentifier public function Returns a unique identifier for this object. Overrides PlaceholderInterface::uniqueIdentifier
Query::__clone public function Implements the magic __clone function. 1
Query::__sleep public function Implements the magic __sleep function to disconnect from the database.
Query::__wakeup public function Implements the magic __wakeup function to reconnect to the database.