From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id CAE1A2096D for ; Wed, 24 Jul 2019 08:24:34 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NuRcu5_CYO4v for ; Wed, 24 Jul 2019 08:24:34 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 8A6BA20903 for ; Wed, 24 Jul 2019 08:24:34 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: [tarantool-patches] Re: [PATCH v2 2/2] sql: fix error in case ARRAY/MAP converted to SCALAR From: "n.pettik" In-Reply-To: <67e721f4818f51861383cdf71cc88c63e45ab450.1563955619.git.imeevma@gmail.com> Date: Wed, 24 Jul 2019 15:24:32 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: <67e721f4818f51861383cdf71cc88c63e45ab450.1563955619.git.imeevma@gmail.com> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: Imeev Mergen > --- > src/box/sql/vdbe.c | 13 +++++++++-- > test/sql/types.result | 62 = +++++++++++++++++++++++++++++++++++++++++++++++++ > test/sql/types.test.lua | 22 ++++++++++++++++++ > 3 files changed, 95 insertions(+), 2 deletions(-) >=20 > diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c > index 1200ff4..f6aaaa6 100644 > --- a/src/box/sql/vdbe.c > +++ b/src/box/sql/vdbe.c > @@ -2704,8 +2704,17 @@ case OP_ApplyType: { > assert(pIn1 <=3D &p->aMem[(p->nMem+1 - p->nCursor)]); > assert(memIsValid(pIn1)); > if (mem_apply_type(pIn1, type) !=3D 0) { > - diag_set(ClientError, ER_SQL_TYPE_MISMATCH, > - sql_value_text(pIn1), > + const char *value; > + if ((pIn1->flags & MEM_Subtype) !=3D 0 && > + pIn1->subtype =3D=3D SQL_SUBTYPE_MSGPACK) { > + if (mp_typeof(*pIn1->z) =3D=3D MP_MAP) > + value =3D "map"; > + else > + value =3D "array"; > + } else { > + value =3D (const char = *)sql_value_text(pIn1); Why not simply patch sql_value_text() to make it convert map/array to string representation? I=E2=80=99m afraid this is unlikely to be the only place where such error may occur. > + } > + diag_set(ClientError, ER_SQL_TYPE_MISMATCH, = value, > field_type_strs[type]); > goto abort_due_to_error; > } > diff --git a/test/sql/types.test.lua b/test/sql/types.test.lua > index 22cb105..a99cc9f 100644 > --- a/test/sql/types.test.lua > +++ b/test/sql/types.test.lua > @@ -291,3 +291,25 @@ s:insert({1, true, {1, 2}, {a =3D 3}, 'asd'}) > box.execute('UPDATE t SET b =3D false WHERE i =3D 1;') > s:select() > s:drop() > + > +-- > +-- Make sure that the array/map conversion to scalar error is > +-- displayed correctly. > +-- > +box.execute('DROP TABLE IF EXISTS t1;=E2=80=99) Why =E2=80=98IF EXISTS=E2=80=99? Btw I=E2=80=99d better use space:drop() = to avoid SQL=E2=80=99s overhead.