From: imeevma@tarantool.org To: korablev@tarantool.org Cc: tarantool-patches@freelists.org Subject: [tarantool-patches] [PATCH v1 1/1] sql: Fix UPDATE for types unknown to SQL. Date: Fri, 28 Jun 2019 18:34:23 +0300 [thread overview] Message-ID: <132ca83597d0e9c2b4ef75bc8f0d03d22cdf27dd.1561736006.git.imeevma@gmail.com> (raw) Before this patch, UPDATE throwed an error when executed on a tuple with types unknown to SQL. This patch fixes the problem in case the fields with unknown types are not updated. Closes #4189 --- https://github.com/tarantool/tarantool/issues/4189 https://github.com/tarantool/tarantool/tree/imeevma/gh-4189-field-type-conversion-error src/box/sql/vdbe.c | 25 +++++++++++++++++++++++++ test/sql/types.result | 43 +++++++++++++++++++++++++++++++++++++++++++ test/sql/types.test.lua | 17 +++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index c8887f9..8ddc29d 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -294,6 +294,20 @@ mem_apply_numeric_type(struct Mem *record) * SCALAR: * Mem is unchanged, but flag is set to BLOB. * + * BOOLEAN: + * If memory holds BOOLEAN no actions take place. + * + * ANY: + * Mem is unchanged, no actions take place. + * + * MAP: + * If memory holds value with SQL_SUBTYPE_MSGPACK subtype and + * data has MP_MAP type, no actions take place. + * + * ARRAY: + * If memory holds value with SQL_SUBTYPE_MSGPACK subtype and + * data has MP_ARRAY type, no actions take place. + * * @param record The value to apply type to. * @param type The type to be applied. */ @@ -337,8 +351,19 @@ mem_apply_type(struct Mem *record, enum field_type type) } record->flags &= ~(MEM_Real | MEM_Int); return 0; + case FIELD_TYPE_ANY: case FIELD_TYPE_SCALAR: return 0; + case FIELD_TYPE_MAP: + if (record->subtype == SQL_SUBTYPE_MSGPACK && + mp_typeof(*record->z) == MP_MAP) + return 0; + return -1; + case FIELD_TYPE_ARRAY: + if (record->subtype == SQL_SUBTYPE_MSGPACK && + mp_typeof(*record->z) == MP_ARRAY) + return 0; + return -1; default: return -1; } diff --git a/test/sql/types.result b/test/sql/types.result index cdfb1e7..5cc7f16 100644 --- a/test/sql/types.result +++ b/test/sql/types.result @@ -966,3 +966,46 @@ box.execute('SELECT ?', {true}) rows: - [true] ... +-- +-- gh-4189: Update throws an error when executed on a tuple with +-- types unknown to SQL. +-- +format = {} +--- +... +format[1] = {type = 'integer', name = 'I'} +--- +... +format[2] = {type = 'boolean', name = 'B'} +--- +... +format[3] = {type = 'array', name = 'F1'} +--- +... +format[4] = {type = 'map', name = 'F2'} +--- +... +format[5] = {type = 'any', name = 'F3'} +--- +... +s = box.schema.space.create('T', {format = format}) +--- +... +ii = s:create_index('ii') +--- +... +s:insert({1, true, {1, 2}, {a = 3}, 'asd'}) +--- +- [1, true, [1, 2], {'a': 3}, 'asd'] +... +box.execute('UPDATE t SET b = false WHERE i = 1;') +--- +- row_count: 1 +... +s:select() +--- +- - [1, false, [1, 2], {'a': 3}, 'asd'] +... +s:drop() +--- +... diff --git a/test/sql/types.test.lua b/test/sql/types.test.lua index ae1a0ab..d33314a 100644 --- a/test/sql/types.test.lua +++ b/test/sql/types.test.lua @@ -234,3 +234,20 @@ box.execute('SELECT \'9223372036854\' + 1;') -- Fix BOOLEAN bindings. box.execute('SELECT ?', {true}) + +-- +-- gh-4189: Update throws an error when executed on a tuple with +-- types unknown to SQL. +-- +format = {} +format[1] = {type = 'integer', name = 'I'} +format[2] = {type = 'boolean', name = 'B'} +format[3] = {type = 'array', name = 'F1'} +format[4] = {type = 'map', name = 'F2'} +format[5] = {type = 'any', name = 'F3'} +s = box.schema.space.create('T', {format = format}) +ii = s:create_index('ii') +s:insert({1, true, {1, 2}, {a = 3}, 'asd'}) +box.execute('UPDATE t SET b = false WHERE i = 1;') +s:select() +s:drop() -- 2.7.4
next reply other threads:[~2019-06-28 15:34 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-06-28 15:34 imeevma [this message] 2019-07-01 23:29 ` [tarantool-patches] " n.pettik 2019-07-08 10:13 ` Mergen Imeev 2019-07-08 13:32 ` n.pettik 2019-07-09 9:14 ` Imeev Mergen 2019-07-15 13:32 ` n.pettik 2019-07-16 14:19 ` Mergen Imeev 2019-07-18 15:59 ` n.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=132ca83597d0e9c2b4ef75bc8f0d03d22cdf27dd.1561736006.git.imeevma@gmail.com \ --to=imeevma@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH v1 1/1] sql: Fix UPDATE for types unknown to SQL.' \ /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