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 C0C256EC56; Tue, 13 Jul 2021 11:51:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C0C256EC56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626166310; bh=dor93YBzlSEOuqJUQ2+kIH6QeXZx0epitaJCiklrjaI=; 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=VA1bVaQcmbiSG09muhsP+fnOiM4c0y3sGQ9L9go1vCtIKJ0FYD17huf+QBGeTCbS2 ndSFb009/CnOwOOFl+DCnDs+g3Wv80sTeF/izqIf6v89wldhy3vBLP5D4/6eBs0EvE qs16QgZCwRbHcPDgWCBh9gk4+LgQ5/dcHlj4y09c= Received: from smtp36.i.mail.ru (smtp36.i.mail.ru [94.100.177.96]) (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 46D776EC56 for ; Tue, 13 Jul 2021 11:51:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 46D776EC56 Received: by smtp36.i.mail.ru with esmtpa (envelope-from ) id 1m3E8T-0004gg-NK; Tue, 13 Jul 2021 11:51:26 +0300 To: Cc: References: In-Reply-To: Date: Tue, 13 Jul 2021 11:51:19 +0300 Message-ID: <03f501d777c4$4014cf80$c03e6e80$@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/19n8ja8ysZxHgJZpYRrqUaqm0A= Content-Language: ru X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD97BB0EF39AD2B33D52181556DE8CA6AFBAFE18027C1DA7DF9182A05F538085040D095D77CBC780A4A1A7DF1399B281CBC6237DAD81B702529E33EF39F238639B5 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE79145AB6E9E75F07EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637F91103FA893F53AB8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8674B463C7B6DA4DA4FCA7A063D1DCC42117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18C26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EEC65AC60A1F0286FE2AE38A8E97BAFFB1D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE38ED1AC82D843A2BB03F1AB874ED89028C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637BBEA499411984DA1EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A5E2D9885EC06C0E9E9BCD168F252742EF04563E2E6BDAB64ED59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA753753CEE10E4ED4A7410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3447DF5779098ECEE961274DDB70C2D0AB0F5444EBB6694EFBFEB522F323674FE2D20371B8D5FFA2F41D7E09C32AA3244CBA0EC1E565ED7722DC18F98A865E9DCF55E75C8D0ED9F6EE729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojAZDAgpmGsvYjlYkohrm6SA== X-Mailru-Sender: B5B6A6EBBD94DAD8F320B9F0F42A6ED16A5F1059E345509FDCB236A22D9662E48897E28B5351C2421EC9E4A2C82A33BC8C24925A86E657CE0C70AEE3C9A96FBAB3D7EE8ED63280BE112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 1/4] sql: truncate 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, but the same minor complaint about format of truncated literal which I've put elsewhere. Timur : From: imeevma@tarantool.org : Subject: [PATCH v2 1/4] sql: truncate values in type mismatch error : : STRING, MAP, and ARRAY values that are too long can make the type : mismatch error description less descriptive than necessary. This patch : truncates values that are too long and adds "..." to indicate that the : value has been truncated. : : Part of #6176 : --- : src/box/sql/mem.c | 18 ++++--- : src/box/sql/mem.h | 3 +- : ...-4766-wrong-cast-from-blob-to-int.test.lua | 7 +-- : test/sql-tap/sql-errors.test.lua | 47 ++++++++++++++++++- : test/sql/types.result | 6 +-- : 5 files changed, 62 insertions(+), 19 deletions(-) : : diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c : index 2595e2fd4..05f053c55 100644 : --- a/src/box/sql/mem.c : +++ b/src/box/sql/mem.c : @@ -57,6 +57,7 @@ sqlVdbeMemGrow(struct Mem *pMem, int n, int preserve); : : enum { : BUF_SIZE = 32, : + STR_VALUE_MAX_LEN = 128, : }; : : bool : @@ -72,26 +73,31 @@ mem_is_field_compatible(const struct Mem *mem, enum : field_type type) : const char * : mem_str(const struct Mem *mem) : { : - char buf[BUF_SIZE]; : + char buf[STR_VALUE_MAX_LEN]; : switch (mem->type) { : case MEM_TYPE_NULL: : return "NULL"; : case MEM_TYPE_STR: : - if ((mem->flags & MEM_Term) != 0) : - return mem->z; : + if (mem->n > STR_VALUE_MAX_LEN) : + return tt_sprintf("%.*s...", STR_VALUE_MAX_LEN, mem->z); : return tt_cstr(mem->z, mem->n); : case MEM_TYPE_INT: : return tt_sprintf("%lld", mem->u.i); : case MEM_TYPE_UINT: : return tt_sprintf("%llu", mem->u.u); : case MEM_TYPE_DOUBLE: : - sql_snprintf(BUF_SIZE, &buf[0], "%!.15g", mem->u.r); : + 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_MAP: : - case MEM_TYPE_ARRAY: : - return mp_str(mem->z); : + case MEM_TYPE_ARRAY: { : + const char *str = mp_str(mem->z); : + if (strlen(str) <= STR_VALUE_MAX_LEN) : + return str; : + memcpy(buf, str, STR_VALUE_MAX_LEN); : + return tt_sprintf("%.*s...", STR_VALUE_MAX_LEN, buf); : + } : case MEM_TYPE_UUID: : return tt_uuid_str(&mem->u.uuid); : case MEM_TYPE_BOOL: : diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h