setFetchMode example



  /** * {@inheritdoc} */
  public function execute($args = []$options = []) {
    if (isset($options['fetch'])) {
      if (is_string($options['fetch'])) {
        // Default to an object. Note: db fields will be added to the object         // before the constructor is run. If you need to assign fields after         // the constructor is run. See https://www.drupal.org/node/315092.         $this->setFetchMode(\PDO::FETCH_CLASS, $options['fetch']);
      }
      else {
        $this->setFetchMode($options['fetch']);
      }
    }

    if ($this->connection->isEventEnabled(StatementExecutionStartEvent::class)) {
      $startEvent = new StatementExecutionStartEvent(
        spl_object_id($this),
        $this->connection->getKey(),
        $this->connection->getTarget(),
        

    public function query($fetchMode = null, $bind = [])
    {
        if (!empty($bind)) {
            $this->bind($bind);
        }

        $stmt = $this->_adapter->query($this);
        if ($fetchMode == null) {
            $fetchMode = $this->_adapter->getFetchMode();
        }
        $stmt->setFetchMode($fetchMode);

        return $stmt;
    }

    /** * Converts this object to an SQL SELECT string. * * @return string|null This object as a SELECT string. (or null if a string cannot be produced.) */
    public function assemble()
    {
        

    protected function _authenticateQuerySelect(Zend_Db_Select $dbSelect)
    {
        try {
            if ($this->_zendDb->getFetchMode() != Zend_DB::FETCH_ASSOC) {
                $origDbFetchMode = $this->_zendDb->getFetchMode();
                $this->_zendDb->setFetchMode(Zend_DB::FETCH_ASSOC);
            }
            $resultIdentities = $this->_zendDb->fetchAll($dbSelect);
            if (isset($origDbFetchMode)) {
                $this->_zendDb->setFetchMode($origDbFetchMode);
                unset($origDbFetchMode);
            }
        } catch (Exception $e) {
            /* * @see Zend_Auth_Adapter_Exception */
            throw new Zend_Auth_Adapter_Exception('The supplied parameters to Zend_Auth_Adapter_DbTable failed to '
                                                .

  public function __construct(Connection $connection$client_connection, string $query, array $options, bool $row_count_enabled = FALSE) {
    $this->connection = $connection;
    $this->clientStatement = $client_connection->prepare($query$options);
    $this->rowCountEnabled = $row_count_enabled;
    $this->setFetchMode(\PDO::FETCH_OBJ);
  }

  /** * Returns the client-level database statement object. * * This method should normally be used only within database driver code. * * @return object * The client-level database statement, for example \PDOStatement. */
  public function getClientStatement() {
    

  public function __construct(
    protected readonly Connection $connection,
    object $clientConnection,
    string $query,
    array $options,
    protected readonly bool $rowCountEnabled = FALSE,
  ) {
    $this->clientStatement = $clientConnection->prepare($query$options);
    $this->setFetchMode(\PDO::FETCH_OBJ);
  }

  /** * Returns the client-level database statement object. * * This method should normally be used only within database driver code. * * @return object * The client-level database statement, for example \PDOStatement. */
  public function getClientStatement(): object {
    
foreach ($added_fields as $added_field) {
          $this->query->groupBy($added_field);
        }
      }
    }

    // Download data in batches for performance.     if (($this->batchSize > 0)) {
      $this->query->range($this->batch * $this->batchSize, $this->batchSize);
    }
    $statement = $this->query->execute();
    $statement->setFetchMode(\PDO::FETCH_ASSOC);
    return new \IteratorIterator($statement);
  }

  /** * Position the iterator to the following row. */
  protected function fetchNextRow() {
    $this->getIterator()->next();
    // We might be out of data entirely, or just out of data in the current     // batch. Attempt to fetch the next batch and see.     if ($this->batchSize > 0 && !$this->getIterator()->valid()) {
      
$sql = "SELECT $this->idCol, CASE WHEN $this->lifetimeCol IS NULL OR $this->lifetimeCol + $this->timeCol > ? THEN $this->dataCol ELSE NULL END FROM $this->table WHERE $this->idCol IN ($sql)";
        $stmt = $connection->prepare($sql);
        $stmt->bindValue($i = 1, $now, \PDO::PARAM_INT);
        foreach ($ids as $id) {
            $stmt->bindValue(++$i$id);
        }
        $result = $stmt->execute();

        if (\is_object($result)) {
            $result = $result->iterateNumeric();
        } else {
            $stmt->setFetchMode(\PDO::FETCH_NUM);
            $result = $stmt;
        }

        foreach ($result as $row) {
            if (null === $row[1]) {
                $expired[] = $row[0];
            } else {
                yield $row[0] => $this->marshaller->unmarshall(\is_resource($row[1]) ? stream_get_contents($row[1]) : $row[1]);
            }
        }

        
/** * Set the default fetch mode for this statement. * * @param int $mode The fetch mode. * @return bool * @throws Zend_Db_Statement_Exception */
    public function setFetchMode($mode)
    {
        $this->_fetchMode = $mode;
        try {
            return $this->_stmt->setFetchMode($mode);
        } catch (PDOException $e) {
            throw new Zend_Db_Statement_Exception($e->getMessage()$e->getCode()$e);
        }
    }

}

    public function prepare($sql)
    {
        $this->_connect();
        $stmtClass = $this->_defaultStmtClass;
        if (!class_exists($stmtClass)) {
            Zend_Loader::loadClass($stmtClass);
        }
        $stmt = new $stmtClass($this$sql);
        $stmt->setFetchMode($this->_fetchMode);
        return $stmt;
    }

    /** * Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column. * * As a convention, on RDBMS brands that support sequences * (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence * from the arguments and returns the last id generated by that sequence. * On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method * returns the last value generated for such a column, and the table name * argument is disregarded. * * On RDBMS brands that don't support sequences, $tableName and $primaryKey * are ignored. * * @param string $tableName OPTIONAL Name of table. * @param string $primaryKey OPTIONAL Name of primary key column. * @return string */


  /** * {@inheritdoc} */
  public function execute($args = []$options = []) {
    if (isset($options['fetch'])) {
      if (is_string($options['fetch'])) {
        // Default to an object. Note: db fields will be added to the object         // before the constructor is run. If you need to assign fields after         // the constructor is run. See https://www.drupal.org/node/315092.         $this->setFetchMode(\PDO::FETCH_CLASS, $options['fetch']);
      }
      else {
        $this->setFetchMode($options['fetch']);
      }
    }

    if ($this->connection->isEventEnabled(StatementExecutionStartEvent::class)) {
      $startEvent = new StatementExecutionStartEvent(
        spl_object_id($this),
        $this->connection->getKey(),
        $this->connection->getTarget(),
        
$this->pdoStatement = $this->prophesize(\PDOStatement::class);
    $this->pdoConnection = $this->prophesize(\PDO::class);
  }

  /** * Creates a Connection object for testing. * * @return \Drupal\mysql\Driver\Database\mysql\Connection */
  private function createConnection(): Connection {
    $this->pdoStatement
      ->setFetchMode(Argument::any())
      ->shouldBeCalled()
      ->willReturn(TRUE);

    $this->pdoStatement
      ->execute(Argument::any())
      ->shouldBeCalled()
      ->willReturn(TRUE);

    $this->pdoConnection
      ->prepare('SELECT VERSION()', Argument::any())
      ->shouldBeCalled()
      
// Let the pager modify the query to add limits.         $view->pager->preExecute($query);

        if (!empty($this->limit) || !empty($this->offset)) {
          // We can't have an offset without a limit, so provide a very large limit instead.           $limit = intval(!empty($this->limit) ? $this->limit : 999999);
          $offset = intval(!empty($this->offset) ? $this->offset : 0);
          $query->range($offset$limit);
        }

        $result = $query->execute();
        $result->setFetchMode(\PDO::FETCH_CLASS, 'Drupal\views\ResultRow');

        // Setup the result row objects.         $view->result = iterator_to_array($result);
        array_walk($view->result, function DResultRow $row$index) {
          $row->index = $index;
        });

        $view->pager->postExecute($view->result);
        $view->pager->updatePageInfo();
        $view->total_rows = $view->pager->getTotalItems();

        
 'Zend_Db::CASE_NATURAL, Zend_Db::CASE_LOWER, Zend_Db::CASE_UPPER');
            }
        }

        if (array_key_exists(Zend_Db::FETCH_MODE, $options)) {
            if (is_string($options[Zend_Db::FETCH_MODE])) {
                $constant = 'Zend_Db::FETCH_' . strtoupper($options[Zend_Db::FETCH_MODE]);
                if (defined($constant)) {
                    $options[Zend_Db::FETCH_MODE] = constant($constant);
                }
            }
            $this->setFetchMode((int) $options[Zend_Db::FETCH_MODE]);
        }

        // obtain quoting property if there is one         if (array_key_exists(Zend_Db::AUTO_QUOTE_IDENTIFIERS, $options)) {
            $this->_autoQuoteIdentifiers = (bool) $options[Zend_Db::AUTO_QUOTE_IDENTIFIERS];
        }

        // obtain allow serialization property if there is one         if (array_key_exists(Zend_Db::ALLOW_SERIALIZATION, $options)) {
            $this->_allowSerialization = (bool) $options[Zend_Db::ALLOW_SERIALIZATION];
        }

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