From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 6C82F6EC58; Fri, 28 May 2021 14:41:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6C82F6EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1622202116; bh=tQjFWtqe0NWLNHobYzJXpKUPoPd9x/HiU/rtUjToK7M=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=KV1NcsPPGrrnYBVK0OV76pIjHaURKeF651cKuCAp9BM+Mp7fjVFBJwrugnL1IL1Pb QHQoY+ruQ4FEaV5jiyVUo6w+1UUYauzgqL7Mo2cRl58fjuV9XCb5Lx3N5YS3+eznIs 0JXo6fPyZFmti8A62E6lH6wXv8iYslp1WLdqdeVU= Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 9D0B86EC58 for ; Fri, 28 May 2021 14:41:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9D0B86EC58 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1lmarm-00033C-2Y; Fri, 28 May 2021 14:41:26 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 28 May 2021 14:41:25 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9157EECD0FDB90B9AD9819BC4F6F88210EBA761B64B871D0000894C459B0CD1B9AEEF6060904605ED31E44A099A5B345D3966DC9522174D5804D8E79596628258 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE769420192704DB0E7EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637B28E90C11C329EF18638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D880CF95C38B8398F43C0FC0BBA5D61A94117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B62CFFCC7B69C47339089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C7E9571940300E71A520FF14F47EE41957B1388B6261046879C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFB4CA5BC574AE2910699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34AC223B6CC5B2DFAC1734C44BA06DF238F030138BF9FA9DF095B5FF0EDAB900CB56FCC757F59ACC9C1D7E09C32AA3244C4A985010A75FF0571B6B9EF2A36031609CA7333006C390A0729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojrzEAfVgW/77wB0iPEPVf7A== X-Mailru-Sender: 689FA8AB762F73936BC43F508A06382290379E5A2AFBDE5B21868145B150369783D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 1/2] sql: VARBINARY result for C functions X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This patch allows VARBINARY to be returned for user-defined C functions. There is currently no support for UUID and DECIMAL in SQL, so they are also treated as VARBINARY. Part of #6024 --- src/box/sql/mem.c | 11 ++++ test/sql-tap/CMakeLists.txt | 1 + test/sql-tap/gh-6024-funcs-return-bin.c | 46 ++++++++++++++++ .../sql-tap/gh-6024-funcs-return-bin.test.lua | 53 +++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 test/sql-tap/gh-6024-funcs-return-bin.c create mode 100755 test/sql-tap/gh-6024-funcs-return-bin.test.lua diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 03fbffc7f..f81f78e27 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -3047,6 +3047,17 @@ port_c_get_vdbemem(struct port *base, uint32_t *size) if (mem_copy_str(&val[i], str, len) != 0) goto error; break; + case MP_BIN: + str = mp_decode_bin(&data, &len); + if (mem_copy_bin(&val[i], str, len) != 0) + goto error; + break; + case MP_EXT: + str = data; + mp_next(&data); + if (mem_copy_bin(&val[i], str, data - str) != 0) + goto error; + break; case MP_NIL: break; default: diff --git a/test/sql-tap/CMakeLists.txt b/test/sql-tap/CMakeLists.txt index 6e2eae2ff..bf0c3a11d 100644 --- a/test/sql-tap/CMakeLists.txt +++ b/test/sql-tap/CMakeLists.txt @@ -1,2 +1,3 @@ include_directories(${MSGPUCK_INCLUDE_DIRS}) build_module(gh-5938-wrong-string-length gh-5938-wrong-string-length.c) +build_module(gh-6024-funcs-return-bin gh-6024-funcs-return-bin.c) diff --git a/test/sql-tap/gh-6024-funcs-return-bin.c b/test/sql-tap/gh-6024-funcs-return-bin.c new file mode 100644 index 000000000..ed9070006 --- /dev/null +++ b/test/sql-tap/gh-6024-funcs-return-bin.c @@ -0,0 +1,46 @@ +#include "msgpuck.h" +#include "module.h" +#include "uuid/mp_uuid.h" +#include "mp_decimal.h" + +enum { + BUF_SIZE = 512, +}; + +int +ret_bin(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + (void)args; + (void)args_end; + const char bin[] = "some varbinary string"; + char res[BUF_SIZE]; + char *end = mp_encode_bin(res, bin, sizeof(bin)); + box_return_mp(ctx, res, end); + return 0; +} + +int +ret_uuid(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + (void)args; + (void)args_end; + struct tt_uuid uuid; + memset(&uuid, 0x11, sizeof(uuid)); + char res[BUF_SIZE]; + char *end = mp_encode_uuid(res, &uuid); + box_return_mp(ctx, res, end); + return 0; +} + +int +ret_decimal(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + (void)args; + (void)args_end; + decimal_t dec; + decimal_from_string(&dec, "9999999999999999999.9999999999999999999"); + char res[BUF_SIZE]; + char *end = mp_encode_decimal(res, &dec); + box_return_mp(ctx, res, end); + return 0; +} diff --git a/test/sql-tap/gh-6024-funcs-return-bin.test.lua b/test/sql-tap/gh-6024-funcs-return-bin.test.lua new file mode 100755 index 000000000..90d09b497 --- /dev/null +++ b/test/sql-tap/gh-6024-funcs-return-bin.test.lua @@ -0,0 +1,53 @@ +#!/usr/bin/env tarantool +local build_path = os.getenv("BUILDDIR") +package.cpath = build_path..'/test/sql-tap/?.so;'..build_path..'/test/sql-tap/?.dylib;'..package.cpath + +local test = require("sqltester") +test:plan(3) + +box.schema.func.create("gh-6024-funcs-return-bin.ret_bin", { + language = "C", + param_list = {}, + returns = "varbinary", + exports = {"SQL"}, +}) + +test:do_execsql_test( + "gh-6024-1", + [[ + SELECT typeof("gh-6024-funcs-return-bin.ret_bin"()); + ]], { + "varbinary" + }) + +box.schema.func.create("gh-6024-funcs-return-bin.ret_uuid", { + language = "C", + param_list = {}, + returns = "varbinary", + exports = {"SQL"}, +}) + +test:do_execsql_test( + "gh-6024-2", + [[ + SELECT typeof("gh-6024-funcs-return-bin.ret_uuid"()); + ]], { + "varbinary" + }) + +box.schema.func.create("gh-6024-funcs-return-bin.ret_decimal", { + language = "C", + param_list = {}, + returns = "varbinary", + exports = {"SQL"}, +}) + +test:do_execsql_test( + "gh-6024-3", + [[ + SELECT typeof("gh-6024-funcs-return-bin.ret_decimal"()); + ]], { + "varbinary" + }) + +test:finish_test() -- 2.25.1