public function Truncate::__toString

Same name in this branch
  1. 9.x drupal/core/lib/Drupal/Core/Database/Query/Truncate.php \Drupal\Core\Database\Query\Truncate::__toString()
  2. 9.x drupal/core/lib/Drupal/Core/Database/Driver/mysql/Truncate.php \Drupal\Core\Database\Driver\mysql\Truncate::__toString()
  3. 9.x drupal/core/lib/Drupal/Core/Database/Driver/sqlite/Truncate.php \Drupal\Core\Database\Driver\sqlite\Truncate::__toString()

Implements PHP magic __toString method to convert the query to a string.

Return value

string The prepared statement.

Overrides Truncate::__toString

File

drupal/core/lib/Drupal/Core/Database/Driver/mysql/Truncate.php, line 13
Definition of Drupal\Core\Database\Driver\mysql\Truncate

Class

Truncate

Namespace

Drupal\Core\Database\Driver\mysql

Code

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();
  }
}