function Schema::findTables

Same name in this branch
  1. 10 core/modules/sqlite/src/Driver/Database/sqlite/Schema.php \Drupal\sqlite\Driver\Database\sqlite\Schema::findTables()
  2. 10 core/lib/Drupal/Core/Database/Schema.php \Drupal\Core\Database\Schema::findTables()
Same name and namespace in other branches
  1. 9 core/modules/sqlite/src/Driver/Database/sqlite/Schema.php \Drupal\sqlite\Driver\Database\sqlite\Schema::findTables()
  2. 9 core/modules/pgsql/src/Driver/Database/pgsql/Schema.php \Drupal\pgsql\Driver\Database\pgsql\Schema::findTables()
  3. 9 core/lib/Drupal/Core/Database/Schema.php \Drupal\Core\Database\Schema::findTables()
  4. 8.9.x core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php \Drupal\Core\Database\Driver\sqlite\Schema::findTables()
  5. 8.9.x core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php \Drupal\Core\Database\Driver\pgsql\Schema::findTables()
  6. 8.9.x core/lib/Drupal/Core/Database/Schema.php \Drupal\Core\Database\Schema::findTables()
  7. 11.x core/modules/sqlite/src/Driver/Database/sqlite/Schema.php \Drupal\sqlite\Driver\Database\sqlite\Schema::findTables()
  8. 11.x core/modules/pgsql/src/Driver/Database/pgsql/Schema.php \Drupal\pgsql\Driver\Database\pgsql\Schema::findTables()
  9. 11.x core/lib/Drupal/Core/Database/Schema.php \Drupal\Core\Database\Schema::findTables()

Overrides Schema::findTables

File

core/modules/pgsql/src/Driver/Database/pgsql/Schema.php, line 518

Class

Schema
PostgreSQL implementation of <a href="/api/drupal/core%21lib%21Drupal%21Core%21Database%21Schema.php/class/Schema/10" title="Provides a base implementation for Database Schema." class="local">\Drupal\Core\Database\Schema</a>.

Namespace

Drupal\pgsql\Driver\Database\pgsql

Code

public function findTables($table_expression) {
    $prefix = $this->connection
        ->getPrefix();
    $prefix_length = strlen($prefix);
    $tables = [];
    // Load all the tables up front in order to take into account per-table
    // prefixes. The actual matching is done at the bottom of the method.
    $results = $this->connection
        ->query("SELECT tablename FROM pg_tables WHERE schemaname = :schema", [
        ':schema' => $this->defaultSchema,
    ]);
    foreach ($results as $table) {
        if ($prefix && substr($table->tablename, 0, $prefix_length) !== $prefix) {
            // This table name does not start the default prefix, which means that
            // it is not managed by Drupal so it should be excluded from the result.
            continue;
        }
        // Remove the prefix from the returned tables.
        $unprefixed_table_name = substr($table->tablename, $prefix_length);
        // The pattern can match a table which is the same as the prefix. That
        // will become an empty string when we remove the prefix, which will
        // probably surprise the caller, besides not being a prefixed table. So
        // remove it.
        if (!empty($unprefixed_table_name)) {
            $tables[$unprefixed_table_name] = $unprefixed_table_name;
        }
    }
    // Convert the table expression from its SQL LIKE syntax to a regular
    // expression and escape the delimiter that will be used for matching.
    $table_expression = str_replace([
        '%',
        '_',
    ], [
        '.*?',
        '.',
    ], preg_quote($table_expression, '/'));
    $tables = preg_grep('/^' . $table_expression . '$/i', $tables);
    return $tables;
}

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