[Tarantool-patches] [PATCH v1 6/7] sql: disallow concatination for SCALAR

imeevma at tarantool.org imeevma at tarantool.org
Wed Aug 11 19:01:51 MSK 2021


Part of #6221
---
 src/box/sql/mem.c               |  6 ++++--
 test/sql-tap/metatypes.test.lua | 11 ++++++++++-
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index e34f24c96..732d1b012 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -1552,12 +1552,14 @@ mem_concat(struct Mem *a, struct Mem *b, struct Mem *result)
 		return 0;
 	}
 	/* Concatenation operation can be applied only to strings and blobs. */
-	if (((b->type & (MEM_TYPE_STR | MEM_TYPE_BIN)) == 0)) {
+	if (((b->type & (MEM_TYPE_STR | MEM_TYPE_BIN)) == 0) ||
+	    mem_is_metatype(b)) {
 		diag_set(ClientError, ER_INCONSISTENT_TYPES,
 			 "string or varbinary", mem_str(b));
 		return -1;
 	}
-	if (((a->type & (MEM_TYPE_STR | MEM_TYPE_BIN)) == 0)) {
+	if (((a->type & (MEM_TYPE_STR | MEM_TYPE_BIN)) == 0) ||
+	    mem_is_metatype(a)) {
 		diag_set(ClientError, ER_INCONSISTENT_TYPES,
 			 "string or varbinary", mem_str(a));
 		return -1;
diff --git a/test/sql-tap/metatypes.test.lua b/test/sql-tap/metatypes.test.lua
index 50d700cc4..b767e3f31 100755
--- a/test/sql-tap/metatypes.test.lua
+++ b/test/sql-tap/metatypes.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 local test = require("sqltester")
-test:plan(12)
+test:plan(13)
 
 -- Check that SCALAR and NUMBER meta-types works as intended.
 box.execute([[CREATE TABLE t (i INT PRIMARY KEY, s SCALAR, n NUMBER);]])
@@ -124,6 +124,15 @@ test:do_catchsql_test(
         1, "Type mismatch: can not convert scalar(1) to unsigned"
     })
 
+-- Check that concatination is prohibited for SCALAR values.
+test:do_catchsql_test(
+    "metatypes-5",
+    [[
+        SELECT CAST('asd' AS SCALAR) || 'dsa';
+    ]], {
+        1, "Inconsistent types: expected string or varbinary got scalar('asd')"
+    })
+
 box.execute([[DROP TABLE t;]])
 
 test:finish_test()
-- 
2.25.1



More information about the Tarantool-patches mailing list