Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Yukhin <kyukhin@tarantool.org>
To: korablev@tarantool.org
Cc: tarantool-patches@freelists.org, Kirill Yukhin <kyukhin@tarantool.org>
Subject: [tarantool-patches] [PATCH] sql: make RANDOMBLOB(0) return NULL, fix rounding
Date: Fri, 29 Jun 2018 14:43:25 +0300	[thread overview]
Message-ID: <7a115d9d7557bd9377b523e2588a948dd1d31e24.1530272540.git.kyukhin@tarantool.org> (raw)

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

             reply	other threads:[~2018-06-29 11:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-29 11:43 Kirill Yukhin [this message]
2018-06-29 13:04 ` [tarantool-patches] " n.pettik
2018-06-29 13:39   ` 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=7a115d9d7557bd9377b523e2588a948dd1d31e24.1530272540.git.kyukhin@tarantool.org \
    --to=kyukhin@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH] sql: make RANDOMBLOB(0) return NULL, fix rounding' \
    /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