getPrefixInfo example

/** * Override DatabaseSchema::$defaultSchema. * * @var string */
  protected $defaultSchema = 'main';

  /** * {@inheritdoc} */
  public function tableExists($table) {
    $info = $this->getPrefixInfo($table);

    // Don't use {} around sqlite_master table.     return (bool) $this->connection->query('SELECT 1 FROM [' . $info['schema'] . '].sqlite_master WHERE type = :type AND name = :name', [':type' => 'table', ':name' => $info['table']])->fetchField();
  }

  /** * {@inheritdoc} */
  public function fieldExists($table$column) {
    $schema = $this->introspectSchema($table);
    return !empty($schema['fields'][$column]);
  }


  /** * Build a condition to match a table name against a standard information_schema. * * MySQL uses databases like schemas rather than catalogs so when we build * a condition to query the information_schema.tables, we set the default * database as the schema unless specified otherwise, and exclude table_catalog * from the condition criteria. */
  protected function buildTableNameCondition($table_name$operator = '=', $add_prefix = TRUE) {
    $table_info = $this->getPrefixInfo($table_name$add_prefix);

    $condition = $this->connection->condition('AND');
    $condition->condition('table_schema', $table_info['database']);
    $condition->condition('table_name', $table_info['table']$operator);
    return $condition;
  }

  /** * {@inheritdoc} */
  protected function createTableSql($name$table) {
    

  protected function ensureIdentifiersLength($table_identifier_part$column_identifier_part$tag$separator = '__') {
    $info = $this->getPrefixInfo($table_identifier_part);
    $table_identifier_part = $info['table'];
    $identifierName = implode($separator[$table_identifier_part$column_identifier_part$tag]);

    // Retrieve the max identifier length which is usually 63 characters     // but can be altered before PostgreSQL is compiled so we need to check.     if (empty($this->maxIdentifierLength)) {
      $this->maxIdentifierLength = $this->connection->query("SHOW max_identifier_length")->fetchField();
    }

    if (strlen($identifierName) > $this->maxIdentifierLength) {
      $saveIdentifier = '"drupal_' . $this->hashBase64($identifierName) . '_' . $tag . '"';
    }

    return $info;
  }

  /** * Create names for indexes, primary keys and constraints. * * This prevents using {} around non-table names like indexes and keys. */
  public function prefixNonTable($table) {
    $args = func_get_args();
    $info = $this->getPrefixInfo($table);
    $args[0] = $info['table'];
    return implode('_', $args);
  }

  /** * 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. * * @param $table_name * The name of the table in question. * @param $operator * The operator to apply on the 'table' part of the condition. * @param $add_prefix * Boolean to indicate whether the table name needs to be prefixed. * * @return \Drupal\Core\Database\Query\Condition * A Condition object. */
Home | Imprint | This part of the site doesn't use cookies.