From d538a7a4602a0cd38e60d4d024c70132e6a8c609 Mon Sep 17 00:00:00 2001 From: Karl Lehenbauer Date: Thu, 13 Feb 2014 23:24:41 +0000 Subject: [PATCH] Make the cursor next method return 1 if a row was available and 0 if 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: --- README.md | 4 +++- generic/cursor.c | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b5e3f4a..fc1f6a6 100755 --- a/README.md +++ b/README.md @@ -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 diff --git a/generic/cursor.c b/generic/cursor.c index f3c282f..35c7782 100644 --- a/generic/cursor.c +++ b/generic/cursor.c @@ -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; }