From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 82F6125AB8 for ; Thu, 11 Jul 2019 17:23:43 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aW6SlfLaPxDn for ; Thu, 11 Jul 2019 17:23:43 -0400 (EDT) Received: from smtp37.i.mail.ru (smtp37.i.mail.ru [94.100.177.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 7668E25AB4 for ; Thu, 11 Jul 2019 17:23:42 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH 6/6] sql: allow to specify UNSIGNED column type From: Vladislav Shpilevoy References: <734EC309-6DCF-42C2-8041-135A8B68E935@tarantool.org> <9a397d31-1cae-0dd0-cdd6-733388cb01af@tarantool.org> Message-ID: Date: Thu, 11 Jul 2019 23:25:04 +0200 MIME-Version: 1.0 In-Reply-To: <9a397d31-1cae-0dd0-cdd6-733388cb01af@tarantool.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: "n.pettik" , tarantool-patches@freelists.org As I promised, below are other comments regarding Mem.u.i/u, MEM_Int/UInt. Perhaps, they are final. ------------------------- vdbemem.c:661 > if ((pMem->flags & MEM_Blob) != 0 && type == FIELD_TYPE_NUMBER) { > bool is_neg; > if (sql_atoi64(pMem->z, (int64_t *) &pMem->u.i, &is_neg, > pMem->n) == 0) { > MemSetTypeFlag(pMem, MEM_Real); > pMem->u.r = pMem->u.i; > return 0; > } > return ! sqlAtoF(pMem->z, &pMem->u.r, pMem->n); > } Here you use assign 'pMem.u.i' to 'pMem.u.r' without checking its sign. In theory something like that should work wrong now: box.execute("SELECT CAST('9223372036854775837' AS REAL)") But you need to somehow write that number as blob. ------------------------- vdbetrace.c:90 Function sqlVdbeExpandSql stringifies integers, but misses a version for big unsigned. ------------------------- vdbe.c:307 > case FIELD_TYPE_INTEGER: > case FIELD_TYPE_UNSIGNED: > if ((record->flags & MEM_Int) == MEM_Int) > return 0; > if ((record->flags & MEM_UInt) == MEM_UInt) > return 0; > if ((record->flags & MEM_Real) == MEM_Real) { > int64_t i = (int64_t) record->u.r; > if (i == record->u.r) > mem_set_int(record, record->u.r, > record->u.r <= -1); > return 0; > } It is a part of function mem_apply_type. When target type is UNSIGNED, and a value is MEM_Int, you do nothing. Why? Looks like it is possible to pass here a negative value, and CAST UNSIGNED would do nothing.