From: Mergen Imeev <imeevma@tarantool.org> To: Nikita Pettik <korablev@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH v3 8/8] sql: show value and its type in type mismatch error Date: Sun, 5 Jul 2020 18:03:17 +0300 [thread overview] Message-ID: <20200705150317.GF135859@tarantool.org> (raw) In-Reply-To: <20200630002231.GE27240@tarantool.org> My answers and diff below. On Tue, Jun 30, 2020 at 12:22:32AM +0000, Nikita Pettik wrote: > On 25 Jun 18:17, imeevma@tarantool.org wrote: > > After this patch value and its type will be shown in description > > of type mismatch error > > Какие цели преследует этот патч? Зачем мы это делаем? > Диф то на 1.5 кслок. It is just a refactoring. It can be dropped. > Забыл точку в конце :) > Fixed. > > } > > #ifdef SQL_DEBUG > > @@ -4740,7 +4735,7 @@ case OP_IdxGE: { /* jump */ > > (mem->flags & (MEM_Real | MEM_Int | MEM_UInt)) != 0) > > continue; > > diag_set(ClientError, ER_SQL_TYPE_MISMATCH, > > - field_type_strs[type], mem_type_to_str(mem)); > > + sql_value_to_diag_str(mem), mem_type_to_str(mem)); > > goto abort_due_to_error; > > } > > #ifdef SQL_DEBUG > > diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c > > index a721afc83..bb7676354 100644 > > --- a/src/box/sql/vdbemem.c > > +++ b/src/box/sql/vdbemem.c > > @@ -1166,12 +1166,15 @@ sqlValueText(sql_value * pVal) > > const char * > > sql_value_to_diag_str(sql_value *value) > > { > > - if (sql_value_type(value) == MP_BIN) { > > - if (mem_has_msgpack_subtype(value)) > > - return sqlValueText(value); > > + if (sql_value_mp_type(value) == MP_BIN) > > return "varbinary"; > > - } > > - return sqlValueText(value); > > + char *type = mem_type_to_str(value); > > + char *str = (char *)sqlValueText(value); > > + if (str == NULL) > > + return "NULL"; > > + if (strlen(str) < 80) > > https://en.wikipedia.org/wiki/Magic_number_(programming) > Added a enum here. > > + return tt_sprintf("'%s' (type: %s)", str, type); > > + return tt_sprintf("'%.80s...' (type: %s)", str, type); > > } > > > > /* > > diff --git a/test/sql-tap/autoinc.test.lua b/test/sql-tap/autoinc.test.lua > > index 07442b60a..1547ffcd3 100755 > > --- a/test/sql-tap/autoinc.test.lua > > +++ b/test/sql-tap/autoinc.test.lua > > @@ -618,7 +618,7 @@ test:do_catchsql_test( > > INSERT INTO t2 VALUES('asd'); > > ]], { > > -- <autoinc-10.2> > > - 1, "Type mismatch: can not convert asd to integer" > > + 1, "Type mismatch: can not convert 'asd' (type: text) to integer" > > Выглядит зачотно, выглядит all right! > > > diff --git a/test/sql-tap/gh-3809-implicit-cast-assignment.test.lua b/test/sql-tap/gh-3809-implicit-cast-assignment.test.lua > > index a1809b3cb..f1edfa0f6 100755 > > --- a/test/sql-tap/gh-3809-implicit-cast-assignment.test.lua > > +++ b/test/sql-tap/gh-3809-implicit-cast-assignment.test.lua > > @@ -28,7 +28,7 @@ test:do_catchsql_test( > > [[ > > INSERT INTO ti(i) VALUES (100000000000000000000000000000000.1) > > ]], { > > - 1, "Type mismatch: can not convert 1.0e+32 to integer" > > + 1, "Type mismatch: can not convert '1.0e+32' (type: real) to integer" > > }) > > Я бы может еще кавычки вокруг чиселок/буленов не добавлял, но это > в принципе мелочь - тип то печатается. > I think it is better as it is now since in some cases STRING value and BOOLEAN values look the same. > В остальном - ОК. Diff: diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c index 32f4ae0b6..7cff881c0 100644 --- a/src/box/sql/vdbemem.c +++ b/src/box/sql/vdbemem.c @@ -1163,6 +1163,10 @@ sqlValueText(sql_value * pVal) return valueToText(pVal); } +enum { + DIAG_STR_LEN_MAX = 80, +}; + const char * sql_value_to_diag_str(sql_value *value) { @@ -1172,7 +1176,7 @@ sql_value_to_diag_str(sql_value *value) char *str = (char *)sqlValueText(value); if (str == NULL) return "NULL"; - if (strlen(str) < 80) + if (strlen(str) < DIAG_STR_LEN_MAX) return tt_sprintf("'%s' (type: %s)", str, type); return tt_sprintf("'%.80s...' (type: %s)", str, type); }
next prev parent reply other threads:[~2020-07-05 15:03 UTC|newest] Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-25 15:17 [Tarantool-patches] [PATCH v3 0/8] Remove implicit cast imeevma 2020-06-25 15:17 ` [Tarantool-patches] [PATCH v3 1/8] sql: introduce mem_set_double() imeevma 2020-06-28 13:31 ` Nikita Pettik 2020-07-06 14:02 ` Nikita Pettik 2020-06-25 15:17 ` [Tarantool-patches] [PATCH v3 2/8] sql: change implicit cast for assignment imeevma 2020-06-30 11:50 ` Nikita Pettik 2020-07-05 14:26 ` Mergen Imeev 2020-07-06 21:27 ` Nikita Pettik 2020-07-07 9:29 ` Mergen Imeev 2020-07-07 15:35 ` Nikita Pettik 2020-07-10 10:49 ` Nikita Pettik 2020-06-25 15:17 ` [Tarantool-patches] [PATCH v3 3/8] sql: remove mem_apply_type() from OP_MakeRecord imeevma 2020-06-25 15:17 ` [Tarantool-patches] [PATCH v3 4/8] sql: replace ApplyType by CheckType for IN operator imeevma 2020-06-29 12:56 ` Nikita Pettik 2020-07-05 14:28 ` Mergen Imeev 2020-07-06 22:06 ` Nikita Pettik 2020-07-07 11:26 ` Mergen Imeev 2020-07-07 16:29 ` Nikita Pettik 2020-06-25 15:17 ` [Tarantool-patches] [PATCH v3 5/8] sql: remove mem_apply_type() from OP_MustBeInt imeevma 2020-06-29 13:29 ` Nikita Pettik 2020-07-05 14:29 ` Mergen Imeev 2020-06-25 15:17 ` [Tarantool-patches] [PATCH v3 6/8] sql: remove implicit cast for comparison imeevma 2020-06-29 23:51 ` Nikita Pettik 2020-07-05 14:47 ` Mergen Imeev 2020-07-06 23:11 ` Nikita Pettik 2020-06-25 15:17 ` [Tarantool-patches] [PATCH v3 7/8] sql: remove unused functions imeevma 2020-06-29 23:52 ` Nikita Pettik 2020-07-05 14:50 ` Mergen Imeev 2020-06-25 15:17 ` [Tarantool-patches] [PATCH v3 8/8] sql: show value and its type in type mismatch error imeevma 2020-06-30 0:22 ` Nikita Pettik 2020-07-05 15:03 ` Mergen Imeev [this message] 2020-07-06 21:44 ` Nikita Pettik
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=20200705150317.GF135859@tarantool.org \ --to=imeevma@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v3 8/8] sql: show value and its type 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