Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: v.shpilevoy@tarantool.org, Nikita Pettik <korablev@tarantool.org>
Subject: [tarantool-patches] [PATCH 3/3] sql: fix resulting type for concatenation operator
Date: Tue, 19 Feb 2019 11:28:23 +0300	[thread overview]
Message-ID: <8ed63c91ff43fed8288d6116c5312918e96cf5e1.1550532805.git.korablev@tarantool.org> (raw)
In-Reply-To: <cover.1550532805.git.korablev@tarantool.org>
In-Reply-To: <cover.1550532805.git.korablev@tarantool.org>

Before this patch, resulting type of concatenation operator always was
TEXT (i.e. type of memory cell containing result - MEM_Str). Lets fix it
and return type depending on type of concatenation arguments: if both
arguments are TEXT, then resulting type is TEXT; BLOB otherwise. Note
that other options of combining types of arguments are illegal.

Closes #3544
---
 src/box/sql/vdbe.c      |  5 ++++-
 test/sql/types.result   | 10 ++++++++++
 test/sql/types.test.lua |  4 ++++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 37955858d..b647491bb 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -1587,7 +1587,10 @@ case OP_Concat: {           /* same as TK_CONCAT, in1, in2, out3 */
 	if (sqlVdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2)) {
 		goto no_mem;
 	}
-	MemSetTypeFlag(pOut, MEM_Str);
+	if (pIn1->flags & MEM_Str)
+		MemSetTypeFlag(pOut, MEM_Str);
+	else
+		MemSetTypeFlag(pOut, MEM_Blob);
 	if (pOut!=pIn2) {
 		memcpy(pOut->z, pIn2->z, pIn2->n);
 	}
diff --git a/test/sql/types.result b/test/sql/types.result
index 0cbbd1642..a0159d661 100644
--- a/test/sql/types.result
+++ b/test/sql/types.result
@@ -163,3 +163,13 @@ box.sql.execute("SELECT CAST('abc' AS BLOB) || 'x';")
 ---
 - error: 'Inconsistent types: expected BLOB got TEXT'
 ...
+-- Result of BLOBs concatenation must be BLOB.
+--
+box.sql.execute("SELECT TYPEOF(CAST('abc' AS BLOB) || CAST('cda' AS BLOB))")
+---
+- - ['blob']
+...
+box.sql.execute("VALUES (TYPEOF(randomblob(5) || zeroblob(5)));")
+---
+- - ['blob']
+...
diff --git a/test/sql/types.test.lua b/test/sql/types.test.lua
index e0331bb8f..b944b081b 100644
--- a/test/sql/types.test.lua
+++ b/test/sql/types.test.lua
@@ -52,3 +52,7 @@ box.sql.execute("SELECt 'a' || 'b' || 1;")
 --
 box.sql.execute("SELECT 'abc' || CAST('x' AS BLOB);")
 box.sql.execute("SELECT CAST('abc' AS BLOB) || 'x';")
+-- Result of BLOBs concatenation must be BLOB.
+--
+box.sql.execute("SELECT TYPEOF(CAST('abc' AS BLOB) || CAST('cda' AS BLOB))")
+box.sql.execute("VALUES (TYPEOF(randomblob(5) || zeroblob(5)));")
-- 
2.15.1

  parent reply	other threads:[~2019-02-19  8:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-19  8:28 [tarantool-patches] [PATCH 0/3] Concatenation operator type fixes Nikita Pettik
2019-02-19  8:28 ` [tarantool-patches] [PATCH 1/3] sql: fix value of mask to map VDBE memory type Nikita Pettik
2019-02-19  8:28 ` [tarantool-patches] [PATCH 2/3] sql: allow only string-like arguments for concatenation Nikita Pettik
2019-02-19  8:28 ` Nikita Pettik [this message]
2019-02-22 15:54 ` [tarantool-patches] Re: [PATCH 0/3] Concatenation operator type fixes Vladislav Shpilevoy
2019-02-25 11:42 ` Kirill Yukhin

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=8ed63c91ff43fed8288d6116c5312918e96cf5e1.1550532805.git.korablev@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH 3/3] sql: fix resulting type for concatenation operator' \
    /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