Truncate.php 817 Bytes
Newer Older
1 2
<?php

Crell's avatar
Crell committed
3 4 5 6 7
/**
 * @file
 * Definition of Drupal\Core\Database\Driver\mysql\Truncate
 */

8
namespace Drupal\Core\Database\Driver\mysql;
9

10
use Drupal\Core\Database\Query\Truncate as QueryTruncate;
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

class Truncate extends QueryTruncate {
  public function __toString() {
    // TRUNCATE is actually a DDL statement on MySQL, and DDL statements are
    // not transactional, and result in an implicit COMMIT. When we are in a
    // transaction, fallback to the slower, but transactional, DELETE.
    if ($this->connection->inTransaction()) {
      // Create a comment string to prepend to the query.
      $comments = $this->connection->makeComment($this->comments);
      return $comments . 'DELETE FROM {' . $this->connection->escapeTable($this->table) . '}';
    }
    else {
      return parent::__toString();
    }
  }
}