Delete.php in Drupal 9
File
core/lib/Drupal/Core/Database/Query/Delete.php
View source
<?php
namespace Drupal\Core\Database\Query;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Connection;
class Delete extends Query implements ConditionInterface {
use QueryConditionTrait;
protected $table;
public function __construct(Connection $connection, $table, array $options = []) {
$options['return'] = Database::RETURN_AFFECTED;
parent::__construct($connection, $options);
$this->table = $table;
$this->condition = $this->connection
->condition('AND');
}
public function execute() {
$values = [];
if (count($this->condition)) {
$this->condition
->compile($this->connection, $this);
$values = $this->condition
->arguments();
}
$stmt = $this->connection
->prepareStatement((string) $this, $this->queryOptions, TRUE);
try {
$stmt
->execute($values, $this->queryOptions);
return $stmt
->rowCount();
} catch (\Exception $e) {
$this->connection
->exceptionHandler()
->handleExecutionException($e, $stmt, $values, $this->queryOptions);
}
}
public function __toString() {
$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;
}
}
Classes
Name |
Description |
Delete |
General class for an abstracted DELETE operation. |