From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 118CA6E45E; Fri, 8 Oct 2021 20:33:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 118CA6E45E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1633714420; bh=HJFAiZOwtp0439z1cqtJQoLlW+Yk6ZemrjXPIPUMEj4=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Rks7Sni9UEK9qCiDMuxOsiFQ9BrQBGLddKAgQcQC+NqEovPVEEVSrx4ykgD3bN9Z9 Sk2tyj5pTdNV6VZmOjwvrmkTNXRccx1tmX1dt3OkiVKEjUUnqevXhODmudYJgXf95v NRFjuiW+wY6k4z6V3BMyOtAM4RYh8Gfo2B0WtUvk= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id E1B096E463 for ; Fri, 8 Oct 2021 20:31:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E1B096E463 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mYtie-00081B-CT; Fri, 08 Oct 2021 20:31:40 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 8 Oct 2021 20:31:40 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9A6D4E3B1981C4C7DC9765195527EE77661ADD44F6E79FA5A182A05F5380850402DC3B91BD4822AE9055E472532D6730A5B49BA8A5F205B2C17D899E2A0A66AC9 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7D6964C9E324ABA58EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637188F5654332B449D8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D87644ED86CDECFA373702D19C186CFFD5117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B62CFFCC7B69C47339089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C650BD2383FF25EF52878A7D93863C429417780125ECCECA69C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF520746E264B47742699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34324A9840C798D5005650F3A336A5E2AC0C57894613A9CFBFF3A9373648DCCFD037AE6D4CF5436D831D7E09C32AA3244C8426549A6CF6759B8DCC6F961ED5DDB2F165894D92D62706729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojMZ06aokA6brt2l9wjBrTZw== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D47C82EFE9F109E7E6BBD1217AFD4C61F83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 04/21] sql: refactor LENGTH() function X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Part of #4145 --- src/box/sql/func.c | 55 +++++++++++++--------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index e5d763be1..863dbf1c4 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -833,6 +833,19 @@ func_hex(struct sql_context *ctx, int argc, struct Mem *argv) mem_set_str_allocated(ctx->pOut, str, size); } +/** Implementation of the OCTET_LENGTH() function. */ +static void +func_octet_length(struct sql_context *ctx, int argc, struct Mem *argv) +{ + assert(argc == 1); + (void)argc; + struct Mem *arg = &argv[0]; + if (mem_is_null(arg)) + return; + assert(mem_is_bytes(arg) && arg->n >= 0); + mem_set_uint(ctx->pOut, arg->n); +} + static const unsigned char * mem_as_ustr(struct Mem *mem) { @@ -927,44 +940,6 @@ typeofFunc(struct sql_context *context, int argc, struct Mem *argv) sql_result_text(context, z, -1, SQL_STATIC); } -/* - * Implementation of the length() function - */ -static void -lengthFunc(struct sql_context *context, int argc, struct Mem *argv) -{ - int len; - - assert(argc == 1); - UNUSED_PARAMETER(argc); - switch (sql_value_type(&argv[0])) { - case MP_BIN: - case MP_ARRAY: - case MP_MAP: - case MP_INT: - case MP_UINT: - case MP_BOOL: - case MP_DOUBLE:{ - mem_as_bin(&argv[0]); - sql_result_uint(context, mem_len_unsafe(&argv[0])); - break; - } - case MP_EXT: - case MP_STR:{ - const unsigned char *z = mem_as_ustr(&argv[0]); - if (z == 0) - return; - len = sql_utf8_char_count(z, mem_len_unsafe(&argv[0])); - sql_result_uint(context, len); - break; - } - default:{ - sql_result_null(context); - break; - } - } -} - /* * Implementation of the printf() function. */ @@ -1904,8 +1879,8 @@ static struct sql_func_definition definitions[] = { {"LENGTH", 1, {FIELD_TYPE_STRING}, FIELD_TYPE_INTEGER, func_char_length, NULL}, - {"LENGTH", 1, {FIELD_TYPE_VARBINARY}, FIELD_TYPE_INTEGER, lengthFunc, - NULL}, + {"LENGTH", 1, {FIELD_TYPE_VARBINARY}, FIELD_TYPE_INTEGER, + func_octet_length, NULL}, {"LIKE", 2, {FIELD_TYPE_STRING, FIELD_TYPE_STRING}, FIELD_TYPE_BOOLEAN, likeFunc, NULL}, {"LIKE", 3, {FIELD_TYPE_STRING, FIELD_TYPE_STRING, FIELD_TYPE_STRING}, -- 2.25.1