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 2/4] sql: properly show values in type mismatch error Date: Tue, 13 Jul 2021 11:51:13 +0300 [thread overview] Message-ID: <03f301d777c4$3c1ba8e0$b452faa0$@tarantool.org> (raw) In-Reply-To: <ab3ec1e174a2268899a01e4ee7dfaff47c610456.1626159705.git.imeevma@gmail.com> LGTM, with one minor note, which may be addressed later. : From: imeevma@tarantool.org <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
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 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 [this message] 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 2/4] sql: properly show values in " Mergen Imeev via Tarantool-patches 2021-07-07 22:09 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-12 8:56 ` 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='03f301d777c4$3c1ba8e0$b452faa0$@tarantool.org' \ --to=tarantool-patches@dev.tarantool.org \ --cc=imeevma@tarantool.org \ --cc=tsafin@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v2 2/4] sql: properly show 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