[tarantool-patches] [PATCH] sql: make RANDOMBLOB(0) return NULL, fix rounding

Kirill Yukhin kyukhin at tarantool.org
Fri Jun 29 14:43:25 MSK 2018


Make RANDOMBLOB(0) return NULL, it was returning random
blob of length 1 before. Allow rounding to more than 30
digits.

Part of #2347
---
Issue: https://github.com/tarantool/tarantool/issues/2347
Branch: https://github.com/tarantool/tarantool/commits/kyukhin/gh-2347-randomblob-round

 src/box/sql/func.c         |  7 ++-----
 test/sql-tap/func.test.lua | 24 ++++++++++++++++++++++--
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 097778a..e211de1 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -422,8 +422,6 @@ roundFunc(sqlite3_context * context, int argc, sqlite3_value ** argv)
 		if (SQLITE_NULL == sqlite3_value_type(argv[1]))
 			return;
 		n = sqlite3_value_int(argv[1]);
-		if (n > 30)
-			n = 30;
 		if (n < 0)
 			n = 0;
 	}
@@ -568,9 +566,8 @@ randomBlob(sqlite3_context * context, int argc, sqlite3_value ** argv)
 	assert(argc == 1);
 	UNUSED_PARAMETER(argc);
 	n = sqlite3_value_int(argv[0]);
-	if (n < 1) {
-		n = 1;
-	}
+	if (n < 1)
+		return;
 	p = contextMalloc(context, n);
 	if (p) {
 		sqlite3_randomness(n, p);
diff --git a/test/sql-tap/func.test.lua b/test/sql-tap/func.test.lua
index 03d033d..531ce39 100755
--- a/test/sql-tap/func.test.lua
+++ b/test/sql-tap/func.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(14534)
+test:plan(14538)
 
 --!./tcltestrunner.lua
 -- 2001 September 15
@@ -989,7 +989,7 @@ test:do_execsql_test(
                length(randomblob(2000))
     ]], {
         -- <func-9.5>
-        32, 1, 2000
+        32, "", 2000
         -- </func-9.5>
     })
 
@@ -2646,4 +2646,24 @@ test:do_execsql_test(
     [[SELECT version()]],
     {_TARANTOOL})
 
+test:do_execsql_test(
+    "func-33",
+    [[VALUES (ROUND(1e-31,30))]],
+    {0})
+
+test:do_execsql_test(
+    "func-34",
+    [[VALUES (ROUND(1e-31,31))]],
+    {1e-31})
+
+test:do_execsql_test(
+    "func-35",
+    [[VALUES (ROUND(1e-31, 100))]],
+    {1e-31})
+
+test:do_execsql_test(
+    "func-36",
+    [[VALUES (LENGTH(RANDOMBLOB(0)))]],
+    {""})
+
 test:finish_test()
-- 
2.16.2





More information about the Tarantool-patches mailing list