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 AC098292B7 for ; Tue, 27 Aug 2019 09:34:37 -0400 (EDT) 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 LzihCrM8AJR1 for ; Tue, 27 Aug 2019 09:34:37 -0400 (EDT) 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 634522928C for ; Tue, 27 Aug 2019 09:34:37 -0400 (EDT) From: Nikita Pettik Subject: [tarantool-patches] [PATCH 6/8] refactoring: use sql_prepare() and sql_execute() in tx_process_sql() Date: Tue, 27 Aug 2019 16:34:27 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: 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 Cc: v.shpilevoy@tarantool.org, kostja@tarantool.org, alexander.turenko@tarantool.org, Nikita Pettik In case of dry-run execution we don't need to substitute binding values or execute statement. So now we split sql_prepare_and_execute() into independent steps, so that we can omit some of them depending on execution mode. Needed for #3292 --- src/box/execute.c | 17 +---------------- src/box/execute.h | 17 +++++++++++++++++ src/box/iproto.cc | 15 +++++++++++++-- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/box/execute.c b/src/box/execute.c index 078753342..a8a2e516b 100644 --- a/src/box/execute.c +++ b/src/box/execute.c @@ -398,22 +398,7 @@ port_sql_dump_msgpack(struct port *port, struct obuf *out) return 0; } -/** - * 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 port Port to store SQL response. - * @param region Region to allocate temporary objects. - * - * @retval 0 Success. - * @retval -1 Error. - */ -static inline int +int sql_execute(struct sql_stmt *stmt, struct port *port, struct region *region) { int rc, column_count = sql_column_count(stmt); diff --git a/src/box/execute.h b/src/box/execute.h index 1b4e14246..23366d65c 100644 --- a/src/box/execute.h +++ b/src/box/execute.h @@ -81,6 +81,23 @@ int sql_prepare(const char *sql, int length, struct sql_stmt **stmt, const char **sql_tail); +/** + * 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 stmt Prepared statement. + * @param port Port to store SQL response. + * @param region Region to allocate temporary objects. + * + * @retval 0 Success. + * @retval -1 Error. + */ +int +sql_execute(struct sql_stmt *stmt, struct port *port, struct region *region); + #if defined(__cplusplus) } /* extern "C" { */ #endif diff --git a/src/box/iproto.cc b/src/box/iproto.cc index 8f899fed8..9b59e1af0 100644 --- a/src/box/iproto.cc +++ b/src/box/iproto.cc @@ -1661,9 +1661,20 @@ tx_process_sql(struct cmsg *m) } sql = msg->sql.sql_text; sql = mp_decode_str(&sql, &len); - if (sql_prepare_and_execute(sql, len, bind, bind_count, &port, - &fiber()->gc) != 0) + /* Compile, bind and execute SQL statement. */ + struct sql_stmt *stmt; + if (sql_prepare(sql, len, &stmt, NULL) != 0) goto error; + assert(stmt != NULL); + port_sql_create(&port, stmt); + if (sql_bind(stmt, bind, bind_count) != 0) { + port_destroy(&port); + goto error; + } + if (sql_execute(stmt, &port, &fiber()->gc) != 0) { + port_destroy(&port); + goto error; + } /* * Take an obuf only after execute(). Else the buffer can * become out of date during yield. -- 2.15.1