Same filename in this branch
- 10 core/lib/Drupal/Core/Database/Query/Truncate.php
- 10 core/lib/Drupal/Core/Database/Driver/pgsql/Truncate.php
- 10 core/lib/Drupal/Core/Database/Driver/sqlite/Truncate.php
- 10 core/modules/mysql/src/Driver/Database/mysql/Truncate.php
- 10 core/modules/pgsql/src/Driver/Database/pgsql/Truncate.php
- 10 core/modules/sqlite/src/Driver/Database/sqlite/Truncate.php
Same filename and directory in other branches
- 8.9.x core/lib/Drupal/Core/Database/Query/Truncate.php
- 9 core/lib/Drupal/Core/Database/Query/Truncate.php
Namespace
Drupal\Core\Database\Query
File
core/lib/Drupal/Core/Database/Query/Truncate.php
View source
<?php
namespace Drupal\Core\Database\Query;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Connection;
class Truncate extends Query {
protected $table;
public function __construct(Connection $connection, $table, array $options = []) {
$options['return'] = Database::RETURN_AFFECTED;
parent::__construct($connection, $options);
$this->table = $table;
}
public function execute() {
$stmt = $this->connection
->prepareStatement((string) $this, $this->queryOptions, TRUE);
try {
$stmt
->execute([], $this->queryOptions);
return $stmt
->rowCount();
} catch (\Exception $e) {
$this->connection
->exceptionHandler()
->handleExecutionException($e, $stmt, [], $this->queryOptions);
}
return NULL;
}
public function __toString() {
$comments = $this->connection
->makeComment($this->comments);
if ($this->connection
->inTransaction()) {
return $comments . 'DELETE FROM {' . $this->connection
->escapeTable($this->table) . '}';
}
else {
return $comments . 'TRUNCATE {' . $this->connection
->escapeTable($this->table) . '} ';
}
}
}
Classes
Name |
Description |
Truncate |
General class for an abstracted TRUNCATE operation. |