From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: v.shpilevoy@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v1 1/2] sql: VARBINARY result for C functions
Date: Fri, 28 May 2021 14:41:25 +0300 [thread overview]
Message-ID: <c8e30d5d1bb383133de4442a545456bdce0bd231.1622201982.git.imeevma@gmail.com> (raw)
In-Reply-To: <cover.1622201982.git.imeevma@gmail.com>
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
next prev parent reply other threads:[~2021-05-28 11:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-28 11:41 [Tarantool-patches] [PATCH v1 0/2] sql: VARBINARY result for user-defined functions Mergen Imeev via Tarantool-patches
2021-05-28 11:41 ` Mergen Imeev via Tarantool-patches [this message]
2021-05-28 21:05 ` [Tarantool-patches] [PATCH v1 1/2] sql: VARBINARY result for C functions Vladislav Shpilevoy via Tarantool-patches
2021-05-31 10:18 ` Mergen Imeev via Tarantool-patches
2021-05-28 11:41 ` [Tarantool-patches] [PATCH v1 2/2] sql: VARBINARY result for LUA functions Mergen Imeev via Tarantool-patches
2021-06-01 21:44 ` [Tarantool-patches] [PATCH v1 0/2] sql: VARBINARY result for user-defined functions Vladislav Shpilevoy via Tarantool-patches
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=c8e30d5d1bb383133de4442a545456bdce0bd231.1622201982.git.imeevma@gmail.com \
--to=tarantool-patches@dev.tarantool.org \
--cc=imeevma@tarantool.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH v1 1/2] sql: VARBINARY result for C functions' \
/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