[tarantool-patches] [PATCH 2/2] sql: fix the bug with wrong result type in <CAST>

Roman Khabibov roman.habibov at tarantool.org
Sun Sep 15 22:39:11 MSK 2019


Before this patch, in some cases of casting from blob to number
result was mistakenly interpreted as a string. This is the cases
when sqlAtoF() was used.

Part of #4356
---
 src/box/sql/vdbemem.c      |  5 ++++-
 test/sql-tap/cast.test.lua | 14 ++++++++++++--
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index ac0dfa333..8707e31fa 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -660,7 +660,10 @@ sqlVdbeMemCast(Mem * pMem, enum field_type type)
 				pMem->u.r = pMem->u.u;
 			return 0;
 		}
-		return ! sqlAtoF(pMem->z, &pMem->u.r, pMem->n);
+		int rc = ! sqlAtoF(pMem->z, &pMem->u.r, pMem->n);
+		if (rc == 0)
+			MemSetTypeFlag(pMem, MEM_Real);
+		return rc;
 	}
 	switch (type) {
 	case FIELD_TYPE_SCALAR:
diff --git a/test/sql-tap/cast.test.lua b/test/sql-tap/cast.test.lua
index 1eba15b38..092d9fb21 100755
--- a/test/sql-tap/cast.test.lua
+++ b/test/sql-tap/cast.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(84)
+test:plan(85)
 
 --!./tcltestrunner.lua
 -- 2005 June 25
@@ -891,6 +891,16 @@ test:do_test(
         -- </cast-4.4>
     })
 
-
+-- gh-4356 Check that result is NUMBER, when convert from blob to
+-- number.
+test:do_execsql_test(
+    "cast-5.1",
+    [[
+        SELECT CAST(x'3138343436373434303733372e33' AS NUMBER)
+    ]], {
+        -- <cast-5.1>
+        184467440737.3
+        -- </cast-5.1>
+    })
 
 test:finish_test()
-- 
2.20.1 (Apple Git-117)





More information about the Tarantool-patches mailing list