fetchAllKeyed example


    $all = $query->execute()->fetchAll(\PDO::FETCH_ASSOC);
    $this->assertCount(1, $all, "Found link $id matching all the expected properties");
    $raw = reset($all);

    // Put the current link onto the front.     array_unshift($parents$raw['id']);

    $query = $this->connection->select('menu_tree');
    $query->fields('menu_tree', ['id', 'mlid']);
    $query->condition('id', $parents, 'IN');
    $found_parents = $query->execute()->fetchAllKeyed(0, 1);

    $this->assertSameSize($parents$found_parents, 'Found expected number of parents');
    $this->assertCount($raw['depth']$found_parents, 'Number of parents is the same as the depth');

    $materialized_path = $this->treeStorage->getRootPathIds($id);
    $this->assertEquals(array_values($parents)array_values($materialized_path), 'Parents match the materialized path');
    // Check that the selected mlid values of the parents are in the correct     // column, including the link's own.     for ($i = $raw['depth']$i >= 1; $i--) {
      $parent_id = array_shift($parents);
      $this->assertEquals($found_parents[$parent_id]$raw["p{$i}"], "mlid of parent matches at column p{$i}");
    }
$inner_select->condition("t.$rta_field", '1');
    $inner_select->fields('t', [$id_field$langcode_field]);
    $inner_select->addExpression("MAX([t].[$revision_field])", $revision_field);
    $inner_select
      ->groupBy("t.$id_field")
      ->groupBy("t.$langcode_field");

    $query->join($inner_select, 'mr', "[tfr].[$revision_field] = [mr].[$revision_field] AND [tfr].[$langcode_field] = [mr].[$langcode_field]");

    $query->groupBy("tfr.$id_field");

    return $query->execute()->fetchAllKeyed(1, 0);
  }

  /** * {@inheritdoc} */
  public function getVocabularyHierarchyType($vid) {
    // Return early if we already computed this value.     if (isset($this->vocabularyHierarchyType[$vid])) {
      return $this->vocabularyHierarchyType[$vid];
    }

    
