From: Timur Safin via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: <imeevma@tarantool.org> Cc: <tarantool-patches@dev.tarantool.org> Subject: Re: [Tarantool-patches] [PATCH v2 1/4] sql: truncate values in type mismatch error Date: Tue, 13 Jul 2021 11:51:19 +0300 [thread overview] Message-ID: <03f501d777c4$4014cf80$c03e6e80$@tarantool.org> (raw) In-Reply-To: <f2bcdef6ed88f845f36ed600fcbad32630e95718.1626159705.git.imeevma@gmail.com> LGTM, but the same minor complaint about format of truncated literal which I've put elsewhere. Timur : From: imeevma@tarantool.org <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
next prev parent reply other threads:[~2021-07-13 8:51 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-13 7:03 [Tarantool-patches] [PATCH v2 0/4] sql: fix description of type mismatch errors Mergen Imeev via Tarantool-patches 2021-07-13 7:03 ` [Tarantool-patches] [PATCH v2 1/4] sql: truncate values in type mismatch error Mergen Imeev via Tarantool-patches 2021-07-13 8:51 ` Timur Safin via Tarantool-patches [this message] 2021-07-13 7:03 ` [Tarantool-patches] [PATCH v2 2/4] sql: properly show " Mergen Imeev via Tarantool-patches 2021-07-13 8:51 ` Timur Safin via Tarantool-patches 2021-07-13 7:03 ` [Tarantool-patches] [PATCH v2 3/4] sql: use proper type names in error descriptions Mergen Imeev via Tarantool-patches 2021-07-13 8:51 ` Timur Safin via Tarantool-patches 2021-07-13 7:04 ` [Tarantool-patches] [PATCH v2 4/4] sql: make type mismatch errors more informative Mergen Imeev via Tarantool-patches 2021-07-13 8:51 ` Timur Safin via Tarantool-patches 2021-07-13 10:17 ` Mergen Imeev via Tarantool-patches -- strict thread matches above, loose matches on Subject: below -- 2021-07-05 15:27 [Tarantool-patches] [PATCH v2 0/4] sql: fix description of type mismatch error Mergen Imeev via Tarantool-patches 2021-07-05 15:27 ` [Tarantool-patches] [PATCH v2 1/4] sql: truncate values in " Mergen Imeev via Tarantool-patches 2021-07-07 22:09 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-12 8:50 ` Mergen Imeev via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to='03f501d777c4$4014cf80$c03e6e80$@tarantool.org' \ --to=tarantool-patches@dev.tarantool.org \ --cc=imeevma@tarantool.org \ --cc=tsafin@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v2 1/4] sql: truncate values in type mismatch error' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox