Skip to content

Commit

Permalink
sql: fix resulting type for concatenation operator
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Korablev77 authored and kyukhin committed Feb 25, 2019
1 parent d8cfb80 commit 7464491
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/box/sql/vdbe.c
Expand Up @@ -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);
}
Expand Down
10 changes: 10 additions & 0 deletions test/sql/types.result
Expand Up @@ -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']
...
4 changes: 4 additions & 0 deletions test/sql/types.test.lua
Expand Up @@ -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)));")

0 comments on commit 7464491

Please sign in to comment.