diff --git a/lib/triagens/ArangoDb/BatchedCursor.php b/lib/triagens/ArangoDb/BatchedCursor.php new file mode 100644 index 00000000..20447f4e --- /dev/null +++ b/lib/triagens/ArangoDb/BatchedCursor.php @@ -0,0 +1,48 @@ +_result=[]; + $this->add( $data ); + $this->rewind(); + $this->updateLength(); + } + + public function fetchNextBatch() + { + // continuation + $this->_processed += $this->_length; + $response = $this->_connection->put($this->url() . '/' . $this->_id, '', array()); + ++$this->_fetches; + + $data = $response->getJson(); + + $this->_hasMore = (bool) $data[Cursor::ENTRY_HASMORE]; + $this->setResults($data[Cursor::ENTRY_RESULT]); + + if (!$this->_hasMore) { + // we have fetched the complete result set and can unset the id now + $this->_id = null; + } + return $this->_result; + } + + public function next() + { + parent::next(); + if( $this->key() >= $this->_length && $this->_hasMore ) + { + $this->fetchNextBatch(); + } + } + + public function fullKey() + { + return $this->_processed + $this->key(); + } +} +?> \ No newline at end of file diff --git a/lib/triagens/ArangoDb/BatchedStatement.php b/lib/triagens/ArangoDb/BatchedStatement.php new file mode 100644 index 00000000..8d66809e --- /dev/null +++ b/lib/triagens/ArangoDb/BatchedStatement.php @@ -0,0 +1,16 @@ +sanitize($data) as $row) { if (!is_array($row) || (isset($this->_options[self::ENTRY_FLAT]) && $this->_options[self::ENTRY_FLAT])) { @@ -672,7 +672,7 @@ private function fetchOutstanding() * * @return void */ - private function updateLength() + protected function updateLength() { $this->_length = count($this->_result); } @@ -683,7 +683,7 @@ private function updateLength() * * @return string */ - private function url() + protected function url() { if (isset($this->_options[self::ENTRY_BASEURL])) { return $this->_options[self::ENTRY_BASEURL]; diff --git a/lib/triagens/ArangoDb/Statement.php b/lib/triagens/ArangoDb/Statement.php index 5786ee94..e42ad203 100644 --- a/lib/triagens/ArangoDb/Statement.php +++ b/lib/triagens/ArangoDb/Statement.php @@ -250,7 +250,7 @@ public function execute() while (true) { try { $response = $this->_connection->post(Urls::URL_CURSOR, $this->getConnection()->json_encode_wrapper($data), array()); - return new Cursor($this->_connection, $response->getJson(), $this->getCursorOptions()); + return static::getCursor($this->_connection, $response->getJson(), $this->getCursorOptions()); } catch (ServerException $e) { if ($tries++ >= $this->_retries) { throw $e; @@ -264,6 +264,10 @@ public function execute() } } + protected static function getCursor($connection, $json, $options) + { + return new Cursor( $connection, $json, $options ); + } /** * Explain the statement's execution plan diff --git a/test b/test new file mode 100644 index 00000000..62d8fe9f --- /dev/null +++ b/test @@ -0,0 +1 @@ +X