protected function Schema::buildTableNameCondition

Same name in this branch
  1. 8.x drupal/core/lib/Drupal/Core/Database/Schema.php \Drupal\Core\Database\Schema::buildTableNameCondition()
  2. 8.x drupal/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php \Drupal\Core\Database\Driver\mysql\Schema::buildTableNameCondition()

Build a condition to match a table name against a standard information_schema.

The information_schema is a SQL standard that provides information about the database server and the databases, schemas, tables, columns and users within it. This makes information_schema a useful tool to use across the drupal database drivers and is used by a few different functions. The function below describes the conditions to be meet when querying information_schema.tables for drupal tables or information associated with drupal tables. Even though this is the standard method, not all databases follow standards and so this method should be overwritten by a database driver if the database provider uses alternate methods. Because information_schema.tables is used in a few different functions, a database driver will only need to override this function to make all the others work. For example see core/includes/databases/mysql/schema.inc.

Parameters

$table_name: The name of the table in question.

$operator: The operator to apply on the 'table' part of the condition.

$add_prefix: Boolean to indicate whether the table name needs to be prefixed.

Return value

Drupal\Core\Database\Query\ConditionInterface A Drupal\Core\Database\Query\Condition object.

3 calls to Schema::buildTableNameCondition()
Schema::fieldExists in drupal/core/lib/Drupal/Core/Database/Schema.php
Check if a column exists in the given table.
Schema::findTables in drupal/core/lib/Drupal/Core/Database/Schema.php
Find all tables that are like the specified base table name.
Schema::tableExists in drupal/core/lib/Drupal/Core/Database/Schema.php
Check if a table exists.
1 method overrides Schema::buildTableNameCondition()
Schema::buildTableNameCondition in drupal/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php
Build a condition to match a table name against a standard information_schema.

File

drupal/core/lib/Drupal/Core/Database/Schema.php, line 293
Definition of Drupal\Core\Database\Schema

Class

Schema

Namespace

Drupal\Core\Database

Code

protected function buildTableNameCondition($table_name, $operator = '=', $add_prefix = TRUE) {
  $info = $this->connection
    ->getConnectionOptions();

  // Retrive the table name and schema
  $table_info = $this
    ->getPrefixInfo($table_name, $add_prefix);
  $condition = new Condition('AND');
  $condition
    ->condition('table_catalog', $info['database']);
  $condition
    ->condition('table_schema', $table_info['schema']);
  $condition
    ->condition('table_name', $table_info['table'], $operator);
  return $condition;
}