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 2880A68713; Mon, 1 Feb 2021 11:16:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2880A68713 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1612167412; bh=OJRyELx9acc4w7AWMIbJcVBrJZkRChoSN6IVK2kZYbg=; 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=NKFk/nr680jg36uKSIJp8Pr8ERm6TgAxtV/Lht1f8PSlZtAR5oQGdEMr1XFO9IKAG 8NaxW2HFauLWQVYD6OyxBcW14HSPgqN1ZU8J+dD/4GPoV9WQ6G5bK3ONYrtA5+Kwg9 4E2ZPXk2ntbLTvZH4ltPDUbCjiYQKuUiBokNBrDY= Received: from smtp42.i.mail.ru (smtp42.i.mail.ru [94.100.177.102]) (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 E21B963342 for ; Mon, 1 Feb 2021 11:14:57 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E21B963342 Received: by smtp42.i.mail.ru with esmtpa (envelope-from ) id 1l6UMK-0001jp-V5; Mon, 01 Feb 2021 11:14:57 +0300 To: s.ostanevich@corp.mail.ru, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Mon, 1 Feb 2021 11:14:56 +0300 Message-Id: <7b6a3cf80a894403d3ce6b9bcc50d805868a9df8.1612166870.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-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD953AC099BC0052A9C3D690943982D6E894AC6DB5C833CB876182A05F5380850404D3170195589A24CBC6BE38CDF38112680FCD7DED02C0F358909A85797C00ECC X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE73B2A9F8A35432468EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006375A514678F9DF65078638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FC632E30DA10E3D6BDD8C90617A08688E3152609AFFBFA0654389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C02CC0D3CB04F14752D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8B8883BAB8B32E402CA471835C12D1D977C4224003CC836476EB9C4185024447017B076A6E789B0E975F5C1EE8F4F765FC3F904BEBCF17E58A3AA81AA40904B5D9CF19DD082D7633A078D18283394535A93AA81AA40904B5D98AA50765F79006373C5F04BB6B8F722ED81D268191BDAD3D698AB9A7B718F8C442539A7722CA490C13377AFFFEAFD26923F8577A6DFFEA7C089C7B220955F2D693EC92FD9297F6715571747095F342E857739F23D657EF2BD5E8D9A59859A8B6A99CF4BA5C1FDA12EFF80C71ABB335746BA297DBC24807EA27F269C8F02392CDC58410348177836EABEDDA51113D120200306258E7E6ABB4E4A6367B16DE6309 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C6FA9FB90A9CF70185DC159B6B11C7EE6EEEDF9B639320A4D9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF31C0090ACECF247D699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D345DB600F8E858000F7C25EB778E1A308CF52217A6FF29BD65DF0F5AA80B4987DFBA31FD6780B89B141D7E09C32AA3244C9928D328CA9BED127CAA334D67B246D005AB220A9D022EBCFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojyKiJYJ15DtKP8rw3SXm5qw== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306ED2394B017BB8EB29CBC6BE38CDF38112660497F7EF99AAC8F5105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 04/10] sql: introduce mem_convert_to_binary() 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" This patch introduces function mem_convert_to_binary() which allows us to unify a method to convert a MEM to a MEM of type VARBINARY. Part of #4470 --- src/box/sql/vdbeInt.h | 8 ++++++++ src/box/sql/vdbemem.c | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h index 0bb045170..213531d05 100644 --- a/src/box/sql/vdbeInt.h +++ b/src/box/sql/vdbeInt.h @@ -713,6 +713,14 @@ mems_have_same_type(const struct Mem *mem1, const struct Mem *mem2) (mem2->flags & MEM_PURE_TYPE_MASK); } +/** + * Cast MEM to varbinary according to explicit cast rules. + * + * @param mem VDBE memory register to convert. + */ +int +mem_convert_to_binary(struct Mem *mem); + void sqlVdbeMemInit(Mem *, sql *, u32); void sqlVdbeMemSetNull(Mem *); void sqlVdbeMemSetZeroBlob(Mem *, int); diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c index 186aebe03..849d490b8 100644 --- a/src/box/sql/vdbemem.c +++ b/src/box/sql/vdbemem.c @@ -981,6 +981,21 @@ mem_set_array(struct Mem *mem, char *value, uint32_t size, int alloc_type) return 0; } +int +mem_convert_to_binary(struct Mem *mem) +{ + if (mem_is_null(mem) || mem_is_binary(mem)) + return 0; + if (mem_is_string(mem)) { + mem->flags = (mem->flags & (MEM_Dyn | MEM_Static | MEM_Ephem)) | + MEM_Blob; + return 0; + } + diag_set(ClientError, ER_SQL_TYPE_MISMATCH, sql_value_to_diag_str(mem), + "varbinary"); + return -1; +} + /* * Return true if the Mem object contains a TEXT or BLOB that is * too large - whose size exceeds SQL_MAX_LENGTH. -- 2.25.1