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 178616EC55; Tue, 13 Jul 2021 11:51:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 178616EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626166281; bh=Xq9HBLK/hg5q29zKc+P12RSJobUeMQvjfio5s7fBvyk=; h=To:Cc:References:In-Reply-To:Date:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=xoj3H5sj3AfaylMo2MHBkDPrXmkGdmihhcYs7c7TMbJ0iplSlkX9tHr40TR3JFe1G ogIro+P7lTTXm/7jbxLzRKGZ82U8e96IZ2qXfTNKc8C4loHNE6nM24tSTIcDxAJ0GN F72Z666OfW0ZP4Jgmxwlbf4bKD258bLSPPPbMGnc= Received: from smtp51.i.mail.ru (smtp51.i.mail.ru [94.100.177.111]) (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 B711B6EC55 for ; Tue, 13 Jul 2021 11:51:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B711B6EC55 Received: by smtp51.i.mail.ru with esmtpa (envelope-from ) id 1m3E8N-0005dg-1i; Tue, 13 Jul 2021 11:51:19 +0300 To: Cc: References: In-Reply-To: Date: Tue, 13 Jul 2021 11:51:13 +0300 Message-ID: <03f301d777c4$3c1ba8e0$b452faa0$@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQLLBM4G8PxJWct8/19n8ja8ysZxHgJiWizlqUZqDOA= Content-Language: ru X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD97BB0EF39AD2B33D5CFD6F66580F08A9EEA70CBC893E637A3182A05F538085040F962DE4D69E3C6650033CC2DA8232709E4AA08440DE38634CF2858984DD86216 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F9D3BE5B596754B8C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE77603ADE015AF816DEA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F2ACF74532F99AFC22456F0D8B36530C72CC7F00164DA146DAFE8445B8C89999728AA50765F790063783E00425F71A4181389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC82FFDA4F57982C5F4F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C6E16326BB14E90379735652A29929C6C4AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C3905409F363357F83BA3038C0950A5D36B5C8C57E37DE458B0BC6067A898B09E46D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE7E1BCFB2C0BE3F189731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A573B53AA22AFDAE0BF629AE26E87F918A11B999DAA8A31ABDD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA753753CEE10E4ED4A7410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D346F44602F3B494634429C61B13FD2BE29C8D16958D71C56FECF5725679A2127776E22AF22373115F21D7E09C32AA3244CF306B3A4FDC537EBCF3ED0E78E39DD4839C99C45E8D137E9729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojAZDAgpmGsva7zQTOaGh5/g== X-Mailru-Sender: B5B6A6EBBD94DAD8F320B9F0F42A6ED16A5F1059E345509FB36374D28825202D60A3BAE4FBD4F8B41EC9E4A2C82A33BC8C24925A86E657CE0C70AEE3C9A96FBAB3D7EE8ED63280BE112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 2/4] sql: properly show values in type mismatch error 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: Timur Safin via Tarantool-patches Reply-To: Timur Safin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" LGTM, with one minor note, which may be addressed later. : From: imeevma@tarantool.org : Subject: [PATCH v2 2/4] sql: properly show values in type mismatch error : ... : : diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c : index 05f053c55..3bbff9897 100644 : --- a/src/box/sql/mem.c : +++ b/src/box/sql/mem.c : @@ -79,8 +79,8 @@ mem_str(const struct Mem *mem) : return "NULL"; : case MEM_TYPE_STR: : if (mem->n > STR_VALUE_MAX_LEN) : - return tt_sprintf("%.*s...", STR_VALUE_MAX_LEN, mem->z); : - return tt_cstr(mem->z, mem->n); : + return tt_sprintf("'%.*s...", STR_VALUE_MAX_LEN, mem->z); : + return tt_sprintf("'%.*s'", mem->n, mem->z); : case MEM_TYPE_INT: : return tt_sprintf("%lld", mem->u.i); : case MEM_TYPE_UINT: : @@ -88,8 +88,18 @@ mem_str(const struct Mem *mem) : case MEM_TYPE_DOUBLE: : sql_snprintf(STR_VALUE_MAX_LEN, buf, "%!.15g", mem->u.r); : return tt_sprintf("%s", buf); : - case MEM_TYPE_BIN: : - return "varbinary"; : + case MEM_TYPE_BIN: { : + int len = MIN(mem->n, STR_VALUE_MAX_LEN / 2); : + for (int i = 0; i < len; ++i) { : + int n = (mem->z[i] & 0xF0) >> 4; : + buf[2 * i] = n < 10 ? ('0' + n) : ('A' + n - 10); : + n = (mem->z[i] & 0x0F); : + buf[2 * i + 1] = n < 10 ? ('0' + n) : ('A' + n - 10); : + } : + if (mem->n > len) : + return tt_sprintf("x'%.*s...", len * 2, buf); : + return tt_sprintf("x'%.*s'", len * 2, buf); : + } This looks mouthful, and improper abstraction level. I wanted to suggest to use cycle with tt_*snprintf for wrapped %0X format calls but on the second thought this function became too fragile and even more verbose (static_reserve(len*2) .. static_alloc(..) series of vsnprintf("%02X",...) Hell no, these 7 lines are simpler. : case MEM_TYPE_MAP: : case MEM_TYPE_ARRAY: { : const char *str = mp_str(mem->z); : @@ -99,7 +109,8 @@ mem_str(const struct Mem *mem) : return tt_sprintf("%.*s...", STR_VALUE_MAX_LEN, buf); : } : case MEM_TYPE_UUID: : - return tt_uuid_str(&mem->u.uuid); : + tt_uuid_to_string(&mem->u.uuid, buf); : + return tt_sprintf("'%s'", buf); : case MEM_TYPE_BOOL: : return mem->u.b ? "TRUE" : "FALSE"; : default: Regards, Timur