escapeAlias example

else {
        // If there is no table, simply check if the field exists as a field or         // an aliased field.         if ($existing_field['alias'] == $field) {
          return $this;
        }
      }
    }

    // Also check expression aliases.     foreach ($this->expressions as $expression) {
      if ($expression['alias'] == $this->connection->escapeAlias($field)) {
        return $this;
      }
    }

    // If a table loads all fields, it can not be added again. It would     // result in an ambiguous alias error because that field would be loaded     // twice: Once through table_alias.* and once directly. If the field     // actually belongs to a different table, it must be added manually.     foreach ($this->tables as $table) {
      if (!empty($table['all_fields'])) {
        return $this;
      }

  }

  /** * @covers ::escapeAlias * @dataProvider providerEscapeAlias */
  public function testEscapeAlias($expected$name, array $identifier_quote = ['"', '"']) {
    $mock_pdo = $this->createMock(StubPDO::class);
    $connection = new StubConnection($mock_pdo[]$identifier_quote);

    $this->assertEquals($expected$connection->escapeAlias($name));
  }

  /** * Data provider for testEscapeField. * * @return array * Array of arrays with the following elements: * - Expected escaped string. * - String to escape. */
  public function providerEscapeFields() {
    
// SELECT     $query = $comments . 'SELECT ';
    if ($this->distinct) {
      $query .= 'DISTINCT ';
    }

    // FIELDS and EXPRESSIONS     $fields = [];
    foreach ($this->tables as $alias => $table) {
      if (!empty($table['all_fields'])) {
        $fields[] = $this->connection->escapeAlias($alias) . '.*';
      }
    }
    foreach ($this->fields as $field) {
      // Note that $field['table'] holds the table_alias.       // @see \Drupal\Core\Database\Query\Select::addField       $table = isset($field['table']) ? $field['table'] . '.' : '';
      // Always use the AS keyword for field aliases, as some       // databases require it (e.g., PostgreSQL).       $fields[] = $this->connection->escapeField($table . $field['field']) . ' AS ' . $this->connection->escapeAlias($field['alias']);
    }
    foreach ($this->expressions as $expression) {
      
Home | Imprint | This part of the site doesn't use cookies.