Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Kirill Shcherbatov <kshcherbatov@tarantool.org>,
	tarantool-patches@freelists.org
Subject: [tarantool-patches] Re: [PATCH v5 6/6] box: user-friendly interface to manage ck constraints
Date: Sun, 26 May 2019 15:07:39 +0300	[thread overview]
Message-ID: <a9c26aff-d274-8a03-1e54-124f1a4407b8@tarantool.org> (raw)
In-Reply-To: <bc2fbb1c4621ee2b8d52d5692547b71092cef3e8.1558605591.git.kshcherbatov@tarantool.org>

Thanks for the patch! See 1 comment below.

> diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc
> index 3e8f3b2e5..b375716c6 100644
> --- a/src/box/lua/space.cc
> +++ b/src/box/lua/space.cc
> @@ -28,6 +28,7 @@
>   * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
>   * SUCH DAMAGE.
>   */
> +#include "box/ck_constraint.h"
>  #include "box/lua/space.h"
>  #include "box/lua/tuple.h"
>  #include "box/lua/key_def.h"
> @@ -147,6 +148,66 @@ lbox_space_before_replace(struct lua_State *L)
>  				  lbox_push_txn_stmt, lbox_pop_txn_stmt);
>  }
>  
> +/**
> + * Make ck_constraints available in Lua, via ck_constraint[]
> + * array.
> + * Updata a ck_constraint table in the parent space table object
> + * on the Lua stack.
> + */
> +static void
> +lbox_ck_constraint(struct lua_State *L, struct space *space, int i)
> +{
> +	lua_getfield(L, i, "ck_constraint");
> +	if (lua_isnil(L, -1)) {
> +		lua_pop(L, 1);
> +		lua_pushstring(L, "ck_constraint");
> +		lua_newtable(L);
> +		lua_settable(L, i);
> +		lua_getfield(L, i, "ck_constraint");
> +	} else {
> +		lua_pushnil(L);
> +		while (lua_next(L, -2) != 0) {
> +			size_t name_len;
> +			const char *name = lua_tolstring(L, -2, &name_len);
> +			/*
> +			 * Remove ck_constraint only if it was
> +			 * deleted.
> +			 */
> +			if (space_ck_constraint_by_name(space, name,
> +					(uint32_t)name_len) == NULL) {
> +				lua_pushlstring(L, name, name_len);
> +				lua_pushnil(L);
> +				lua_settable(L, -5);
> +			}
> +			lua_pop(L, 1);
> +		}
> +	}
> +	struct ck_constraint *ck_constraint = NULL;
> +	rlist_foreach_entry(ck_constraint, &space->ck_constraint, link) {
> +		lua_getfield(L, i, ck_constraint->def->name);
> +		if (lua_isnil(L, -1)) {
> +			lua_pop(L, 1);
> +			lua_pushstring(L, ck_constraint->def->name);
> +			lua_newtable(L);
> +			lua_settable(L, -3);
> +			lua_getfield(L, -1, ck_constraint->def->name);
> +			assert(!lua_isnil(L, -1));
> +		}
> +
> +		lua_pushstring(L, ck_constraint->def->name);
> +		lua_setfield(L, -2, "name");
> +
> +		lua_pushnumber(L, space->def->id);
> +		lua_setfield(L, -2, "space_id");
> +
> +		lua_pushstring(L, ck_constraint->def->expr_str);
> +		lua_setfield(L, -2, "expr_str");

1. I think, 'expr' is better name. What else except 'str' you
can expose? - nothing. It means, that '_str' suffix is
redundant, IMO.

> +
> +		lua_setfield(L, -2, ck_constraint->def->name);
> +	}
> +	lua_pop(L, 1);
> +}

  reply	other threads:[~2019-05-26 12:07 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-23 10:19 [tarantool-patches] [PATCH v5 0/6] box: run checks on insertions in LUA spaces Kirill Shcherbatov
2019-05-23 10:19 ` [tarantool-patches] [PATCH v5 1/6] sql: introduce a new method to bind a pointer Kirill Shcherbatov
2019-05-23 10:19 ` [tarantool-patches] [PATCH v5 2/6] sql: refactor OP_Column vdbe instruction Kirill Shcherbatov
2019-05-23 10:19 ` [tarantool-patches] [PATCH v5 3/6] sql: introduce tuple_fetcher class Kirill Shcherbatov
2019-05-26 12:05   ` [tarantool-patches] " Vladislav Shpilevoy
2019-05-31 13:45     ` Kirill Shcherbatov
2019-05-31 19:45       ` Konstantin Osipov
2019-05-31 19:50         ` Kirill Shcherbatov
2019-05-31 22:36         ` Vladislav Shpilevoy
2019-06-01  5:45           ` Konstantin Osipov
2019-06-02 18:50         ` Kirill Shcherbatov
2019-06-03 21:15           ` Vladislav Shpilevoy
2019-06-05  6:47           ` Konstantin Osipov
2019-06-05  6:48             ` Konstantin Osipov
2019-05-23 10:19 ` [tarantool-patches] [PATCH v5 4/6] schema: add new system space for CHECK constraints Kirill Shcherbatov
2019-05-26 12:06   ` [tarantool-patches] " Vladislav Shpilevoy
2019-05-26 13:31     ` n.pettik
2019-05-26 13:32       ` Vladislav Shpilevoy
2019-05-31 13:45     ` Kirill Shcherbatov
2019-06-03 21:15       ` Vladislav Shpilevoy
2019-05-23 10:19 ` [tarantool-patches] [PATCH v5 5/6] box: run check constraint tests on space alter Kirill Shcherbatov
2019-05-26 12:07   ` [tarantool-patches] " Vladislav Shpilevoy
2019-05-31 13:45     ` Kirill Shcherbatov
2019-06-03 21:15       ` Vladislav Shpilevoy
2019-05-23 10:19 ` [tarantool-patches] [PATCH v5 6/6] box: user-friendly interface to manage ck constraints Kirill Shcherbatov
2019-05-26 12:07   ` Vladislav Shpilevoy [this message]
2019-05-31 13:45     ` [tarantool-patches] " Kirill Shcherbatov
2019-06-03 21:15 ` [tarantool-patches] Re: [PATCH v5 0/6] box: run checks on insertions in LUA spaces Vladislav Shpilevoy
2019-06-04  7:21   ` Kirill Shcherbatov
2019-06-04 18:59     ` Vladislav Shpilevoy
2019-06-06 11:58 ` Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a9c26aff-d274-8a03-1e54-124f1a4407b8@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH v5 6/6] box: user-friendly interface to manage ck constraints' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox