From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp52.i.mail.ru (smtp52.i.mail.ru [94.100.177.112]) (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 ECA1D44643D for ; Sat, 12 Sep 2020 00:51:18 +0300 (MSK) From: Roman Khabibov Date: Sat, 12 Sep 2020 00:51:14 +0300 Message-Id: <20200911215115.6622-6-roman.habibov@tarantool.org> In-Reply-To: <20200911215115.6622-1-roman.habibov@tarantool.org> References: <20200911215115.6622-1-roman.habibov@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v4 5/6] box: disallow to modify format of a view List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org Cc: v.shpilevoy@tarantool.org Disallow to modify format and field_count of a view. Needed for #3075 --- src/box/alter.cc | 8 ++++ test/box/view-dont-modify-format.result | 51 +++++++++++++++++++++++ test/box/view-dont-modify-format.test.lua | 18 ++++++++ 3 files changed, 77 insertions(+) create mode 100644 test/box/view-dont-modify-format.result create mode 100644 test/box/view-dont-modify-format.test.lua diff --git a/src/box/alter.cc b/src/box/alter.cc index ba96d9c62..3bfbb690a 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -2441,6 +2441,14 @@ on_replace_dd_space(struct trigger * /* trigger */, void *event) "view"); return -1; } + if (def->opts.is_view && (def->field_count != + old_space->def->field_count)) { + diag_set(ClientError, ER_ALTER_SPACE, + space_name(old_space), + "can not modify format or field_count of a " + "view"); + return -1; + } /* * Allow change of space properties, but do it * in WAL-error-safe mode. diff --git a/test/box/view-dont-modify-format.result b/test/box/view-dont-modify-format.result new file mode 100644 index 000000000..c130db49c --- /dev/null +++ b/test/box/view-dont-modify-format.result @@ -0,0 +1,51 @@ +-- test-run result file version 2 +-- +-- Make sure we can't modify a view format. +-- +box.execute("CREATE TABLE t1 (a INT PRIMARY KEY);") + | --- + | - row_count: 1 + | ... +box.execute("CREATE VIEW v AS SELECT * FROM t1;") + | --- + | - row_count: 1 + | ... +view = box.space._space.index[2]:select('V')[1]:totable() + | --- + | ... +view_format = view[7] + | --- + | ... +f = {type = 'string', nullable_action = 'none', name = 'C', is_nullable = true} + | --- + | ... +table.insert(view_format, f) + | --- + | ... +view[5] = 3 + | --- + | ... +view[7] = view_format + | --- + | ... +box.space._space:replace(view) + | --- + | - error: 'Can''t modify space ''V'': can not modify format or field_count of a view' + | ... + +view = box.space.V + | --- + | ... +view:format({}) + | --- + | - error: 'Can''t modify space ''V'': can not modify format or field_count of a view' + | ... + +box.execute("DROP VIEW v;") + | --- + | - row_count: 1 + | ... +box.execute("DROP TABLE t1;") + | --- + | - row_count: 1 + | ... diff --git a/test/box/view-dont-modify-format.test.lua b/test/box/view-dont-modify-format.test.lua new file mode 100644 index 000000000..b57d2b94e --- /dev/null +++ b/test/box/view-dont-modify-format.test.lua @@ -0,0 +1,18 @@ +-- +-- Make sure we can't modify a view format. +-- +box.execute("CREATE TABLE t1 (a INT PRIMARY KEY);") +box.execute("CREATE VIEW v AS SELECT * FROM t1;") +view = box.space._space.index[2]:select('V')[1]:totable() +view_format = view[7] +f = {type = 'string', nullable_action = 'none', name = 'C', is_nullable = true} +table.insert(view_format, f) +view[5] = 3 +view[7] = view_format +box.space._space:replace(view) + +view = box.space.V +view:format({}) + +box.execute("DROP VIEW v;") +box.execute("DROP TABLE t1;") -- 2.24.3 (Apple Git-128)