$this->assertEntity(2, 'Image2.jpg', 1831, 'public://image-2.jpg', 'image/jpeg', 1);
    $this->assertEntity(3, 'image-3.jpg', 1831, 'public://image-3.jpg', 'image/jpeg', 1);
    $this->assertEntity(4, 'html-1.txt', 19, 'public://html-1.txt', 'text/plain', 1);
    // Ensure temporary file was not migrated.     $this->assertNull(File::load(6));

    $map_table = $this->getMigration('d6_file')->getIdMap()->mapTableName();
    $map = \Drupal::database()
      ->select($map_table, 'm')
      ->fields('m', ['sourceid1', 'destid1'])
      ->execute()
      ->fetchAllKeyed();
    $map_expected = [
      // The 4 files from the fixture.       1 => '1',
      2 => '2',
      // The file updated in migrateDumpAlter().       3 => '3',
      5 => '4',
      // The file created in migrateDumpAlter().       7 => '4',
    ];
    $this->assertEquals($map_expected$map);

    

      $select->condition($conditions);
    }

    $this->addLanguageFallback($select$langcode);

    // We order by ID ASC so that fetchAllKeyed() returns the most recently     // created alias for each source. Subsequent queries using fetchField() must     // use ID DESC to have the same effect.     $select->orderBy('base_table.id', 'ASC');

    return $select->execute()->fetchAllKeyed();
  }

  /** * {@inheritdoc} */
  public function lookupBySystemPath($path$langcode) {
    // See the queries above. Use LIKE for case-insensitive matching.     $select = $this->getBaseQuery()
      ->fields('base_table', ['id', 'path', 'alias', 'langcode'])
      ->condition('base_table.path', $this->connection->escapeLike($path), 'LIKE');

    
    // over all known schemas and filter by the user-supplied table expression.     $attached_dbs = $this->connection->getAttachedDatabases();
    foreach ($attached_dbs as $schema) {
      // Can't use query placeholders for the schema because the query would       // have to be :prefixsqlite_master, which does not work. We also need to       // ignore the internal SQLite tables.       $result = $this->connection->query("SELECT name FROM [" . $schema . "].sqlite_master WHERE type = :type AND name LIKE :table_name AND name NOT LIKE :pattern", [
        ':type' => 'table',
        ':table_name' => $table_expression,
        ':pattern' => 'sqlite_%',
      ]);
      $tables += $result->fetchAllKeyed(0, 0);
    }

    return $tables;
  }

}
':performance_doc' => 'https://www.drupal.org/docs/system-requirements/setting-the-mysql-transaction-isolation-level',
      ]),
    ];

    return $form;
  }

  /** * Ensure that InnoDB is available. */
  public function ensureInnoDbAvailable() {
    $engines = Database::getConnection()->query('SHOW ENGINES')->fetchAllKeyed();
    if (isset($engines['MyISAM']) && $engines['MyISAM'] == 'DEFAULT' && !isset($engines['InnoDB'])) {
      $this->fail(t('The MyISAM storage engine is not supported.'));
    }
  }

  /** * {@inheritdoc} */
  protected function checkEngineVersion() {
    parent::checkEngineVersion();

    

  protected function result() {
    if ($this->count) {
      return (int) $this->sqlQuery->countQuery()->execute()->fetchField();
    }
    // Return a keyed array of results. The key is either the revision_id or     // the entity_id depending on whether the entity type supports revisions.     // The value is always the entity id.     return $this->sqlQuery->execute()->fetchAllKeyed();
  }

  /** * Constructs a select expression for a given field and language. * * @param string $field * The name of the field being queried. * @param string $langcode * The language code of the field. * * @return string * An expression that will select the given field for the given language in * a SELECT query, such as 'base_table.id'. */
/** * {@inheritdoc} */
  public function getMultiple(array $keys) {
    try {
      $values = $this->connection->query(
        'SELECT [name], [value] FROM {' . $this->connection->escapeTable($this->table) . '} WHERE [expire] > :now AND [name] IN ( :keys[] ) AND [collection] = :collection',
        [
          ':now' => REQUEST_TIME,
          ':keys[]' => $keys,
          ':collection' => $this->collection,
        ])->fetchAllKeyed();
      return array_map([$this->serializer, 'decode']$values);
    }
    catch (\Exception $e) {
      // @todo: Perhaps if the database is never going to be available,       // key/value requests should return FALSE in order to allow exception       // handling to occur but for now, keep it an array, always.       // https://www.drupal.org/node/2787737       $this->catchException($e);
    }
    return [];
  }

  
$update_registry = \Drupal::service('update.update_hook_registry');
    foreach (['user' => 9301, 'node' => 8700, 'system' => 8901, 'update_test_schema' => 8000] as $module => $schema) {
      $this->assertEquals($schema$update_registry->getInstalledVersion($module)new FormattableMarkup('Module @module schema is @schema', ['@module' => $module, '@schema' => $schema]));
    }

    // Ensure that all {router} entries can be unserialized. If they cannot be     // unserialized a notice will be thrown by PHP.
    $result = \Drupal::database()->select('router', 'r')
      ->fields('r', ['name', 'route'])
      ->execute()
      ->fetchAllKeyed(0, 1);
    // For the purpose of fetching the notices and displaying more helpful error     // messages, let's override the error handler temporarily.     set_error_handler(function D$severity$message$filename$lineno) {
      throw new \ErrorException($message, 0, $severity$filename$lineno);
    });
    foreach ($result as $route_name => $route) {
      try {
        unserialize($route);
      }
      catch (\Exception $e) {
        $this->fail(sprintf('Error "%s" while unserializing route %s', $e->getMessage(), Html::escape($route_name)));
      }
$inner_select->condition("t.$rta_field", '1');
    $inner_select->fields('t', [$id_field$langcode_field]);
    $inner_select->addExpression("MAX([t].[$revision_field])", $revision_field);
    $inner_select
      ->groupBy("t.$id_field")
      ->groupBy("t.$langcode_field");

    $query->join($inner_select, 'mr', "[mlfr].[$revision_field] = [mr].[$revision_field] AND [mlfr].[$langcode_field] = [mr].[$langcode_field]");

    $query->groupBy("mlfr.$id_field");

    return $query->execute()->fetchAllKeyed(1, 0);
  }

}
'name' => $this->t('The name of the user role.'),
    ];
  }

  /** * {@inheritdoc} */
  protected function initializeIterator() {
    $filter_roles = $this->select('filter_formats', 'f')
      ->fields('f', ['format', 'roles'])
      ->execute()
      ->fetchAllKeyed();
    foreach ($filter_roles as $format => $roles) {
      // Drupal 6 code: $roles = ','. implode(',', $roles) .',';       // Remove the beginning and ending comma.       foreach (explode(',', trim($roles, ',')) as $rid) {
        $this->filterPermissions[$rid][] = $format;
      }
    }
    return parent::initializeIterator();
  }

  /** * {@inheritdoc} */
