From 645e9a3ba40a402a514dfd90e0ffab5b01b4b90b Mon Sep 17 00:00:00 2001 From: Konstantin Osipov <kostja@tarantool.org> Date: Mon, 30 Jul 2012 17:10:34 +0400 Subject: [PATCH] A fix and a test case for Bug#1030856 A fix and a test case for Bug#1030856 'box.update() doesn't support subtract, contrary to the user guide' Add subtract support, add a test. --- mod/box/request.h | 5 +++-- mod/box/request.m | 14 ++++++++++++++ src/tarantool_lua.m | 3 +++ test/box/lua.result | 12 +++++++++--- test/box/lua.test | 2 ++ 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/mod/box/request.h b/mod/box/request.h index 90cc56179b..5f25eabbae 100644 --- a/mod/box/request.h +++ b/mod/box/request.h @@ -89,8 +89,9 @@ extern const char *requests_strs[]; _(UPDATE_OP_SPLICE, 5) \ _(UPDATE_OP_DELETE, 6) \ _(UPDATE_OP_INSERT, 7) \ - _(UPDATE_OP_NONE, 8) \ - _(UPDATE_OP_MAX, 9) \ + _(UPDATE_OP_SUBTRACT, 8) \ + _(UPDATE_OP_NONE, 9) \ + _(UPDATE_OP_MAX, 10) \ ENUM(update_op_codes, UPDATE_OP_CODES); diff --git a/mod/box/request.m b/mod/box/request.m index 77de17eadb..ffc47ef6f2 100644 --- a/mod/box/request.m +++ b/mod/box/request.m @@ -307,6 +307,19 @@ do_update_op_add(struct op_arith_arg *arg, void *in, void *out) } } +static void +do_update_op_subtract(struct op_arith_arg *arg, void *in, void *out) +{ + switch (arg->val_size) { + case sizeof(i32): + *(i32 *)out = *(i32 *)in - arg->i32_val; + break; + case sizeof(i64): + *(i64 *)out = *(i64 *)in - arg->i64_val; + break; + } +} + static void do_update_op_and(struct op_arith_arg *arg, void *in, void *out) { @@ -535,6 +548,7 @@ static struct update_op_meta update_op_meta[UPDATE_OP_MAX + 1] = { { init_update_op_splice, (do_op_func) do_update_op_splice, false }, { init_update_op_delete, (do_op_func) NULL, true }, { init_update_op_insert, (do_op_func) do_update_op_insert, true }, + { init_update_op_arith, (do_op_func) do_update_op_subtract, true }, { init_update_op_none, (do_op_func) do_update_op_none, false }, { init_update_op_error, (do_op_func) NULL, true } }; diff --git a/src/tarantool_lua.m b/src/tarantool_lua.m index a9f02801c0..63903f60ca 100644 --- a/src/tarantool_lua.m +++ b/src/tarantool_lua.m @@ -155,6 +155,7 @@ static char format_to_opcode(char format) case ':': return 5; case '#': return 6; case '!': return 7; + case '-': return 8; default: return format; } } @@ -255,6 +256,8 @@ lbox_pack(struct lua_State *L) /* update tuple set foo = bar */ case '+': /* set field += val */ + case '-': + /* set field -= val */ case '&': /* set field & =val */ case '|': diff --git a/test/box/lua.result b/test/box/lua.result index d5b965cec0..a063fc7792 100644 --- a/test/box/lua.result +++ b/test/box/lua.result @@ -237,13 +237,19 @@ No match call box.update(0, 'pass', '+p', 2, '���') Found 1 tuple: [1936941424, 'new', 1684234850] +call box.update(0, 'pass', '-p', 2, '���') +Found 1 tuple: +[1936941424, 'new', 1684234849] +call box.update(0, 'pass', '-p', 2, '���') +Found 1 tuple: +[1936941424, 'new', 1684234848] lua box.update(0, 'pass', '+p', 2, 1) --- - - 1936941424: {'new', 1684234851} + - 1936941424: {'new', 1684234849} ... call box.select(0, 0, 'pass') Found 1 tuple: -[1936941424, 'new', 1684234851] +[1936941424, 'new', 1684234849] lua function field_x(space, key, field_index) return (box.select(space, 0, key))[field_index] end --- ... @@ -255,7 +261,7 @@ Found 1 tuple: ['new'] call box.delete(0, 'pass') Found 1 tuple: -[1936941424, 'new', 1684234851] +[1936941424, 'new', 1684234849] lua dofile(...) --- ... diff --git a/test/box/lua.test b/test/box/lua.test index 8d79f5d610..1301fc2d88 100644 --- a/test/box/lua.test +++ b/test/box/lua.test @@ -79,6 +79,8 @@ exec sql "call box.select(0, 0, 'pass')" exec sql "call box.select_range(0, 0, 1, 'pass')" exec sql "call box.update(0, 'miss', '+p', 2, '\1\0\0\0')" exec sql "call box.update(0, 'pass', '+p', 2, '\1\0\0\0')" +exec sql "call box.update(0, 'pass', '-p', 2, '\1\0\0\0')" +exec sql "call box.update(0, 'pass', '-p', 2, '\1\0\0\0')" exec admin "lua box.update(0, 'pass', '+p', 2, 1)" exec sql "call box.select(0, 0, 'pass')" exec admin "lua function field_x(space, key, field_index) return (box.select(space, 0, key))[field_index] end" -- GitLab