Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org, imeevma@tarantool.org
Subject: [tarantool-patches] Re: [PATCH v1 09/10] lua: create vstream implementation for Lua
Date: Mon, 19 Nov 2018 20:58:04 +0300	[thread overview]
Message-ID: <e33b80e7-db6e-c8b9-675a-2c978818cb3f@tarantool.org> (raw)
In-Reply-To: <c827f8f4b5475cb26bc25df21589878bd887a1f5.1542460773.git.imeevma@gmail.com>

Thanks for the patch! See 1 comment below.

> @@ -111,6 +113,39 @@ sqlerror:
>   }
>   
>   static int
> +lbox_execute(struct lua_State *L)
> +{
> +	struct sqlite3 *db = sql_get();
> +	if (db == NULL)
> +		return luaL_error(L, "not ready");
> +
> +	size_t length;
> +	const char *sql = lua_tolstring(L, 1, &length);
> +	if (sql == NULL)
> +		return luaL_error(L, "usage: box.execute(sqlstring)");
> +
> +	struct sql_request request = {};
> +	struct sql_response response = {};

Please, do not forget about binding parameters. You should write an
analogue of sql_bind_list_decode() but in Lua. I do not know how to
virtualize decoding, so lets just write a Lua version of
sql_bind_list_decode(), it does not look too hard.

> +	request.sql_text = sql;
> +	request.sql_text_len = length;
> +	if (sql_prepare_and_execute(&request, &response, &fiber()->gc) != 0)
> +		goto sqlerror;
> +
> +	int keys;
> +	struct vstream vstream;
> +	lua_vstream_init(&vstream, L);
> +	lua_newtable(L);
> +	if (sql_response_dump(&response, &keys, &vstream) != 0) {
> +		lua_pop(L, 1);
> +		goto sqlerror;
> +	}
> +	return 1;
> +sqlerror:
> +	lua_pushstring(L, sqlite3_errmsg(db));
> +	return lua_error(L);
> +}
> +
> +static int
>   lua_sql_debug(struct lua_State *L)
>   {
>   	struct info_handler info;

  reply	other threads:[~2018-11-19 17:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-17 14:03 [tarantool-patches] [PATCH v1 00/10] sql: remove box.sql.execute imeevma
2018-11-17 14:03 ` [tarantool-patches] [PATCH v1 01/10] box: store sql text and length in sql_request imeevma
2018-11-17 14:03 ` [tarantool-patches] [PATCH v1 02/10] iproto: remove iproto functions from execute.c imeevma
2018-11-19 17:58   ` [tarantool-patches] " Vladislav Shpilevoy
2018-11-17 14:03 ` [tarantool-patches] [PATCH v1 03/10] iproto: replace obuf by mpstream in execute.c imeevma
2018-11-17 14:03 ` [tarantool-patches] [PATCH v1 04/10] sql: create interface vstream imeevma
2018-11-19 17:58   ` [tarantool-patches] " Vladislav Shpilevoy
2018-11-17 14:03 ` [tarantool-patches] [PATCH v1 05/10] sql: EXPLAIN through net.box leads to SEGFAULT imeevma
2018-11-19 13:47   ` [tarantool-patches] " Vladislav Shpilevoy
2018-11-17 14:04 ` [tarantool-patches] [PATCH v1 06/10] sql: SELECT from system spaces returns unpacked msgpack imeevma
2018-11-19 13:48   ` [tarantool-patches] " Vladislav Shpilevoy
2018-11-17 14:04 ` [tarantool-patches] [PATCH v1 07/10] sql: too many autogenerated ids leads to SEGFAULT imeevma
2018-11-19 13:47   ` [tarantool-patches] " Vladislav Shpilevoy
2018-11-17 14:04 ` [tarantool-patches] [PATCH v1 08/10] box: add method dump_lua to port imeevma
2018-11-17 14:04 ` [tarantool-patches] [PATCH v1 09/10] lua: create vstream implementation for Lua imeevma
2018-11-19 17:58   ` Vladislav Shpilevoy [this message]
2018-11-17 14:04 ` [tarantool-patches] [PATCH v1 10/10] sql: check new box.sql.execute() imeevma
2018-11-19 12:54 ` [tarantool-patches] Re: [PATCH v1 00/10] sql: remove box.sql.execute Vladislav Shpilevoy

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=e33b80e7-db6e-c8b9-675a-2c978818cb3f@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH v1 09/10] lua: create vstream implementation for Lua' \
    /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