/** * Ensure the query is complete * * Amazon SDB only returns a limited set of data (usually around 100 results). * Calling this method will ensure that SDB is queried until all results are * returned. It will stop retrieving results when MAX_QUERIES is reached. * * Additionally returned items are appended to this response object's items * array. * * \note Only works with Select statements. It should not be neccasary for * others, except maybe getAttributes if you have a large number of * attributes or listDomains if you have a lot. * * \note The $consistentRead parameter must have the same value as the original * command, if the original query was run with consistentRead==true, * then getAll() must be called as getAll(true) * * @param boolean $consistentRead * [optional] defaults to false. Tell SDB whether or not to force consistency. * This must be the same as the original query (ie if the original query * enforced consistent read, this must be true) * @param int $resultsLimit * [optional] Maximum number of records to return (including the original items) * Defaults to no limit (other than those imposed by MAX_QUERIES). * @param int $offset * [optional] Number of rows to skip from beinging when used with limit. * Defaults to 0 (start from beginning). * @param int $currentOffset * The number of rows already skipped. Defaults to 0 (started from beginning). * @return SDBResponse * The current SDBResponse item is returned for convenience */ public function getAll($consistentRead = false, $resultsLimit = null, $offset = 0, $currentOffset = 0) { if (isset($this->body->SelectResult)) { $result = $this; $query = $this->getQuery(); $count = 0; if ($currentOffset < $offset) { $this->clear(); } if ($resultsLimit) { $limit = $resultsLimit; $currentOffset += count($this->_items); NextTokenCache::Store($query, $limit, $currentOffset, $result->nextToken()); $query = str_replace("LIMIT {$limit}", '', $query); } else { $limit = 2400; } // Continue querying SDB until all items have been fetched or limit is reached while ((is_null($resultsLimit) || count($this->_items) < $resultsLimit) && $result->nextToken()) { $limitRemaining = is_null($resultsLimit) ? $limit : $this->_limitRemaining($limit, $offset, $currentOffset); $result = SDBStatement::Query("{$query} LIMIT {$limitRemaining}", $consistentRead, $result->nextToken()); $this->_setItems($result); $currentOffset += count($result); NextTokenCache::Store("{$query} LIMIT {$limitRemaining}", $limit, $currentOffset, $result->nextToken()); if (++$count > self::MAX_QUERIES) { break; } } } return $this; }
/** * Execute a fetchAll query and deal with offsets and limits * * Populates the _result variable. Uses the $_consistentRead property to * determine whether consistency needs to be enforced for the SDB request * * @return boolean * \c true on success */ private function _executeFetchQuery() { $this->_simplifyQuery(); $optionsArray = array('ConsistentRead' => $this->_consistentRead ? 'true' : 'false'); // If we already know some tokens, don't start from the begining (for speed) $initialOffset = 0; if ($this->_offset > 0) { list($initialOffset, $token) = NextTokenCache::GetNearestToken($this->_queryString, $this->_limit, $this->_offset); if ($token) { $optionsArray['NextToken'] = $token; } } $this->_result = self::$_sdb->select($this->_queryString, $optionsArray)->getAll($this->_consistentRead, $this->_limit, $this->_offset, $initialOffset); $this->_items = $this->_result->items(); return $this->_result->isOK(); }