Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH] sql: make RANDOMBLOB(0) return NULL, fix rounding
@ 2018-06-29 11:43 Kirill Yukhin
  2018-06-29 13:04 ` [tarantool-patches] " n.pettik
  0 siblings, 1 reply; 3+ messages in thread
From: Kirill Yukhin @ 2018-06-29 11:43 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches, Kirill Yukhin

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tarantool-patches] Re: [PATCH] sql: make RANDOMBLOB(0) return NULL, fix rounding
  2018-06-29 11:43 [tarantool-patches] [PATCH] sql: make RANDOMBLOB(0) return NULL, fix rounding Kirill Yukhin
@ 2018-06-29 13:04 ` n.pettik
  2018-06-29 13:39   ` Kirill Yukhin
  0 siblings, 1 reply; 3+ messages in thread
From: n.pettik @ 2018-06-29 13:04 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Kirill Yukhin

LGTM.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tarantool-patches] Re: [PATCH] sql: make RANDOMBLOB(0) return NULL, fix rounding
  2018-06-29 13:04 ` [tarantool-patches] " n.pettik
@ 2018-06-29 13:39   ` Kirill Yukhin
  0 siblings, 0 replies; 3+ messages in thread
From: Kirill Yukhin @ 2018-06-29 13:39 UTC (permalink / raw)
  To: n.pettik; +Cc: tarantool-patches

On 29 июн 16:04, n.pettik wrote:
> LGTM.
Thanks, checked into 2.0 branch.

--
Regards, Kirill Yukhin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-06-29 13:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-29 11:43 [tarantool-patches] [PATCH] sql: make RANDOMBLOB(0) return NULL, fix rounding Kirill Yukhin
2018-06-29 13:04 ` [tarantool-patches] " n.pettik
2018-06-29 13:39   ` Kirill Yukhin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox