Skip to content

Commit

Permalink
Make the cursor next method return 1 if a row was available and 0 if …
Browse files Browse the repository at this point in the history
…the cursor is exhausted, rather than generating a Tcl error if the cursor was exhausted. Previously the next method didn't return anything. Update README.md accordingly.

BUGZID:
  • Loading branch information
lehenbauer committed Feb 13, 2014
1 parent e35a5ff commit d538a7a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ Initialize or reinitialize a cursor.

* $cursor next

Move the cursor to the next row.
Move the cursor to the next row. Returns true if there is a next row, false if the cursor is exhausted.

Any error condition (CURSOR_INVALID, CURSOR_PENDING, CURSOR_QUERY_FAIL, CURSOR_BSON_ERROR), it generates a Tcl error and sets the error code to a list consisting of MONGO and the aforementioned condition code.

* $cursor to_list

Expand Down
10 changes: 8 additions & 2 deletions generic/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,14 @@ mongotcl_cursorObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_
}

case OPT_CURSOR_NEXT: {
if (mongo_cursor_next (mc->cursor) != MONGO_OK) {
return mongotcl_setCursorError (interp, mc->cursor);
if (mongo_cursor_next (mc->cursor) == MONGO_OK) {
Tcl_SetObjResult (interp, Tcl_NewBooleanObj (1));
} else {
if (mc->cursor->err == MONGO_CURSOR_EXHAUSTED) {
Tcl_SetObjResult (interp, Tcl_NewBooleanObj (0));
} else {
return mongotcl_setCursorError (interp, mc->cursor);
}
}
break;
}
Expand Down

0 comments on commit d538a7a

Please sign in to comment.