diff --git a/generic/cursor.c b/generic/cursor.c index 1a24c1c..eecb0f9 100644 --- a/generic/cursor.c +++ b/generic/cursor.c @@ -170,17 +170,21 @@ mongotcl_tcllist_to_cursor_fields (Tcl_Interp *interp, Tcl_Obj *fieldList, mongo char *key = Tcl_GetString (listObjv[i]); if (Tcl_GetIntFromObj (interp, listObjv[i+1], &want) == TCL_ERROR) { - error: - bson_destroy(mc->fieldsBson); - return TCL_ERROR; + bson_error: + return mongotcl_setBsonError (interp, mc->fieldsBson); } if (bson_append_int (mc->fieldsBson, key, want) != BSON_OK) { - Tcl_SetObjResult (interp, Tcl_NewStringObj ("bson error while generating field list", -1)); - goto error; + goto bson_error; } } + if (bson_finish (mc->fieldsBson) != BSON_OK) { + goto bson_error; + } + + mongo_cursor_set_fields (mc->cursor, mc->fieldsBson); + return TCL_OK; } diff --git a/generic/mongotcl.h b/generic/mongotcl.h index 3b93ad9..d3996d7 100644 --- a/generic/mongotcl.h +++ b/generic/mongotcl.h @@ -44,6 +44,9 @@ mongotcl_setMongoError (Tcl_Interp *interp, mongo *conn); extern int mongotcl_create_bson_command (Tcl_Interp *interp, char *commandName, CONST bson *bsonObj); +extern int +mongotcl_setBsonError (Tcl_Interp *interp, bson *bson); + extern int mongotcl_createCursorObjCmd(Tcl_Interp *interp, mongo *conn, char *commandName, char *namespace); ;