From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id C12312CC93 for ; Mon, 19 Nov 2018 12:58:06 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id g3b3S7n3z62W for ; Mon, 19 Nov 2018 12:58:06 -0500 (EST) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 803F02D601 for ; Mon, 19 Nov 2018 12:58:06 -0500 (EST) Subject: [tarantool-patches] Re: [PATCH v1 09/10] lua: create vstream implementation for Lua References: From: Vladislav Shpilevoy Message-ID: Date: Mon, 19 Nov 2018 20:58:04 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org, imeevma@tarantool.org 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;