From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [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 6DB2A445321 for ; Tue, 14 Jul 2020 18:48:12 +0300 (MSK) From: imeevma@tarantool.org Date: Tue, 14 Jul 2020 18:48:11 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v5 01/17] sql: set field_type in mem_set_*() functions List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: korablev@tarantool.org, tsafin@tarantool.org, tarantool-patches@dev.tarantool.org After this patch, the mem_set _*() functions will set the mem field type along with its MEM type flag. This will allow us to be sure that the MEM type and field type are set correctly, which is important when converting values from one type to another. Needed for #3809 --- src/box/sql/vdbemem.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c index 2e0d0bc3b..8e9ebf7ab 100644 --- a/src/box/sql/vdbemem.c +++ b/src/box/sql/vdbemem.c @@ -829,6 +829,7 @@ mem_set_bool(struct Mem *mem, bool value) sqlVdbeMemSetNull(mem); mem->u.b = value; mem->flags = MEM_Bool; + mem->field_type = FIELD_TYPE_BOOLEAN; } void @@ -839,6 +840,7 @@ mem_set_i64(struct Mem *mem, int64_t value) mem->u.i = value; int flag = value < 0 ? MEM_Int : MEM_UInt; MemSetTypeFlag(mem, flag); + mem->field_type = FIELD_TYPE_INTEGER; } void @@ -848,6 +850,7 @@ mem_set_u64(struct Mem *mem, uint64_t value) sqlVdbeMemSetNull(mem); mem->u.u = value; MemSetTypeFlag(mem, MEM_UInt); + mem->field_type = FIELD_TYPE_UNSIGNED; } void @@ -863,6 +866,7 @@ mem_set_int(struct Mem *mem, int64_t value, bool is_neg) mem->u.u = value; MemSetTypeFlag(mem, MEM_UInt); } + mem->field_type = FIELD_TYPE_INTEGER; } void @@ -873,6 +877,7 @@ mem_set_double(struct Mem *mem, double value) return; mem->u.r = value; MemSetTypeFlag(mem, MEM_Real); + mem->field_type = FIELD_TYPE_DOUBLE; } /* @@ -1068,6 +1073,11 @@ sqlVdbeMemSetStr(Mem * pMem, /* Memory cell to set to string value */ pMem->n = nByte; pMem->flags = flags; + assert((pMem->flags & (MEM_Str | MEM_Blob)) != 0); + if ((pMem->flags & MEM_Str) != 0) + pMem->field_type = FIELD_TYPE_STRING; + else + pMem->field_type = FIELD_TYPE_VARBINARY; if (nByte > iLimit) { diag_set(ClientError, ER_SQL_EXECUTE, "string or binary string"\ -- 2.25.1