[tarantool-patches] Re: [PATCH v2 2/2] sql: fix error in case ARRAY/MAP converted to SCALAR
n.pettik
korablev at tarantool.org
Wed Jul 24 15:24:32 MSK 2019
> ---
> src/box/sql/vdbe.c | 13 +++++++++--
> test/sql/types.result | 62 +++++++++++++++++++++++++++++++++++++++++++++++++
> test/sql/types.test.lua | 22 ++++++++++++++++++
> 3 files changed, 95 insertions(+), 2 deletions(-)
>
> 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 <= &p->aMem[(p->nMem+1 - p->nCursor)]);
> assert(memIsValid(pIn1));
> if (mem_apply_type(pIn1, type) != 0) {
> - diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
> - sql_value_text(pIn1),
> + const char *value;
> + if ((pIn1->flags & MEM_Subtype) != 0 &&
> + pIn1->subtype == SQL_SUBTYPE_MSGPACK) {
> + if (mp_typeof(*pIn1->z) == MP_MAP)
> + value = "map";
> + else
> + value = "array";
> + } else {
> + value = (const char *)sql_value_text(pIn1);
Why not simply patch sql_value_text() to make it convert
map/array to string representation? I’m 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 = 3}, 'asd'})
> box.execute('UPDATE t SET b = false WHERE i = 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;’)
Why ‘IF EXISTS’? Btw I’d better use space:drop() to avoid
SQL’s overhead.
More information about the Tarantool-patches
mailing list