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 839812670C for ; Fri, 2 Aug 2019 08:52:55 -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 n0qZHwIPdpsf for ; Fri, 2 Aug 2019 08:52:55 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (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 4350F26707 for ; Fri, 2 Aug 2019 08:52:55 -0400 (EDT) From: Roman Khabibov Subject: [tarantool-patches] [PATCH] sql: add check for absence in Date: Fri, 2 Aug 2019 15:52:52 +0300 Message-Id: <20190802125252.54621-1-roman.habibov@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: korablev@tarantool.org Check that hasn't after : "CREATE VIEW v AS WITH ... SELECT ...". Throw error, if it has. Closes #4149 --- Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/gh-4149-view Issue: https://github.com/tarantool/tarantool/issues/4149 src/box/sql/build.c | 7 +++++++ test/sql-tap/view.test.lua | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/box/sql/build.c b/src/box/sql/build.c index ccec10543..e34202c9a 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -1320,6 +1320,13 @@ sql_create_view(struct Parse *parse_context) &create_entity_def->name); if (space == NULL || parse_context->is_aborted) goto create_view_fail; + assert(view_def->select != NULL); + if (view_def->select->pWith != NULL) { + diag_set(ClientError, ER_CREATE_SPACE, space->def->name, + "can't create view as "); + parse_context->is_aborted = true; + goto create_view_fail; + } struct space *select_res_space = sqlResultSetOfSelect(parse_context, view_def->select); if (select_res_space == NULL) diff --git a/test/sql-tap/view.test.lua b/test/sql-tap/view.test.lua index 101f4c3e7..a554c17a7 100755 --- a/test/sql-tap/view.test.lua +++ b/test/sql-tap/view.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool test = require("sqltester") -test:plan(73) +test:plan(76) --!./tcltestrunner.lua -- 2002 February 26 @@ -1233,4 +1233,39 @@ test:do_catchsql_test( -- }) +-- gh-4149: Check error message for "CREATE VIEW v AS WITH ... +-- SELECT ...". +test:do_execsql_test( + "view-24.1", + [[ + CREATE TABLE ts (s1 INT PRIMARY KEY); + INSERT INTO ts VALUES (1); + ]], { + -- + -- + }) + +test:do_catchsql_test( + "view-24.2", + [[ + CREATE VIEW v AS WITH RECURSIVE w AS ( + SELECT s1 FROM ts + UNION ALL + SELECT s1+1 FROM w WHERE s1 < 4) + SELECT * FROM w; + ]], { + -- + 1,"Failed to create space 'V': can't create view as " + -- + }) + +test:do_execsql_test( + "view-24.3", + [[ + DROP TABLE ts + ]], { + -- + -- + }) + test:finish_test() -- 2.20.1 (Apple Git-117)