Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: v.shpilevoy@tarantool.org, kostja@tarantool.org,
	alexander.turenko@tarantool.org,
	Nikita Pettik <korablev@tarantool.org>
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	[thread overview]
Message-ID: <cdd38a1c0a16afb255850a25a6fc301436f7f932.1566907520.git.korablev@tarantool.org> (raw)
In-Reply-To: <cover.1566907519.git.korablev@tarantool.org>
In-Reply-To: <cover.1566907519.git.korablev@tarantool.org>

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

  parent reply	other threads:[~2019-08-27 13:34 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-27 13:34 [tarantool-patches] [PATCH 0/8] rfc: introduce dry-run execution of SQL queries Nikita Pettik
2019-08-27 13:34 ` [tarantool-patches] [PATCH 1/8] port: increase padding of struct port Nikita Pettik
2019-08-28  9:33   ` [tarantool-patches] " Konstantin Osipov
2019-08-29 20:46   ` Vladislav Shpilevoy
2019-08-27 13:34 ` [tarantool-patches] [PATCH 2/8] port: move struct port_sql to box/port.h Nikita Pettik
2019-08-28  9:33   ` [tarantool-patches] " Konstantin Osipov
2019-08-29 20:46   ` Vladislav Shpilevoy
2019-08-27 13:34 ` [tarantool-patches] [PATCH 3/8] sql: remove sql_prepare_v2() Nikita Pettik
2019-08-28  9:33   ` [tarantool-patches] " Konstantin Osipov
2019-08-29 20:46   ` Vladislav Shpilevoy
2019-08-27 13:34 ` [tarantool-patches] [PATCH 4/8] sql: refactor sql_prepare() and sqlPrepare() Nikita Pettik
2019-08-28  9:35   ` [tarantool-patches] " Konstantin Osipov
2019-08-29 20:46   ` Vladislav Shpilevoy
2019-08-27 13:34 ` [tarantool-patches] [PATCH 5/8] sql: move sql_prepare() declaration to box/execute.h Nikita Pettik
2019-08-28  9:35   ` [tarantool-patches] " Konstantin Osipov
2019-08-27 13:34 ` Nikita Pettik [this message]
2019-08-28  9:37   ` [tarantool-patches] Re: [PATCH 6/8] refactoring: use sql_prepare() and sql_execute() in tx_process_sql() Konstantin Osipov
2019-08-29 20:46   ` Vladislav Shpilevoy
2019-08-27 13:34 ` [tarantool-patches] [PATCH 7/8] netbox: allow passing options to :execute() Nikita Pettik
2019-08-28  9:38   ` [tarantool-patches] " Konstantin Osipov
2019-08-29 20:46   ` Vladislav Shpilevoy
2019-08-27 13:34 ` [tarantool-patches] [PATCH 8/8] sql: introduce dry-run execution Nikita Pettik
2019-08-28  9:39   ` [tarantool-patches] " Konstantin Osipov
2019-08-29 20:46   ` Vladislav Shpilevoy
2019-08-28  9:31 ` [tarantool-patches] Re: [PATCH 0/8] rfc: introduce dry-run execution of SQL queries Konstantin Osipov
2019-08-29 20:46 ` 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=cdd38a1c0a16afb255850a25a6fc301436f7f932.1566907520.git.korablev@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH 6/8] refactoring: use sql_prepare() and sql_execute() in tx_process_sql()' \
    /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