function SqlContentEntityStorageSchema::isTableEmpty

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::isTableEmpty()
  2. 10 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::isTableEmpty()
  3. 11.x core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::isTableEmpty()

Checks whether a database table is non-existent or empty.

Empty tables can be dropped and recreated without data loss.

Parameters

string $table_name: The database table to check.

Return value

bool TRUE if the table is empty, FALSE otherwise.

File

core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php, line 2453

Class

SqlContentEntityStorageSchema
Defines a schema handler that supports revisionable, translatable entities.

Namespace

Drupal\Core\Entity\Sql

Code

protected function isTableEmpty($table_name) {
    return !$this->database
        ->schema()
        ->tableExists($table_name) || !$this->database
        ->select($table_name)
        ->countQuery()
        ->range(0, 1)
        ->execute()
        ->fetchField();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.