This repository was archived by the owner on Jun 18, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +41
-4
lines changed
Expand file tree Collapse file tree 3 files changed +41
-4
lines changed Original file line number Diff line number Diff line change 22
33namespace arangodb { namespace fuerte { namespace php {
44
5- Cursor::Cursor (Connection* connection, Vpack* vpack): vpack(vpack), connection(connection)
5+ Cursor::Cursor (Connection* connection, Vpack* vpack): vpack(* vpack), connection(connection)
66 {
7- this ->loadFirstBatch ();
7+ this ->rewind ();
88 }
99
1010 void Cursor::setOption (int option, int value)
@@ -18,7 +18,7 @@ namespace arangodb { namespace fuerte { namespace php {
1818
1919 void Cursor::loadFirstBatch ()
2020 {
21- Request request (" /_api/cursor" , this ->vpack );
21+ Request request (" /_api/cursor" , & this ->vpack );
2222 request.setHttpMethod (Request::METHOD_POST);
2323
2424 Response* response = this ->connection ->sendRequest (&request);
@@ -115,6 +115,8 @@ namespace arangodb { namespace fuerte { namespace php {
115115
116116 void Cursor::rewind ()
117117 {
118+ this ->position = 0 ;
119+ this ->loadFirstBatch ();
118120 }
119121
120122 long Cursor::count () {
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ namespace arangodb { namespace fuerte { namespace php {
1717 {
1818 private:
1919 Connection* connection;
20- Vpack* vpack;
20+ Vpack vpack;
2121
2222 bool hasMore;
2323 int position = 0 ;
Original file line number Diff line number Diff line change @@ -246,4 +246,39 @@ public function it_creates_array_from_cursor()
246246
247247 $ this ->assertCount (100 , $ data );
248248 }
249+
250+
251+ /**
252+ * @test
253+ */
254+ public function it_rewinds_cursor_multiple_times ()
255+ {
256+ $ this ->connection = TestUtil::getConnection ();
257+
258+ $ cursor = $ this ->connection ->query (Vpack::fromArray ([
259+ 'query ' => 'FOR i IN 1..100 RETURN [i, i+1] ' ,
260+ 'batchSize ' => 10
261+ ]));
262+
263+ $ iterations = 0 ;
264+ $ dataSet1 = [];
265+ $ dataSet2 = [];
266+
267+ while ($ cursor ->valid ()) {
268+ $ dataSet1 [] = $ cursor ->current ();
269+ $ cursor ->next ();
270+ $ iterations ++;
271+ }
272+
273+ $ cursor ->rewind ();
274+
275+ while ($ cursor ->valid ()) {
276+ $ dataSet2 [] = $ cursor ->current ();
277+ $ cursor ->next ();
278+ $ iterations ++;
279+ }
280+
281+ $ this ->assertSame (200 , $ iterations );
282+ $ this ->assertTrue ($ dataSet1 === $ dataSet2 );
283+ }
249284}
You can’t perform that action at this time.
0 commit comments