From: imeevma@tarantool.org To: tarantool-patches@freelists.org, v.shpilevoy@tarantool.org Subject: [tarantool-patches] [PATCH v8 2/6] iproto: move map creation to sql_response_dump() Date: Sat, 19 Jan 2019 16:20:21 +0300 [thread overview] Message-ID: <4a5099086f22bb42002678d434d6a4c65fb51547.1547902954.git.imeevma@gmail.com> (raw) In-Reply-To: <cover.1547902954.git.imeevma@gmail.com> Currently, function sql_response_dump() puts data into an already created map. Moving the map creation to sql_response_dump() simplifies the code and allows us to use sql_response_dump() as one of the port_sql methods. Needed for #3505 --- src/box/execute.c | 23 ++++++++++++++++------- src/box/execute.h | 3 +-- src/box/iproto.cc | 8 +++----- src/box/xrow.c | 8 +------- src/box/xrow.h | 9 +-------- 5 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/box/execute.c b/src/box/execute.c index 7fff5fd..38b6cbc 100644 --- a/src/box/execute.c +++ b/src/box/execute.c @@ -555,22 +555,29 @@ sql_prepare_and_execute(const char *sql, int len, const struct sql_bind *bind, } int -sql_response_dump(struct sql_response *response, int *keys, struct obuf *out) +sql_response_dump(struct sql_response *response, struct obuf *out) { sqlite3 *db = sql_get(); struct sqlite3_stmt *stmt = (struct sqlite3_stmt *) response->prep_stmt; struct port_tuple *port_tuple = (struct port_tuple *) &response->port; int rc = 0, column_count = sqlite3_column_count(stmt); if (column_count > 0) { + int keys = 2; + int size = mp_sizeof_map(keys); + char *pos = (char *) obuf_alloc(out, size); + if (pos == NULL) { + diag_set(OutOfMemory, size, "obuf_alloc", "pos"); + goto err; + } + pos = mp_encode_map(pos, keys); if (sql_get_description(stmt, out, column_count) != 0) { err: rc = -1; goto finish; } - *keys = 2; - int size = mp_sizeof_uint(IPROTO_DATA) + - mp_sizeof_array(port_tuple->size); - char *pos = (char *) obuf_alloc(out, size); + size = mp_sizeof_uint(IPROTO_DATA) + + mp_sizeof_array(port_tuple->size); + pos = (char *) obuf_alloc(out, size); if (pos == NULL) { diag_set(OutOfMemory, size, "obuf_alloc", "pos"); goto err; @@ -586,18 +593,20 @@ err: goto err; } } else { - *keys = 1; + int keys = 1; assert(port_tuple->size == 0); struct stailq *autoinc_id_list = vdbe_autoinc_id_list((struct Vdbe *)stmt); uint32_t map_size = stailq_empty(autoinc_id_list) ? 1 : 2; - int size = mp_sizeof_uint(IPROTO_SQL_INFO) + + int size = mp_sizeof_map(keys) + + mp_sizeof_uint(IPROTO_SQL_INFO) + mp_sizeof_map(map_size); char *pos = (char *) obuf_alloc(out, size); if (pos == NULL) { diag_set(OutOfMemory, size, "obuf_alloc", "pos"); goto err; } + pos = mp_encode_map(pos, keys); pos = mp_encode_uint(pos, IPROTO_SQL_INFO); pos = mp_encode_map(pos, map_size); uint64_t id_count = 0; diff --git a/src/box/execute.h b/src/box/execute.h index 9c1bc4f..60b8f31 100644 --- a/src/box/execute.h +++ b/src/box/execute.h @@ -105,14 +105,13 @@ sql_bind_list_decode(const char *data, struct sql_bind **out_bind); * | } | * +----------------------------------------------+ * @param response EXECUTE response. - * @param[out] keys number of keys in dumped map. * @param out Output buffer. * * @retval 0 Success. * @retval -1 Memory error. */ int -sql_response_dump(struct sql_response *response, int *keys, struct obuf *out); +sql_response_dump(struct sql_response *response, struct obuf *out); /** * Prepare and execute an SQL statement. diff --git a/src/box/iproto.cc b/src/box/iproto.cc index 1debc3c..a08c8c5 100644 --- a/src/box/iproto.cc +++ b/src/box/iproto.cc @@ -1641,17 +1641,15 @@ tx_process_sql(struct cmsg *m) * become out of date during yield. */ out = msg->connection->tx.p_obuf; - int keys; struct obuf_svp header_svp; /* Prepare memory for the iproto header. */ - if (iproto_prepare_header(out, &header_svp, IPROTO_SQL_HEADER_LEN) != 0) + if (iproto_prepare_header(out, &header_svp, IPROTO_HEADER_LEN) != 0) goto error; - if (sql_response_dump(&response, &keys, out) != 0) { + if (sql_response_dump(&response, out) != 0) { obuf_rollback_to_svp(out, &header_svp); goto error; } - iproto_reply_sql(out, &header_svp, msg->header.sync, schema_version, - keys); + iproto_reply_sql(out, &header_svp, msg->header.sync, schema_version); iproto_wpos_create(&msg->wpos, out); return; error: diff --git a/src/box/xrow.c b/src/box/xrow.c index 67019a6..c4e3073 100644 --- a/src/box/xrow.c +++ b/src/box/xrow.c @@ -508,17 +508,11 @@ error: void iproto_reply_sql(struct obuf *buf, struct obuf_svp *svp, uint64_t sync, - uint32_t schema_version, int keys) + uint32_t schema_version) { char *pos = (char *) obuf_svp_to_ptr(buf, svp); iproto_header_encode(pos, IPROTO_OK, sync, schema_version, obuf_size(buf) - svp->used - IPROTO_HEADER_LEN); - /* - * MessagePack encodes value <= 15 as - * bitwise OR with 0x80. - */ - assert(keys <= 15); - *(pos + IPROTO_HEADER_LEN) = 0x80 | keys; } void diff --git a/src/box/xrow.h b/src/box/xrow.h index 6bab0a1..2654e35 100644 --- a/src/box/xrow.h +++ b/src/box/xrow.h @@ -52,12 +52,6 @@ enum { IPROTO_HEADER_LEN = 28, /** 7 = sizeof(iproto_body_bin). */ IPROTO_SELECT_HEADER_LEN = IPROTO_HEADER_LEN + 7, - /** - * Header of message + header of body with one or two - * keys: IPROTO_DATA and IPROTO_METADATA or - * IPROTO_SQL_INFO. 1 == mp_sizeof_map(<=15). - */ - IPROTO_SQL_HEADER_LEN = IPROTO_HEADER_LEN + 1, }; struct xrow_header { @@ -491,11 +485,10 @@ xrow_decode_sql(const struct xrow_header *row, struct sql_request *request); * @param svp Savepoint of the header beginning. * @param sync Request sync. * @param schema_version Schema version. - * @param keys Count of keys in the body. */ void iproto_reply_sql(struct obuf *buf, struct obuf_svp *svp, uint64_t sync, - uint32_t schema_version, int keys); + uint32_t schema_version); /** * Write an IPROTO_CHUNK header from a specified position in a -- 2.7.4
next prev parent reply other threads:[~2019-01-19 13:21 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-01-19 13:20 [tarantool-patches] [PATCH v8 0/6] sql: remove box.sql.execute imeevma 2019-01-19 13:20 ` [tarantool-patches] [PATCH v8 1/6] lua: remove exceptions from function luaL_tofield() imeevma 2019-01-22 19:58 ` [tarantool-patches] " Vladislav Shpilevoy 2019-01-24 7:27 ` Imeev Mergen 2019-01-29 20:42 ` Vladislav Shpilevoy 2019-01-19 13:20 ` imeevma [this message] 2019-01-25 16:07 ` [tarantool-patches] Re: [PATCH v8 2/6] iproto: move map creation to sql_response_dump() Konstantin Osipov 2019-01-29 20:42 ` Vladislav Shpilevoy 2019-01-19 13:20 ` [tarantool-patches] [PATCH v8 3/6] iproto: create port_sql imeevma 2019-01-19 13:20 ` [tarantool-patches] [PATCH v8 4/6] lua: create method dump_lua for port_sql imeevma 2019-01-29 20:42 ` [tarantool-patches] " Vladislav Shpilevoy 2019-01-19 13:20 ` [tarantool-patches] [PATCH v8 5/6] lua: parameter binding for new execute() imeevma 2019-01-19 13:20 ` [tarantool-patches] [PATCH v8 6/6] sql: check new box.sql.execute() imeevma 2019-01-22 19:58 ` [tarantool-patches] Re: [PATCH v8 0/6] sql: remove box.sql.execute Vladislav Shpilevoy 2019-01-24 7:31 ` Imeev Mergen
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=4a5099086f22bb42002678d434d6a4c65fb51547.1547902954.git.imeevma@gmail.com \ --to=imeevma@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [tarantool-patches] [PATCH v8 2/6] iproto: move map creation to sql_response_dump()' \ /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