Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-255

Cursor rewind should throw an exception after iteration begins

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 0.6.0
    • Affects Version/s: 0.4.1
    • Component/s: None
    • None

      Per discussion in PR #37 for PHPC-240, bjori commented:

      After reading the cursor-iterator_handlers-001.phpt testcase, I think we have to throw an exception in rewind() if the cursor has been iterated over, or in the middle of iteration. Repeated calls to rewind() without next() in between is fine (although doesn't make a lot of sense), but after iteration has started a call to rewind() really has to throw OutOfBoundsException.

      It is really confusing if calling rewind() is somewhat of a NOOP and you can continue stepping through some parts of it.

      rewind($cursor); $first = current($cursor); next($cursor);
      rewind($cursor); $firstAgain = current($cursor);
      
      // $first must be == $firstAgain
      

      And since cannot do that without re-executing the query, which we clearly don't want to do – I think we must throw an exception.

      Reply from derick:

      I think calling rewind more than once (even when no next() is called), should throw that exception.

            Assignee:
            jmikola@mongodb.com Jeremy Mikola
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: