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 44A5325712 for ; Wed, 16 Jan 2019 13:25:45 -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 SSx6y-9Iu9YX for ; Wed, 16 Jan 2019 13:25:45 -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 F01242570D for ; Wed, 16 Jan 2019 13:25:44 -0500 (EST) Subject: [tarantool-patches] Re: [PATCH v7 3/6] iproto: create port_sql References: <1a3007030ea54fa81533acbf7421f27a2399c941.1547565887.git.imeevma@gmail.com> From: Vladislav Shpilevoy Message-ID: Date: Wed, 16 Jan 2019 21:25:33 +0300 MIME-Version: 1.0 In-Reply-To: <1a3007030ea54fa81533acbf7421f27a2399c941.1547565887.git.imeevma@gmail.com> 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 2 comments below. > commit 1a3007030ea54fa81533acbf7421f27a2399c941 > Author: Mergen Imeev > Date: Fri Dec 21 14:52:03 2018 +0300 > > iproto: create port_sql > > This patch creates port_sql implementation for the port. This will > allow us to dump sql responses to obuf or to Lua. Also this patch > defines methods dump_msgpack() and destroy() of port_sql. > > Part of #3505 > > diff --git a/src/box/execute.c b/src/box/execute.c > index 38b6cbc..a81f482 100644 > --- a/src/box/execute.c > +++ b/src/box/execute.c > @@ -643,7 +672,66 @@ err: > +/** > + * Execute prepared SQL statement. > + * > + * This function uses region to allocate memory for temporary > + * objects. After this function, region will be in the same state > + * in which it was before this function. > + * > + * @param db SQL handle. > + * @param stmt Prepared statement. > + * @param[out] port Port to store SQL response. 1. It is not [out]. Port should be created before calling this function, so it is [in][out], that we usually omit. > + * @param region Region to allocate temporary objects. > + * > + * @retval 0 Success. > + * @retval -1 Error. > + */ > +static inline int > +sql_execute(sqlite3 *db, struct sqlite3_stmt *stmt, struct port *port, > + struct region *region) > +{ > + int rc, column_count = sqlite3_column_count(stmt); > + if (column_count > 0) { > + /* Either ROW or DONE or ERROR. */ > + while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { > + if (sql_row_to_port(stmt, column_count, region, > + port) != 0) > + return -1; > + } > + assert(rc == SQLITE_DONE || rc != SQLITE_OK); > + } else { > + /* No rows. Either DONE or ERROR. */ > + rc = sqlite3_step(stmt); > + assert(rc != SQLITE_ROW && rc != SQLITE_OK); > + } > + if (rc != SQLITE_DONE) { > + diag_set(ClientError, ER_SQL_EXECUTE, sqlite3_errmsg(db)); > + return -1; > + } > + return 0; > +} > diff --git a/src/box/iproto.cc b/src/box/iproto.cc > index a08c8c5..09e8914 100644 > --- a/src/box/iproto.cc > +++ b/src/box/iproto.cc > @@ -1643,9 +1643,11 @@ tx_process_sql(struct cmsg *m) > out = msg->connection->tx.p_obuf; > struct obuf_svp header_svp; > /* Prepare memory for the iproto header. */ > - if (iproto_prepare_header(out, &header_svp, IPROTO_HEADER_LEN) != 0) > + if (iproto_prepare_header(out, &header_svp, IPROTO_HEADER_LEN) != 0) { > + port_destroy(&port); > goto error; > - if (sql_response_dump(&response, out) != 0) { > + } > + if (port_dump_msgpack(&port, out) != 0) { 2. port_sql_dump_msgpack destroys port on an error, but port_tuple_dump_msgpack does not. I think, they should work similar, so port_sql_dump_msgpack does not destroy the port as well. Lets do it, and add here port_destroy() on an error. The same about port_dump_lua. > obuf_rollback_to_svp(out, &header_svp); > goto error; > }