From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp61.i.mail.ru (smtp61.i.mail.ru [217.69.128.41]) (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 3941541C5DB for ; Tue, 30 Jun 2020 03:22:33 +0300 (MSK) Date: Tue, 30 Jun 2020 00:22:32 +0000 From: Nikita Pettik Message-ID: <20200630002231.GE27240@tarantool.org> References: <7781d885cc6a0ea2a420984f88e2612115dbed81.1593096639.git.imeevma@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7781d885cc6a0ea2a420984f88e2612115dbed81.1593096639.git.imeevma@gmail.com> Subject: Re: [Tarantool-patches] [PATCH v3 8/8] sql: show value and its type in type mismatch error List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: imeevma@tarantool.org Cc: tarantool-patches@dev.tarantool.org 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 кслок. Забыл точку в конце :) > } > #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) > + 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'); > ]], { > -- > - 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" > }) Я бы может еще кавычки вокруг чиселок/буленов не добавлял, но это в принципе мелочь - тип то печатается. В остальном - ОК.