From c5926f4961506ad886e6110bc506bf72e4588bc8 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sun, 3 May 2009 08:56:19 +0000 Subject: - Patch #396578 by Damien Tournoud: added db_truncate_table() to the database layer. --- includes/database/query.inc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'includes/database/query.inc') diff --git a/includes/database/query.inc b/includes/database/query.inc index 8c7281820..8cdaaf5e1 100644 --- a/includes/database/query.inc +++ b/includes/database/query.inc @@ -829,6 +829,38 @@ class DeleteQuery extends Query implements QueryConditionInterface { } } + +/** + * General class for an abstracted TRUNCATE operation. + */ +class TruncateQuery extends Query { + + /** + * The table from which to delete. + * + * @var string + */ + protected $table; + + public function __construct(DatabaseConnection $connection, $table, array $options = array()) { + $options['return'] = Database::RETURN_AFFECTED; + parent::__construct($connection, $options); + $this->table = $table; + } + + public function compile(DatabaseConnection $connection) { + return $this->condition->compile($connection); + } + + public function execute() { + return $this->connection->query((string)$this, array(), $this->queryOptions); + } + + public function __toString() { + return 'TRUNCATE {' . $this->connection->escapeTable($this->table) . '} '; + } +} + /** * General class for an abstracted UPDATE operation. */ -- cgit v1.2.3