rowCount example

/** * Returns the number of rows affected by the execution of the * last INSERT, DELETE, or UPDATE statement executed by this * statement object. * * @return int The number of rows affected. * @throws Zend_Db_Statement_Exception */
    public function rowCount()
    {
        try {
            return $this->_stmt->rowCount();
        } catch (PDOException $e) {
            throw new Zend_Db_Statement_Exception($e->getMessage()$e->getCode()$e);
        }
    }

    /** * Set a statement attribute. * * @param string $key Attribute name. * @param mixed $val Attribute value. * @return bool * @throws Zend_Db_Statement_Exception */

  public function execute() {
    $stmt = $this->connection->prepareStatement((string) $this$this->queryOptions, TRUE);
    try {
      $stmt->execute([]$this->queryOptions);
      return $stmt->rowCount();
    }
    catch (\Exception $e) {
      $this->connection->exceptionHandler()->handleExecutionException($e$stmt[]$this->queryOptions);
    }

    return NULL;
  }

  /** * Implements PHP magic __toString method to convert the query to a string. * * @return string * The prepared statement. */


class Migrations_Migration776 extends Shopware\Components\Migrations\AbstractMigration
{
    public function up($modus)
    {
        $rows = $this->getConnection()->query("show index from s_core_payment_data WHERE Non_unique = 0 AND Column_name IN ('payment_mean_id','user_id')")->rowCount();
        if ($rows === 2) {
            return;
        }

        $this->addSql('CREATE TABLE `s_core_payment_data_unique` LIKE `s_core_payment_data`');
        $this->addSql('ALTER TABLE `s_core_payment_data_unique` ADD UNIQUE (`payment_mean_id`, `user_id`)');
        $this->addSql('INSERT IGNORE INTO `s_core_payment_data_unique` SELECT * FROM `s_core_payment_data`');
        $this->addSql('DROP TABLE `s_core_payment_data`');
        $this->addSql('RENAME TABLE `s_core_payment_data_unique` TO `s_core_payment_data`');
    }
}
// Re-initialize the values array so that we can re-use this query.     $this->insertValues = [];

    // Create a savepoint so we can rollback a failed query. This is so we can     // mimic MySQL and SQLite transactions which don't fail if a single query     // fails. This is important for tables that are created on demand. For     // example, \Drupal\Core\Cache\DatabaseBackend.     $this->connection->addSavepoint();
    try {
      $stmt->execute(NULL, $options);
      $this->connection->releaseSavepoint();
      return $stmt->rowCount();
    }
    catch (\Exception $e) {
      $this->connection->rollbackSavepoint();
      $this->connection->exceptionHandler()->handleExecutionException($e$stmt[]$options);
    }
  }

  /** * {@inheritdoc} */
  public function __toString() {
    
      // removed, query() will only return a StatementInterface object.       // @see https://www.drupal.org/project/drupal/issues/3256524       switch ($options['return'] ?? Database::RETURN_STATEMENT) {
        case Database::RETURN_STATEMENT:
          return $stmt;

        // Database::RETURN_AFFECTED should not be used; enable row counting         // by passing the appropriate argument to the constructor instead.         // @see https://www.drupal.org/node/3186368         case Database::RETURN_AFFECTED:
          $stmt->allowRowCount = TRUE;
          return $stmt->rowCount();

        case Database::RETURN_INSERT_ID:
          $sequence_name = $options['sequence_name'] ?? NULL;
          return $this->lastInsertId($sequence_name);

        case Database::RETURN_NULL:
          return NULL;

        default:
          throw new \PDOException('Invalid return directive: ' . $options['return']);

      }

            try {
                $result = Shopware()->Db()->query($sql[
                    $user['userID'],
                    $voucher['vouchercodeID'],
                ]);
            } catch (Zend_Db_Exception $e) {
                continue;
            }

            try {
                $result = $result->rowCount();
            } catch (Zend_Db_Exception $e) {
                continue;
            }

            if (empty($result)) {
                continue;
            }

            $repository = Shopware()->Models()->getRepository(Shop::class);
            $shopId = is_numeric($user['language']) ? $user['language'] : $user['subshopID'];
            $shop = $repository->getActiveById($shopId);
            
