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 0C7CE7105E; Thu, 11 Nov 2021 13:52:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0C7CE7105E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1636627925; bh=v5os/F0wm0NWUYpytqXxkk+hMOZbWpNycGwb/G1p8mQ=; 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=k7qSfKHzcux4aSVv1DjRQ4Pf+gWZPUZ5f2d2gNOxb2CCT5LwKwicF1IfnZScGD1A3 WVZEyIbC71adwdXmfJXARGeJpRh0RyNi41myzMCSxCf0CPXpe29CVBCCnNul4blaXz hFVJD4TJjZ5QWMlaFNoY4PjK35SUqTQUVI10mZ8M= 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 ED9B071062 for ; Thu, 11 Nov 2021 13:48:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org ED9B071062 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1ml7dX-0004tN-VX; Thu, 11 Nov 2021 13:48:56 +0300 To: kyukhin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Thu, 11 Nov 2021 13:48:55 +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: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9731B3922EC0639792BB520D6BC54996EEEF308B3433E7AC900894C459B0CD1B9F33630E1C07A5C732E4FB3A894770815BD7B9CED87D255674E897E529B7F4697 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7FEAC828D2BF6EC3CEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637F91103FA893F53AB8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D833D16D4E6F10826ADE4FA8CC3E1D7BD3117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B66F6A3E018CF4DC80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C7E9FEBB9C11794A18E93A689C3F971F92D47836284E054AE9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFCDE59DDCCE53AF2B699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D71B56C992F8AF19091ACA3BEBD2CED18904518CB488A6DD457E5F032DCBA4C21ED2EFF7ACD500DF1D7E09C32AA3244C331C7C294D19C920821E297F08EE233A30452B15D76AEC14729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj4t8MBgWr8bLfD5OxAJ7EAA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DD83BB8E6D6901DDD2C06615A609E468F83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B 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 e4372de86..c0e8c4416 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -847,6 +847,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) { @@ -941,44 +954,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. */ @@ -1918,8 +1893,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