From: imeevma@tarantool.org To: korablev@tarantool.org, tsafin@tarantool.org, tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH v6 09/22] sql: check args of position() Date: Thu, 16 Jul 2020 17:46:20 +0300 [thread overview] Message-ID: <8128b363970ac8e314eb6085524c47e17e3995cf.1594909974.git.imeevma@gmail.com> (raw) In-Reply-To: <cover.1594909974.git.imeevma@gmail.com> After this patch, the argument types of the position() function will be checked properly. Part of #4159 --- src/box/sql/func.c | 24 ++++------------ test/sql-tap/func5.test.lua | 51 +++++++++++++++++++++++++++++++++- test/sql-tap/position.test.lua | 6 ++-- 3 files changed, 58 insertions(+), 23 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 2910f308f..a1b284762 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -532,22 +532,8 @@ position_func(struct sql_context *context, int argc, struct Mem **argv) if (haystack_type == MP_NIL || needle_type == MP_NIL) return; - /* - * Position function can be called only with string - * or blob params. - */ - struct Mem *inconsistent_type_arg = NULL; - if (needle_type != MP_STR && needle_type != MP_BIN) - inconsistent_type_arg = needle; - if (haystack_type != MP_STR && haystack_type != MP_BIN) - inconsistent_type_arg = haystack; - if (inconsistent_type_arg != NULL) { - diag_set(ClientError, ER_INCONSISTENT_TYPES, - "text or varbinary", - mem_type_to_str(inconsistent_type_arg)); - context->is_aborted = true; - return; - } + assert(needle_type == MP_STR || needle_type == MP_BIN); + assert(haystack_type == MP_STR || haystack_type == MP_BIN); /* * Both params of Position function must be of the same * type. @@ -2683,9 +2669,9 @@ static struct { }, { .name = "POSITION", .param_count = 2, - .first_arg = FIELD_TYPE_ANY, - .args = FIELD_TYPE_ANY, - .is_blob_like_str = false, + .first_arg = FIELD_TYPE_STRING, + .args = FIELD_TYPE_STRING, + .is_blob_like_str = true, .returns = FIELD_TYPE_INTEGER, .aggregate = FUNC_AGGREGATE_NONE, .is_deterministic = true, diff --git a/test/sql-tap/func5.test.lua b/test/sql-tap/func5.test.lua index b704ed7d5..170dee9f9 100755 --- a/test/sql-tap/func5.test.lua +++ b/test/sql-tap/func5.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool test = require("sqltester") -test:plan(99) +test:plan(106) --!./tcltestrunner.lua -- 2010 August 27 @@ -836,4 +836,53 @@ test:do_catchsql_test( 1, "Type mismatch: can not convert varbinary to string" }) +test:do_execsql_test( + "func-5-6.12.1", [[ + SELECT position(NULL, NULL); + ]],{ + "" + }) + +test:do_catchsql_test( + "func-5-6.12.2", [[ + SELECT position(23, 123); + ]], { + 1, "Type mismatch: can not convert 23 to string" + }) + +test:do_catchsql_test( + "func-5-6.12.3", [[ + SELECT position(-12, -123); + ]], { + 1, "Type mismatch: can not convert -12 to string" + }) + +test:do_catchsql_test( + "func-5-6.12.4", [[ + SELECT position(-5.5, -5.5); + ]], { + 1, "Type mismatch: can not convert -5.5 to string" + }) + +test:do_execsql_test( + "func-5-6.12.5", [[ + SELECT position('23', '-123'); + ]], { + 3 + }) + +test:do_catchsql_test( + "func-5-6.12.6", [[ + SELECT position(false, true); + ]], { + 1, "Type mismatch: can not convert FALSE to string" + }) + +test:do_execsql_test( + "func-5-6.12.7", [[ + SELECT position(X'34', X'3334'); + ]], { + 2 + }) + test:finish_test() diff --git a/test/sql-tap/position.test.lua b/test/sql-tap/position.test.lua index e0455abc9..0d4f6f371 100755 --- a/test/sql-tap/position.test.lua +++ b/test/sql-tap/position.test.lua @@ -228,7 +228,7 @@ test:do_test( return test:catchsql "SELECT position(34, 12345);" end, { -- <position-1.23> - 1, "Inconsistent types: expected text or varbinary got unsigned" + 1, "Type mismatch: can not convert 34 to string" -- </position-1.23> }) @@ -238,7 +238,7 @@ test:do_test( return test:catchsql "SELECT position(34, 123456.78);" end, { -- <position-1.24> - 1, "Inconsistent types: expected text or varbinary got real" + 1, "Type mismatch: can not convert 34 to string" -- </position-1.24> }) @@ -248,7 +248,7 @@ test:do_test( return test:catchsql "SELECT position(x'3334', 123456.78);" end, { -- <position-1.25> - 1, "Inconsistent types: expected text or varbinary got real" + 1, "Type mismatch: can not convert 123456.78 to string" -- </position-1.25> }) -- 2.25.1
next prev parent reply other threads:[~2020-07-16 14:46 UTC|newest] Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-07-16 14:45 [Tarantool-patches] [PATCH v6 00/22] sql: change implicit cast imeevma 2020-07-16 14:45 ` [Tarantool-patches] [PATCH v6 01/22] sql: change implicit cast for assignment imeevma 2020-07-16 14:45 ` [Tarantool-patches] [PATCH v6 02/22] sql: use ApplyType to check function arguments imeevma 2020-07-16 14:45 ` [Tarantool-patches] [PATCH v6 03/22] sql: check args of abs() imeevma 2020-07-16 16:12 ` Nikita Pettik 2020-07-16 14:45 ` [Tarantool-patches] [PATCH v6 04/22] sql: check args of avg(), sum() and total() imeevma 2020-07-16 16:21 ` Nikita Pettik 2020-07-16 14:45 ` [Tarantool-patches] [PATCH v6 05/22] sql: check args of char() imeevma 2020-07-16 16:27 ` Nikita Pettik 2020-07-16 14:45 ` [Tarantool-patches] [PATCH v6 06/22] sql: check args of length() imeevma 2020-07-16 16:31 ` Nikita Pettik 2020-07-16 14:46 ` [Tarantool-patches] [PATCH v6 07/22] sql: check operands of LIKE imeevma 2020-07-16 17:03 ` Nikita Pettik 2020-07-16 14:46 ` [Tarantool-patches] [PATCH v6 08/22] sql: check args of lower() and upper() imeevma 2020-07-16 17:09 ` Nikita Pettik 2020-07-16 14:46 ` imeevma [this message] 2020-07-16 17:28 ` [Tarantool-patches] [PATCH v6 09/22] sql: check args of position() Nikita Pettik 2020-07-16 14:46 ` [Tarantool-patches] [PATCH v6 10/22] sql: check args of randomblob() imeevma 2020-07-16 17:28 ` Nikita Pettik 2020-07-16 14:46 ` [Tarantool-patches] [PATCH v6 11/22] sql: check args of replace() imeevma 2020-07-16 14:46 ` [Tarantool-patches] [PATCH v6 12/22] sql: check args of round() imeevma 2020-07-16 14:46 ` [Tarantool-patches] [PATCH v6 13/22] sql: check args of soundex() imeevma 2020-07-16 14:47 ` [Tarantool-patches] [PATCH v6 14/22] sql: check args of substr() imeevma 2020-07-16 14:47 ` [Tarantool-patches] [PATCH v6 15/22] sql: check args of unicode() imeevma 2020-07-16 14:47 ` [Tarantool-patches] [PATCH v6 16/22] sql: check args of zeroblob() imeevma 2020-07-16 14:47 ` [Tarantool-patches] [PATCH v6 17/22] sql: remove unused DOUBLE to INTEGER conversion imeevma 2020-07-16 14:47 ` [Tarantool-patches] [PATCH v6 18/22] sql: add implicit cast between numbers in OP_Seek* imeevma 2020-07-16 14:47 ` [Tarantool-patches] [PATCH v6 19/22] sql: change comparison between numbers using index imeevma 2020-07-16 14:47 ` [Tarantool-patches] [PATCH v6 20/22] sql: remove implicit cast from comparison opcodes imeevma 2020-07-16 14:47 ` [Tarantool-patches] [PATCH v6 21/22] sql: fix implicit cast in opcode MustBeInt imeevma 2020-07-16 14:47 ` [Tarantool-patches] [PATCH v6 22/22] sql: remove implicit cast from MakeRecord opcode imeevma
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=8128b363970ac8e314eb6085524c47e17e3995cf.1594909974.git.imeevma@gmail.com \ --to=imeevma@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=tsafin@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v6 09/22] sql: check args of position()' \ /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