$params = [
            'endDate' => $endDate,
            'startDate' => $startDate,
        ];

        $sql = 'SELECT id FROM s_order_basket WHERE modus = 0 AND datum >= :startDate AND datum <= DATE_ADD(:endDate, INTERVAL 1 DAY) GROUP BY sessionID';
        $result = Shopware()->Db()->query($sql$params);
        $total = $result->rowCount();

        if (\is_array($filter) && isset($filter[0]['value'])) {
            $params['filter'] = '%' . $filter[0]['value'] . '%';
            $filter = 'AND lastviewport LIKE :filter';
        } else {
            $filter = '';
        }

        if ($sort !== null && isset($sort[0]['property'])) {
            if (isset($sort['0']['direction']) && $sort['0']['direction'] === 'DESC') {
                $direction = 'DESC';
            }
$this->setResultsetCurrentRow($row);
    return $row;
  }

  /** * {@inheritdoc} */
  public function rowCount() {
    // SELECT query should not use the method.     if ($this->rowCountEnabled) {
      return $this->clientStatement->rowCount();
    }
    else {
      throw new RowCountException();
    }
  }

  /** * {@inheritdoc} */
  public function setFetchMode($mode$a1 = NULL, $a2 = []) {
    // Call \PDOStatement::setFetchMode to set fetch mode.
return true;
            }

            $updateStmt = $this->getUpdateStatement($sessionId$data$maxlifetime);
            $updateStmt->execute();

            // When MERGE is not supported, like in Postgres < 9.5, we have to use this approach that can result in             // duplicate key errors when the same session is written simultaneously (given the LOCK_NONE behavior).             // We can just catch such an error and re-execute the update. This is similar to a serializable             // transaction with retry logic on serialization failures but without the overhead and without possible             // false positives due to longer gap locking.             if (!$updateStmt->rowCount()) {
                try {
                    $insertStmt = $this->getInsertStatement($sessionId$data$maxlifetime);
                    $insertStmt->execute();
                } catch (\PDOException $e) {
                    // Handle integrity violation SQLSTATE 23000 (or a subclass like 23505 in Postgres) for duplicate keys                     if (str_starts_with($e->getCode(), '23')) {
                        $updateStmt->execute();
                    } else {
                        throw $e;
                    }
                }
            }
    $statement = $this->getStatement($this->queryString, $args);
    if (!$statement) {
      $this->throwPDOException();
    }

    $return = $statement->execute($args);
    if (!$return) {
      $this->throwPDOException();
    }

    if ($this->rowCountEnabled) {
      $this->rowCount = $statement->rowCount();
    }
    // Fetch all the data from the reply, in order to release any lock     // as soon as possible.     $this->data = $statement->fetchAll(\PDO::FETCH_ASSOC);
    // Destroy the statement as soon as possible. See the documentation of     // \Drupal\sqlite\Driver\Database\sqlite\Statement for an explanation.     unset($statement);

    $this->resultRowCount = count($this->data);

    if ($this->resultRowCount) {
      
$this->throwPDOException();
    }

    $return = $statement->execute($args);
    if (!$return) {
      $this->throwPDOException();
    }

    // Fetch all the data from the reply, in order to release any lock as soon     // as possible.     $this->data = $statement->fetchAll(\PDO::FETCH_ASSOC);
    $this->rowCount = $this->rowCountEnabled ? $statement->rowCount() : NULL;
    // Destroy the statement as soon as possible. See the documentation of     // \Drupal\sqlite\Driver\Database\sqlite\Statement for an explanation.     unset($statement);
    $this->markResultsetIterable($return);

    $this->columnNames = count($this->data) > 0 ? array_keys($this->data[0]) : [];

    if (isset($startEvent) && $this->connection->isEventEnabled(StatementExecutionEndEvent::class)) {
      $this->connection->dispatchEvent(new StatementExecutionEndEvent(
        $startEvent->statementObjectId,
        $startEvent->key,
        
$update_values[':db_update_placeholder_' . ($max_placeholder++)] = $value;
    }

    if (count($this->condition)) {
      $this->condition->compile($this->connection, $this);
      $update_values = array_merge($update_values$this->condition->arguments());
    }

    $stmt = $this->connection->prepareStatement((string) $this$this->queryOptions, TRUE);
    try {
      $stmt->execute($update_values$this->queryOptions);
      return $stmt->rowCount();
    }
    catch (\Exception $e) {
      $this->connection->exceptionHandler()->handleExecutionException($e$stmt$update_values$this->queryOptions);
    }
  }

  /** * Implements PHP magic __toString method to convert the query to a string. * * @return string * The prepared statement. */
public function _count($value)
    {
        if (is_array($value) === true || $value instanceof Countable) {
            return count($value);
        } elseif ($value instanceof IteratorAggregate) {
            // Note: getIterator() returns a Traversable, not an Iterator             // thus rewind() and valid() methods may not be present             return iterator_count($value->getIterator());
        } elseif ($value instanceof Iterator) {
            return iterator_count($value);
        } elseif ($value instanceof PDOStatement) {
            return $value->rowCount();
        } elseif ($value instanceof Traversable) {
            return iterator_count($value);
        } elseif ($value instanceof ArrayAccess) {
            if ($value->offsetExists(0)) {
                return 1;
            }
        } elseif (is_object($value)) {
            return count($value);
        }
        return 0;
    }

    
$arguments = $this->condition->arguments();
      foreach ($arguments as $placeholder => $value) {
        $stmt->getClientStatement()->bindParam($placeholder$arguments[$placeholder]);
      }
    }

    $this->connection->addSavepoint();
    try {
      $stmt->execute(NULL, $this->queryOptions);
      $this->connection->releaseSavepoint();
      return $stmt->rowCount();
    }
    catch (\Exception $e) {
      $this->connection->rollbackSavepoint();
      $this->connection->exceptionHandler()->handleExecutionException($e$stmt[]$this->queryOptions);
    }
  }

}
 catch (Zend_Db_Exception $e) {
            return;
        }

        $result = Shopware()->Container()->get('events')->filter(
            'Shopware_Modules_Export_ExportResult_Filter',
            $result,
            ['feedId' => $this->sFeedID, 'subject' => $this]
        );

        // Update db with the latest values         $count = (int) $result->rowCount();
        $this->db->update(
            's_export',
            [
                'last_export' => new Zend_Date(),
                'cache_refreshed' => new Zend_Date(),
                'count_articles' => $count,
            ],
            ['id = ?' => $this->sFeedID]
        );

        // Fetches all required data to smarty
Home | Imprint | This part of the site doesn't use cookies.