From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: vdavydov.dev@gmail.com
Subject: [PATCH 4/4] sql: move sql_request and xrow_decode_sql to xrow lib
Date: Tue, 11 Dec 2018 00:40:41 +0300 [thread overview]
Message-ID: <eae9d30e68747e0b65d4d11500b33e95440de261.1544477760.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1544477760.git.v.shpilevoy@tarantool.org>
In-Reply-To: <cover.1544477760.git.v.shpilevoy@tarantool.org>
All binary struct *_request are stored in xrow.h/.c
together with their decoders. The only reason why
xrow_decode_sql was implemented in execute.c was a
dependency on struct sql_bind. Now xrow_decode_sql
and struct sql_request operate only by MessagePack and
some iproto constants and are moved to their true
home.
Follow up #3828
---
src/box/execute.c | 46 ----------------------------------------------
src/box/execute.h | 20 --------------------
src/box/xrow.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
src/box/xrow.h | 19 +++++++++++++++++++
4 files changed, 65 insertions(+), 66 deletions(-)
diff --git a/src/box/execute.c b/src/box/execute.c
index 25a594d7d..7fff5fdff 100644
--- a/src/box/execute.c
+++ b/src/box/execute.c
@@ -228,52 +228,6 @@ sql_bind_list_decode(const char *data, struct sql_bind **out_bind)
return bind_count;
}
-int
-xrow_decode_sql(const struct xrow_header *row, struct sql_request *request)
-{
- if (row->bodycnt == 0) {
- diag_set(ClientError, ER_INVALID_MSGPACK, "missing request body");
- return 1;
- }
- assert(row->bodycnt == 1);
- const char *data = (const char *) row->body[0].iov_base;
- const char *end = data + row->body[0].iov_len;
- assert((end - data) > 0);
-
- if (mp_typeof(*data) != MP_MAP || mp_check_map(data, end) > 0) {
-error:
- diag_set(ClientError, ER_INVALID_MSGPACK, "packet body");
- return -1;
- }
-
- uint32_t map_size = mp_decode_map(&data);
- request->sql_text = NULL;
- request->bind = NULL;
- for (uint32_t i = 0; i < map_size; ++i) {
- uint8_t key = *data;
- if (key != IPROTO_SQL_BIND && key != IPROTO_SQL_TEXT) {
- mp_check(&data, end); /* skip the key */
- mp_check(&data, end); /* skip the value */
- continue;
- }
- const char *value = ++data; /* skip the key */
- if (mp_check(&data, end) != 0) /* check the value */
- goto error;
- if (key == IPROTO_SQL_BIND)
- request->bind = value;
- else
- request->sql_text = value;
- }
- if (request->sql_text == NULL) {
- diag_set(ClientError, ER_MISSING_REQUEST_FIELD,
- iproto_key_name(IPROTO_SQL_TEXT));
- return -1;
- }
- if (data != end)
- goto error;
- return 0;
-}
-
/**
* Serialize a single column of a result set row.
* @param stmt Prepared and started statement. At least one
diff --git a/src/box/execute.h b/src/box/execute.h
index 025695ea9..9c1bc4f05 100644
--- a/src/box/execute.h
+++ b/src/box/execute.h
@@ -51,15 +51,6 @@ extern const char *sql_info_key_strs[];
struct obuf;
struct region;
struct sql_bind;
-struct xrow_header;
-
-/** EXECUTE request. */
-struct sql_request {
- /** SQL statement text. */
- const char *sql_text;
- /** MessagePack array of parameters. */
- const char *bind;
-};
/** Response on EXECUTE request. */
struct sql_response {
@@ -123,17 +114,6 @@ sql_bind_list_decode(const char *data, struct sql_bind **out_bind);
int
sql_response_dump(struct sql_response *response, int *keys, struct obuf *out);
-/**
- * Parse the EXECUTE request.
- * @param row Encoded data.
- * @param[out] request Request to decode to.
- *
- * @retval 0 Sucess.
- * @retval -1 Format or memory error.
- */
-int
-xrow_decode_sql(const struct xrow_header *row, struct sql_request *request);
-
/**
* Prepare and execute an SQL statement.
* @param sql SQL statement.
diff --git a/src/box/xrow.c b/src/box/xrow.c
index 76c6f8166..67019a68d 100644
--- a/src/box/xrow.c
+++ b/src/box/xrow.c
@@ -460,6 +460,52 @@ iproto_reply_select(struct obuf *buf, struct obuf_svp *svp, uint64_t sync,
memcpy(pos + IPROTO_HEADER_LEN, &body, sizeof(body));
}
+int
+xrow_decode_sql(const struct xrow_header *row, struct sql_request *request)
+{
+ if (row->bodycnt == 0) {
+ diag_set(ClientError, ER_INVALID_MSGPACK, "missing request body");
+ return 1;
+ }
+ assert(row->bodycnt == 1);
+ const char *data = (const char *) row->body[0].iov_base;
+ const char *end = data + row->body[0].iov_len;
+ assert((end - data) > 0);
+
+ if (mp_typeof(*data) != MP_MAP || mp_check_map(data, end) > 0) {
+error:
+ diag_set(ClientError, ER_INVALID_MSGPACK, "packet body");
+ return -1;
+ }
+
+ uint32_t map_size = mp_decode_map(&data);
+ request->sql_text = NULL;
+ request->bind = NULL;
+ for (uint32_t i = 0; i < map_size; ++i) {
+ uint8_t key = *data;
+ if (key != IPROTO_SQL_BIND && key != IPROTO_SQL_TEXT) {
+ mp_check(&data, end); /* skip the key */
+ mp_check(&data, end); /* skip the value */
+ continue;
+ }
+ const char *value = ++data; /* skip the key */
+ if (mp_check(&data, end) != 0) /* check the value */
+ goto error;
+ if (key == IPROTO_SQL_BIND)
+ request->bind = value;
+ else
+ request->sql_text = value;
+ }
+ if (request->sql_text == NULL) {
+ diag_set(ClientError, ER_MISSING_REQUEST_FIELD,
+ iproto_key_name(IPROTO_SQL_TEXT));
+ return -1;
+ }
+ if (data != end)
+ goto error;
+ return 0;
+}
+
void
iproto_reply_sql(struct obuf *buf, struct obuf_svp *svp, uint64_t sync,
uint32_t schema_version, int keys)
diff --git a/src/box/xrow.h b/src/box/xrow.h
index ca8d04d44..6bab0a1fd 100644
--- a/src/box/xrow.h
+++ b/src/box/xrow.h
@@ -466,6 +466,25 @@ int
iproto_reply_error(struct obuf *out, const struct error *e, uint64_t sync,
uint32_t schema_version);
+/** EXECUTE request. */
+struct sql_request {
+ /** SQL statement text. */
+ const char *sql_text;
+ /** MessagePack array of parameters. */
+ const char *bind;
+};
+
+/**
+ * Parse the EXECUTE request.
+ * @param row Encoded data.
+ * @param[out] request Request to decode to.
+ *
+ * @retval 0 Sucess.
+ * @retval -1 Format or memory error.
+ */
+int
+xrow_decode_sql(const struct xrow_header *row, struct sql_request *request);
+
/**
* Write the SQL header.
* @param buf Out buffer.
--
2.17.2 (Apple Git-113)
next prev parent reply other threads:[~2018-12-10 21:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-10 21:40 [PATCH 0/4] Fix sql_bind leak Vladislav Shpilevoy
2018-12-10 21:40 ` [PATCH 1/4] sql: remove sync from sql_request/response Vladislav Shpilevoy
2018-12-10 21:40 ` [PATCH 2/4] Revert "box: store sql text and length in sql_request" Vladislav Shpilevoy
2018-12-10 21:40 ` [PATCH 3/4] sql: decode bind parameters in TX thread Vladislav Shpilevoy
2018-12-10 21:40 ` Vladislav Shpilevoy [this message]
2018-12-18 12:02 ` [PATCH 0/4] Fix sql_bind leak Vladimir Davydov
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=eae9d30e68747e0b65d4d11500b33e95440de261.1544477760.git.v.shpilevoy@tarantool.org \
--to=v.shpilevoy@tarantool.org \
--cc=tarantool-patches@freelists.org \
--cc=vdavydov.dev@gmail.com \
--subject='Re: [PATCH 4/4] sql: move sql_request and xrow_decode_sql to xrow lib' \
/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