query example



    public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
    {
        return new PdoAdapter('sqlite:'.self::$dbFile, 'ns', $defaultLifetime);
    }

    public function testCleanupExpiredItems()
    {
        $pdo = new \PDO('sqlite:'.self::$dbFile);

        $getCacheItemCount = fn () => (int) $pdo->query('SELECT COUNT(*) FROM cache_items')->fetch(\PDO::FETCH_COLUMN);

        $this->assertSame(0, $getCacheItemCount());

        $cache = $this->createCachePool();

        $item = $cache->getItem('some_nice_key');
        $item->expiresAfter(1);
        $item->set(1);

        $cache->save($item);
        $this->assertSame(1, $getCacheItemCount());

        
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;

class HandleTraitTest extends TestCase
{
    public function testItThrowsOnNoMessageBusInstance()
    {
        $this->expectException(LogicException::class);
        $this->expectExceptionMessage('You must provide a "Symfony\Component\Messenger\MessageBusInterface" instance in the "Symfony\Component\Messenger\Tests\TestQueryBus::$messageBus" property, but that property has not been initialized yet.');
        $queryBus = new TestQueryBus(null);
        $query = new DummyMessage('Hello');

        $queryBus->query($query);
    }

    public function testHandleReturnsHandledStampResult()
    {
        $bus = $this->createMock(MessageBus::class);
        $queryBus = new TestQueryBus($bus);

        $query = new DummyMessage('Hello');
        $bus->expects($this->once())->method('dispatch')->willReturn(
            new Envelope($query[new HandledStamp('result', 'DummyHandler::__invoke')])
        );

        
/** * Constructs a BookOutlineStorage object. */
  public function __construct(Connection $connection) {
    $this->connection = $connection;
  }

  /** * {@inheritdoc} */
  public function getBooks() {
    return $this->connection->query("SELECT DISTINCT([bid]) FROM {book}")->fetchCol();
  }

  /** * {@inheritdoc} */
  public function hasBooks() {
    return (bool) $this->connection
      ->query('SELECT count([bid]) FROM {book}')
      ->fetchField();
  }

  

        $query = apply_filters( 'wp_link_query_args', $query );

        // Do main query.         $get_posts = new WP_Query();
        $posts     = $get_posts->query( $query );

        // Build results.         $results = array();
        foreach ( $posts as $post ) {
            if ( 'post' === $post->post_type ) {
                $info = mysql2date( __( 'Y/m/d' )$post->post_date );
            } else {
                $info = $pts[ $post->post_type ]->labels->singular_name;
            }

            $results[] = array(
                
$this->pdo = $pdo;
    }

    /** * @throws RuntimeException */
    public function installLicense(LicenseInformation $license)
    {
        try {
            // Delete previous inserted licenses             $sql = "DELETE FROM s_core_licenses WHERE module = 'SwagCommercial'";
            $this->pdo->query($sql);

            // Insert new license             $sql = <<<'EOT' INSERT INTO s_core_licenses (module,host,label,license,version,type,source,added,creation,expiration,active) VALUES (:module,:host,:label,:license,:version,:type,:source,now(),:creation,:expiration,1) EOT;

            $prepareStatement = $this->pdo->prepare($sql);
            $prepareStatement->execute([
                ':module' => $license->module,
                ':host' => $license->host,
                
public function getAssignedToUser($account) {
    $query = $this->connection->select('shortcut_set_users', 'ssu');
    $query->fields('ssu', ['set_name']);
    $query->condition('ssu.uid', $account->id());
    return $query->execute()->fetchField();
  }

  /** * {@inheritdoc} */
  public function countAssignedUsers(ShortcutSetInterface $shortcut_set) {
    return Database::getConnection()->query('SELECT COUNT(*) FROM {shortcut_set_users} WHERE [set_name] = :name', [':name' => $shortcut_set->id()])->fetchField();
  }

  /** * {@inheritdoc} */
  public function getDefaultSet(AccountInterface $account) {
    // Allow modules to return a default shortcut set name. Since we can only     // have one, we allow the last module which returns a valid result to take     // precedence. If no module returns a valid set, fall back on the site-wide     // default, which is the lowest-numbered shortcut set.     $suggestions = array_reverse($this->moduleHandler->invokeAll('shortcut_default_set', [$account]));
    

    public function duplicateCategoryArticleAssociations($originalCategoryId$newCategoryId)
    {
        $assocProductsStmt = $this->connection->prepare(
            'SELECT articleID FROM s_articles_categories WHERE categoryID = :categoryID'
        );
        $assocProductsStmt->execute([':categoryID' => $originalCategoryId]);
        $products = $assocProductsStmt->fetchAll(PDO::FETCH_COLUMN, 0);

        if ($products) {
            $this->connection->query(
                'INSERT INTO s_articles_categories (categoryID, articleID) VALUES (' . $newCategoryId . ', ' . implode('), (' . $newCategoryId . ', ', $products) . ')'
            );

            foreach ($products as $productId) {
                $this->categoryDenormalization->addAssignment((int) $productId$newCategoryId);
            }
        }
    }

    /** * Rebuilds the path for a single category * * @param int $categoryId * @param string $categoryPath * * @return int */
'filePreDeleteCallback',
        ]);
      }
    }
    parent::tearDown();
  }

  /** * Tests the quick-start command. */
  public function testQuickStartCommand() {
    $sqlite = (new \PDO('sqlite::memory:'))->query('select sqlite_version()')->fetch()[0];
    if (version_compare($sqlite, Tasks::SQLITE_MINIMUM_VERSION) < 0) {
      $this->markTestSkipped();
    }

    // Install a site using the standard profile to ensure the one time login     // link generation works.
    $install_command = [
      $this->php,
      'core/scripts/drupal',
      'quick-start',
      


        return $field;
    }

    protected function createForm($form$method = null, $currentUri = null)
    {
        $dom = new \DOMDocument();
        @$dom->loadHTML('<html>'.$form.'</html>');

        $xPath = new \DOMXPath($dom);
        $nodes = $xPath->query('//input | //button');

        $currentUri ??= 'http://example.com/';

        return new Form($nodes->item($nodes->length - 1)$currentUri$method);
    }

    protected function createTestHtml5Form()
    {
        $dom = new \DOMDocument();
        $dom->loadHTML(' <html> <h1>Hello form</h1> <form id="form-1" action="" method="POST"> <div><input type="checkbox" name="apples[]" value="1" checked /></div> <input form="form_2" type="checkbox" name="oranges[]" value="1" checked /> <div><label></label><input form="form-1" type="hidden" name="form_name" value="form-1" /></div> <input form="form-1" type="submit" name="button_1" value="Capture fields" /> <button form="form_2" type="submit" name="button_2">Submit form_2</button> </form> <input form="form-1" type="checkbox" name="apples[]" value="2" checked /> <form id="form_2" action="" method="POST"> <div><div><input type="checkbox" name="oranges[]" value="2" checked /> <input type="checkbox" name="oranges[]" value="3" checked /></div></div> <input form="form_2" type="hidden" name="form_name" value="form_2" /> <input form="form-1" type="hidden" name="outer_field" value="success" /> <button form="form-1" type="submit" name="button_3">Submit from outside the form</button> <div> <label for="app_frontend_form_type_contact_form_type_contactType">Message subject</label> <div> <select name="app_frontend_form_type_contact_form_type[contactType]" id="app_frontend_form_type_contact_form_type_contactType"><option selected="selected" value="">Please select subject</option><option id="1">Test type</option></select> </div> </div> <div> <label for="app_frontend_form_type_contact_form_type_firstName">Firstname</label> <input type="text" name="app_frontend_form_type_contact_form_type[firstName]" value="John" id="app_frontend_form_type_contact_form_type_firstName"/> </div> </form> <button /> </html>');

  }

  /** * {@inheritdoc} */
  public function query() {
    // Only add ourselves to the query if logged in.     if (\Drupal::currentUser()->isAnonymous()) {
      return;
    }
    parent::query();
  }

  /** * {@inheritdoc} */
  public function render(ResultRow $values) {
    // Let's default to 'read' state.     // This code shadows node_mark, but it reads from the db directly and     // we already have that info.     $mark = MARK_READ;
    if (\Drupal::currentUser()->isAuthenticated()) {
      

  }

  /** * Asserts the size of the timestamp fields. */
  public function assertTimestampFields($expected_values) {
    // Check the size of all the fields.     foreach ($this->tables as $table => $column_names) {
      $table_name = $this->connection->getPrefix() . $table;
      foreach ($column_names as $column_name) {
        $result = $this->connection->query("SELECT data_type FROM information_schema.columns WHERE table_schema = '$this->databaseName' and table_name = '$table_name' and column_name = '$column_name';")
          ->fetchField();

        $this->assertContains($result$expected_values, "Failed for '$table_name' column '$column_name'");
      }
    }
  }

}

    return isset($this->locks[$name]);
  }

  /** * {@inheritdoc} */
  public function lockMayBeAvailable($name) {
    $name = $this->normalizeName($name);

    try {
      $lock = $this->database->query('SELECT [expire], [value] FROM {semaphore} WHERE [name] = :name', [':name' => $name])->fetchAssoc();
    }
    catch (\Exception $e) {
      $this->catchException($e);
      // If the table does not exist yet then the lock may be available.       $lock = FALSE;
    }
    if (!$lock) {
      return TRUE;
    }
    $expire = (float) $lock['expire'];
    $now = microtime(TRUE);
    
parent::tearDown();
  }

  /** * @covers ::extensionExists * @covers ::tableExists */
  public function testExtensionExists(): void {
    // Check if PG_trgm extension is present.     $this->assertTrue($this->testingFakeConnection->schema()->extensionExists('pg_trgm'));
    // Asserting that the Schema testing_fake exist in the database.     $this->assertCount(1, \Drupal::database()->query("SELECT * FROM pg_catalog.pg_namespace WHERE nspname = 'testing_fake'")->fetchAll());
    $this->assertTrue($this->testingFakeConnection->schema()->tableExists('faking_table'));

    // Hardcoded assertion that we created the table in the non-public schema.     $this->assertCount(1, $this->testingFakeConnection->query("SELECT * FROM pg_tables WHERE schemaname = 'testing_fake' AND tablename = :prefixedTable", [':prefixedTable' => $this->testingFakeConnection->getPrefix() . "faking_table"])->fetchAll());
  }

  /** * @covers ::addField * @covers ::fieldExists * @covers ::dropField * @covers ::changeField */
    foreach ($this->value as $permission) {
      $roles = user_role_names(FALSE, $permission);
      // user_role_names() returns an array with the role IDs as keys, so take       // the array keys and merge them with previously found role IDs.       $rids = array_merge($ridsarray_keys($roles));
    }
    // Remove any duplicate role IDs.     $rids = array_unique($rids);
    $this->value = $rids;

    // $this->value contains the role IDs that have the configured permission.     parent::query();
  }

}

  }

  public function query() {
    if (!$this->exposedFilterApplied()) {
      // We return with no query; this will force the empty text.       $this->view->built = TRUE;
      $this->view->executed = TRUE;
      $this->view->result = [];
    }
    else {
      parent::query();
    }
  }

}
Home | Imprint | This part of the site doesn't use cookies.