/** * Tests statement fetching after a full traversal. */
  public function testIteratedStatementFetch(): void {
    $statement = $this->connection->query('SELECT * FROM {test}');

    foreach ($statement as $row) {
      $this->assertNotNull($row);
    }

    $this->assertSame([]$statement->fetchAll());
    $this->assertSame([]$statement->fetchAllKeyed());
    $this->assertSame([]$statement->fetchAllAssoc('age'));
    $this->assertSame([]$statement->fetchCol());

    $this->assertFalse($statement->fetch());
    $this->assertFalse($statement->fetchObject());
    $this->assertFalse($statement->fetchAssoc());
    $this->assertFalse($statement->fetchField());
  }

  /** * Tests statement fetchAll after a partial traversal. */
    $subquery->fields($this->table, ['p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9']);
    $subquery->condition('id', $id);
    $result = current($subquery->execute()->fetchAll(\PDO::FETCH_ASSOC));
    $ids = array_filter($result);
    if ($ids) {
      $query = $this->connection->select($this->table, NULL, $this->options);
      $query->fields($this->table, ['id']);
      $query->orderBy('depth', 'DESC');
      $query->condition('mlid', $ids, 'IN');
      // @todo Cache this result in memory if we find it is being used more       // than once per page load. https://www.drupal.org/node/2302185       return $this->safeExecuteSelect($query)->fetchAllKeyed(0, 0);
    }
    return [];
  }

  /** * {@inheritdoc} */
  public function getExpanded($menu_name, array $parents) {
    // @todo Go back to tracking in state or some other way which menus have     // expanded links? https://www.drupal.org/node/2302187     do {
      


  /** * Asserts that a connection ID exists. * * @param int $id * The connection ID to verify. * * @internal */
  protected function assertConnection(int $id): void {
    $this->assertArrayHasKey($id$this->monitor->query($this->getQuery()['processlist'])->fetchAllKeyed(0, 0));
  }

  /** * Asserts that a connection ID does not exist. * * @param int $id * The connection ID to verify. * * @internal */
  protected function assertNoConnection(int $id): void {
    
/** * {@inheritdoc} */
  public function countStrings() {
    return $this->dbExecute("SELECT COUNT(*) FROM {locales_source}")->fetchField();
  }

  /** * {@inheritdoc} */
  public function countTranslations() {
    return $this->dbExecute("SELECT t.language, COUNT(*) AS translated FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid GROUP BY t.language")->fetchAllKeyed();
  }

  /** * {@inheritdoc} */
  public function save($string) {
    if ($string->isNew()) {
      $result = $this->dbStringInsert($string);
      if ($string->isSource() && $result) {
        // Only for source strings, we set the locale identifier.         $string->setId($result);
      }
Home | Imprint | This part of the site doesn't use cookies.