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 AC29F6CE3E; Thu, 11 Nov 2021 13:54:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AC29F6CE3E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1636628045; bh=/EYyWOjhS9UFtqtAMm4bPMAOwGnjAyFbimzkAArbQvw=; 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=L9El6l7cQgVgF+BE5UwTICngB3ugj7emovtwcihEcEr/baCisPuk9a63OCFzuyeqS d+DFUkrCWUW6tLHSZglfiROj2WG2tHcwo+MevkgQQsU+JKC7vUJm3LXowinsCp4sbJ 8tQ15rhwRBnCM/X5DmD+6EcsrzRfAKD7bjGrLEEs= 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 6D1FE71064 for ; Thu, 11 Nov 2021 13:49:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6D1FE71064 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1ml7df-00050F-Jv; Thu, 11 Nov 2021 13:49:03 +0300 To: kyukhin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Thu, 11 Nov 2021 13:49:03 +0300 Message-Id: <25596025696b5efcea294929f195703ae0ab2b18.1636627579.git.imeevma@gmail.com> 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: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD9731B3922EC0639796C498EBF619285F2FA7E0E589BD7410700894C459B0CD1B909CC8C5A2187C24BEE84F8128BBFF955BD7B9CED87D255679799EF890AE2FEA9 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE701173C01F417A2A6EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637995C329E4A8C93938638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D82CA8E37F0934FF647A51E0FD37DDDCA2117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC8C7ADC89C2F0B2A5A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18F04B652EEC242312D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B66F6A3E018CF4DC80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C7E9FEBB9C11794A1DC7666BE0AAD3FACD621AE850DF0FD689C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFCDE59DDCCE53AF2B699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3435B1F14A93C4073F9CDFF31162AEC27D525B0F304DB47CBAEC0306470EFC5FA171C36AA6973AA1471D7E09C32AA3244C70EBACC0F7CB41121D8268E901D074B860759606DA2E136A729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj4t8MBgWr8bJC69vyps+M4w== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D04ADB46ED39B587962CF1D9C094924E883D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 08/21] sql: refactor ZEROBLOB() 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 | 54 +++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 408c56e45..842e4e766 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -927,6 +927,32 @@ func_randomblob(struct sql_context *ctx, int argc, struct Mem *argv) mem_set_bin_allocated(ctx->pOut, res, len); } +/** + * Implementation of the ZEROBLOB() function. + * + * This function returns a zero-filled VARBINARY value. The size of this value + * is specified as an argument of the function. + */ +static void +func_zeroblob(struct sql_context *ctx, int argc, struct Mem *argv) +{ + assert(argc == 1); + (void)argc; + struct Mem *arg = &argv[0]; + assert(mem_is_null(arg) || mem_is_int(arg)); + if (mem_is_null(arg) || !mem_is_uint(arg)) + return; + if (arg->u.u == 0) + return mem_set_bin_static(ctx->pOut, "", 0); + uint64_t len = arg->u.u; + char *res = sqlDbMallocZero(sql_get(), len); + if (res == NULL) { + ctx->is_aborted = true; + return; + } + mem_set_bin_allocated(ctx->pOut, res, len); +} + static const unsigned char * mem_as_ustr(struct Mem *mem) { @@ -1498,32 +1524,6 @@ unicodeFunc(struct sql_context *context, int argc, struct Mem *argv) sql_result_uint(context, sqlUtf8Read(&z)); } -/* - * The zeroblob(N) function returns a zero-filled blob of size N bytes. - */ -static void -zeroblobFunc(struct sql_context *context, int argc, struct Mem *argv) -{ - int64_t n; - assert(argc == 1); - UNUSED_PARAMETER(argc); - n = mem_get_int_unsafe(&argv[0]); - if (n < 0) - n = 0; - if (n > sql_get()->aLimit[SQL_LIMIT_LENGTH]) { - diag_set(ClientError, ER_SQL_EXECUTE, "string or binary string"\ - "is too big"); - context->is_aborted = true; - return; - } - char *str = sqlDbMallocZero(sql_get(), n); - if (str == NULL) { - context->is_aborted = true; - return; - } - mem_set_bin_allocated(context->pOut, str, n); -} - /* * The replace() function. Three arguments are all strings: call * them A, B, and C. The result is also a string which is derived @@ -1967,7 +1967,7 @@ static struct sql_func_definition definitions[] = { {"UUID", 1, {FIELD_TYPE_INTEGER}, FIELD_TYPE_UUID, sql_func_uuid, NULL}, {"VERSION", 0, {}, FIELD_TYPE_STRING, sql_func_version, NULL}, {"ZEROBLOB", 1, {FIELD_TYPE_INTEGER}, FIELD_TYPE_VARBINARY, - zeroblobFunc, NULL}, + func_zeroblob, NULL}, }; static struct sql_func_dictionary * -- 2.25.1