Cursor delete operation only requires cursor handle and key (no need for a value)

This commit is contained in:
Gregory Burd 2013-03-21 18:44:13 -04:00
parent a844dc5846
commit 0203b06a61
2 changed files with 16 additions and 14 deletions

View file

@ -101,7 +101,7 @@ static ErlNifFunc nif_funcs[] =
{"cursor_prev", 1, wterl_cursor_prev}, {"cursor_prev", 1, wterl_cursor_prev},
{"cursor_prev_key", 1, wterl_cursor_prev_key}, {"cursor_prev_key", 1, wterl_cursor_prev_key},
{"cursor_prev_value", 1, wterl_cursor_prev_value}, {"cursor_prev_value", 1, wterl_cursor_prev_value},
{"cursor_remove", 3, wterl_cursor_remove}, {"cursor_remove", 2, wterl_cursor_remove},
{"cursor_reset", 1, wterl_cursor_reset}, {"cursor_reset", 1, wterl_cursor_reset},
{"cursor_search", 2, wterl_cursor_search}, {"cursor_search", 2, wterl_cursor_search},
{"cursor_search_near", 2, wterl_cursor_search_near}, {"cursor_search_near", 2, wterl_cursor_search_near},
@ -614,16 +614,21 @@ static inline ERL_NIF_TERM wterl_cursor_data_op(ErlNifEnv* env, int argc, const
{ {
ErlNifBinary key, value; ErlNifBinary key, value;
int rc; int rc;
if (enif_inspect_binary(env, argv[1], &key) && enif_inspect_binary(env, argv[2], &value))
if (enif_inspect_binary(env, argv[1], &key) &&
(op == WTERL_OP_CURSOR_REMOVE ? 1 : enif_inspect_binary(env, argv[2], &value)))
{ {
WT_CURSOR* cursor = cursor_handle->cursor; WT_CURSOR* cursor = cursor_handle->cursor;
WT_ITEM raw_key, raw_value; WT_ITEM raw_key, raw_value;
raw_key.data = key.data; raw_key.data = key.data;
raw_key.size = key.size; raw_key.size = key.size;
cursor->set_key(cursor, &raw_key); cursor->set_key(cursor, &raw_key);
raw_value.data = value.data; if (op != WTERL_OP_CURSOR_REMOVE)
raw_value.size = value.size; {
cursor->set_value(cursor, &raw_value); raw_value.data = value.data;
raw_value.size = value.size;
cursor->set_value(cursor, &raw_value);
}
switch (op) switch (op)
{ {
case WTERL_OP_CURSOR_INSERT: case WTERL_OP_CURSOR_INSERT:

View file

@ -31,7 +31,7 @@
cursor_prev/1, cursor_prev/1,
cursor_prev_key/1, cursor_prev_key/1,
cursor_prev_value/1, cursor_prev_value/1,
cursor_remove/3, cursor_remove/2,
cursor_reset/1, cursor_reset/1,
cursor_search/2, cursor_search/2,
cursor_search_near/2, cursor_search_near/2,
@ -242,8 +242,8 @@ cursor_insert(_Cursor, _Key, _Value) ->
cursor_update(_Cursor, _Key, _Value) -> cursor_update(_Cursor, _Key, _Value) ->
?nif_stub. ?nif_stub.
-spec cursor_remove(cursor(), key(), value()) -> ok | {error, term()}. -spec cursor_remove(cursor(), key()) -> ok | {error, term()}.
cursor_remove(_Cursor, _Key, _Value) -> cursor_remove(_Cursor, _Key) ->
?nif_stub. ?nif_stub.
-type fold_keys_fun() :: fun((Key::binary(), any()) -> any()). -type fold_keys_fun() :: fun((Key::binary(), any()) -> any()).
@ -586,13 +586,10 @@ various_cursor_test_() ->
{"remove an item using a cursor", {"remove an item using a cursor",
fun() -> fun() ->
{ok, Cursor} = cursor_open(SRef, "table:test"), {ok, Cursor} = cursor_open(SRef, "table:test"),
?assertMatch(ok, ?assertMatch(ok, cursor_remove(Cursor, <<"g">>)),
cursor_remove(Cursor, <<"g">>, <<"goji berries">>)), ?assertMatch(not_found, cursor_remove(Cursor, <<"l">>)),
?assertMatch(not_found,
cursor_remove(Cursor, <<"l">>, <<"lemon">>)),
?assertMatch(ok, cursor_close(Cursor)), ?assertMatch(ok, cursor_close(Cursor)),
?assertMatch(not_found, ?assertMatch(not_found, session_get(SRef, "table:test", <<"g">>))
session_get(SRef, "table:test", <<"g">>))
end}]} end}]}
end}. end}.