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 61C332CE3E for ; Mon, 19 Nov 2018 08:47:43 -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 TB3d1aGtEgzW for ; Mon, 19 Nov 2018 08:47:43 -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 A26AA2CC36 for ; Mon, 19 Nov 2018 08:47:42 -0500 (EST) From: Vladislav Shpilevoy Subject: [tarantool-patches] [PATCH 2/3] sql: SELECT from system spaces returns unpacked msgpack. Date: Mon, 19 Nov 2018 16:47:29 +0300 Message-Id: <9e22a12510a952d2378d8b926db266f4a426c332.1542635129.git.v.shpilevoy@tarantool.org> 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: korablev@tarantool.org, Mergen Imeev From: Mergen Imeev SELECT executed through net.box returns unpacked msgpask. Fixed in this patch. --- src/box/execute.c | 22 +++++++++++++++------- test/sql/iproto.result | 9 +++++++++ test/sql/iproto.test.lua | 4 ++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/box/execute.c b/src/box/execute.c index 5b747cf7f..2a0302703 100644 --- a/src/box/execute.c +++ b/src/box/execute.c @@ -351,13 +351,21 @@ sql_column_to_messagepack(struct sqlite3_stmt *stmt, int i, } case SQLITE_BLOB: { uint32_t len = sqlite3_column_bytes(stmt, i); - size = mp_sizeof_bin(len); - char *pos = (char *) region_alloc(region, size); - if (pos == NULL) - goto oom; - const char *s; - s = (const char *)sqlite3_column_blob(stmt, i); - mp_encode_bin(pos, s, len); + const char *s = + (const char *)sqlite3_column_blob(stmt, i); + if (sql_column_subtype(stmt, i) == SQL_SUBTYPE_MSGPACK) { + size = len; + char *pos = (char *)region_alloc(region, size); + if (pos == NULL) + goto oom; + memcpy(pos, s, len); + } else { + size = mp_sizeof_bin(len); + char *pos = (char *)region_alloc(region, size); + if (pos == NULL) + goto oom; + mp_encode_bin(pos, s, len); + } break; } case SQLITE_NULL: { diff --git a/test/sql/iproto.result b/test/sql/iproto.result index 31e5d2e75..b1313e10e 100644 --- a/test/sql/iproto.result +++ b/test/sql/iproto.result @@ -785,6 +785,15 @@ cn = remote.connect(box.cfg.listen) _ = cn:execute("EXPLAIN SELECT 1;") --- ... +-- SELECT from system spaces returns unpacked msgpack. +res = cn:execute('select "format" from "_space" limit 1;') +--- +... +res.rows +--- +- - [[{'name': 'space_id', 'type': 'unsigned'}, {'name': 'lsn', 'type': 'unsigned'}, + {'name': 'tuple', 'type': 'array'}]] +... cn:close() --- ... diff --git a/test/sql/iproto.test.lua b/test/sql/iproto.test.lua index a0f0f15ee..5c90cba52 100644 --- a/test/sql/iproto.test.lua +++ b/test/sql/iproto.test.lua @@ -257,6 +257,10 @@ cn = remote.connect(box.cfg.listen) -- Segmentation fault when EXPLAIN executed using net.box. _ = cn:execute("EXPLAIN SELECT 1;") +-- SELECT from system spaces returns unpacked msgpack. +res = cn:execute('select "format" from "_space" limit 1;') +res.rows + cn:close() box.schema.user.revoke('guest', 'read,write,execute', 'universe') -- 2.17.2 (Apple Git-113)