From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id B2AFD267CF for ; Fri, 29 Jun 2018 07:43:33 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xu4wOxdWcI0V for ; Fri, 29 Jun 2018 07:43:33 -0400 (EDT) Received: from smtp15.mail.ru (smtp15.mail.ru [94.100.176.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 71C2D267CE for ; Fri, 29 Jun 2018 07:43:33 -0400 (EDT) From: Kirill Yukhin Subject: [tarantool-patches] [PATCH] sql: make RANDOMBLOB(0) return NULL, fix rounding Date: Fri, 29 Jun 2018 14:43:25 +0300 Message-Id: <7a115d9d7557bd9377b523e2588a948dd1d31e24.1530272540.git.kyukhin@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: korablev@tarantool.org Cc: tarantool-patches@freelists.org, 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)) ]], { -- - 32, 1, 2000 + 32, "", 2000 -- }) @@ -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