/**
 Always make sure the db cursor set is released, no matter what happens.
*/
ham_status_t 
btree_close_cursors(ham_db_t *db, ham_u32_t flags)
{
    ham_status_t st = HAM_SUCCESS;
    ham_status_t st2 = HAM_SUCCESS;

    /*
    * auto-cleanup cursors?
    */
    if (db_get_cursors(db)) {
        ham_bt_cursor_t *c=(ham_bt_cursor_t *)db_get_cursors(db);
        while (c) {
            ham_bt_cursor_t *next=(ham_bt_cursor_t *)cursor_get_next(c);
            if (flags&HAM_AUTO_CLEANUP)
            {
                st=ham_cursor_close((ham_cursor_t *)c);
            }
            else
            {
                //st=bt_cursor_close(c);
                st=c->_fun_close(c);
            }
            if (st)
            {
                if (st2 == 0) st2 = st;
                /* continue to try to close the other cursors, though */
            }
            c=next;
        }
        db_set_cursors(db, 0);
    }
    
    return st2;
}
Exemple #2
0
static ham_status_t
_remote_fun_close(ham_db_t *db, ham_u32_t flags)
{
    ham_status_t st;
    ham_env_t *env=db_get_env(db);
    proto_wrapper_t *request, *reply;
    
    /*
     * auto-cleanup cursors?
     */
    if (flags&HAM_AUTO_CLEANUP) {
        ham_cursor_t *cursor=db_get_cursors(db);
        while ((cursor=db_get_cursors(db))) {
            (void)ham_cursor_close(cursor);
        }
    }
    else if (db_get_cursors(db)) {
        return (HAM_CURSOR_STILL_OPEN);
    }

    request=proto_init_db_close_request(db_get_remote_handle(db), flags);

    st=_perform_request(env, env_get_curl(env), request, &reply);
    proto_delete(request);
    if (st) {
        if (reply)
            proto_delete(reply);
        return (st);
    }

    ham_assert(reply!=0, (""));
    ham_assert(proto_has_db_close_reply(reply), (""));

    st=proto_db_close_reply_get_status(reply);

    proto_delete(reply);

    if (st==0)
        db_set_remote_handle(db, 0);

    return (st);
}