From: imeevma@tarantool.org To: korablev@tarantool.org Cc: tarantool-patches@freelists.org Subject: [tarantool-patches] [PATCH v2 1/1] sql: ANSI aliases for LENGTH() Date: Sat, 6 Jul 2019 13:46:03 +0300 [thread overview] Message-ID: <e3db9d273b15ba6349e82c846e6e73b16ecb879f.1562409914.git.imeevma@gmail.com> (raw) This patch creates aliases CHARACTER_LENGTH() and CHAR_LENGTH() for LENGTH(). These functions are added because they are described in ANSI. Closes #3929 @TarantoolBot document Title: SQL functions CHAR_LENGTH() and CHARACTER_LENGTH() The SQL functions CHAR_LENGTH() and CHARACTER_LENGTH() work the same as the LENGTH() function. They take exactly one argument. If an argument of type TEXT or can be cast to a TEXT value using internal casting rules, these functions return the length of the TEXT value that represents the argument. They throw an error if the argument cannot be cast to a TEXT value. --- https://github.com/tarantool/tarantool/issues/3929 https://github.com/tarantool/tarantool/tree/imeevma/gh-3929-character-length-functions src/box/sql/func.c | 3 +++ test/sql-tap/func3.test.lua | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 761a3ab..98cad51 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1893,6 +1893,9 @@ sqlRegisterBuiltinFunctions(void) FIELD_TYPE_STRING), FUNCTION2(length, 1, 0, 0, lengthFunc, SQL_FUNC_LENGTH, FIELD_TYPE_INTEGER), + FUNCTION(char_length, 1, 0, 0, lengthFunc, FIELD_TYPE_INTEGER), + FUNCTION(character_length, 1, 0, 0, lengthFunc, + FIELD_TYPE_INTEGER), FUNCTION(position, 2, 0, 1, position_func, FIELD_TYPE_INTEGER), FUNCTION(printf, -1, 0, 0, printfFunc, FIELD_TYPE_STRING), FUNCTION(unicode, 1, 0, 0, unicodeFunc, FIELD_TYPE_STRING), diff --git a/test/sql-tap/func3.test.lua b/test/sql-tap/func3.test.lua index 6d6411c..2d0579d 100755 --- a/test/sql-tap/func3.test.lua +++ b/test/sql-tap/func3.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool test = require("sqltester") -test:plan(25) +test:plan(35) --!./tcltestrunner.lua -- 2010 August 27 @@ -285,5 +285,26 @@ test:do_test( end, test:execsql "EXPLAIN SELECT min(1.0+'2.0',4*11)") +-- +-- gh-3929: sql: ANSI aliases for LENGTH(). +-- +suits = {} +suits[1] = {str = '123456789', len = 9} +suits[2] = {str = '\x80', len = 1} +suits[3] = {str = '\x61\x62\x63', len = 3} +suits[4] = {str = '\x7f\x80\x81', len = 3} +suits[5] = {str = '\x61\xc0', len = 2} +suits[6] = {str = '\x61\xc0\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80', len = 12} +suits[7] = {str = '\xc0\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80', len = 11} +suits[8] = {str = '\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80', len = 10} +suits[9] = {str = '\x80\x80\x80\x80\x80\xf0\x80\x80\x80\x80', len = 7} +suits[10] = {str = '\x80\x80\x80\x80\x80\xf0\x80\x80\x80\xff', len = 7} + +for k,v in pairs(suits) do + test:do_execsql_test( + "func3-6."..k, + "SELECT CHAR_LENGTH('"..v.str.."'), CHARACTER_LENGTH('"..v.str.."');", + {v.len, v.len}) +end test:finish_test() -- 2.7.4
next reply other threads:[~2019-07-06 10:46 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-07-06 10:46 imeevma [this message] 2019-07-08 13:12 ` [tarantool-patches] " n.pettik 2019-07-11 7:48 ` 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=e3db9d273b15ba6349e82c846e6e73b16ecb879f.1562409914.git.imeevma@gmail.com \ --to=imeevma@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH v2 1/1] sql: ANSI aliases for LENGTH()' \ /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