Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH] sql: add check for <WITH> absence in <CREATE VIEW>
@ 2019-08-02 12:52 Roman Khabibov
  2019-08-09 15:15 ` [tarantool-patches] " n.pettik
  0 siblings, 1 reply; 12+ messages in thread
From: Roman Khabibov @ 2019-08-02 12:52 UTC (permalink / raw)
  To: tarantool-patches; +Cc: korablev

Check that <CREATE VIEW> hasn't <WITH> after <AS>: "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 <WITH>");
+			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(
         -- </view-23.8>
     })
 
+-- 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);
+    ]], {
+        -- <view-24.1>
+        -- </view-24.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;
+    ]], {
+        -- <view-24.2>
+        1,"Failed to create space 'V': can't create view as <WITH>"
+        -- </view-24.2>
+    })
+
+test:do_execsql_test(
+    "view-24.3",
+    [[
+        DROP TABLE ts
+    ]], {
+        -- <view-24.3>
+        -- </view-24.3>
+    })
+
 test:finish_test()
-- 
2.20.1 (Apple Git-117)

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-09-13 14:57 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-02 12:52 [tarantool-patches] [PATCH] sql: add check for <WITH> absence in <CREATE VIEW> Roman Khabibov
2019-08-09 15:15 ` [tarantool-patches] " n.pettik
2019-08-13 12:42   ` Roman Khabibov
2019-08-13 22:10     ` n.pettik
2019-08-16 19:09       ` Roman Khabibov
2019-08-19 15:39         ` Roman Khabibov
2019-08-20 19:41         ` n.pettik
2019-08-28 12:17           ` Roman Khabibov
2019-08-29 17:59             ` Nikita Pettik
2019-09-04 14:14               ` Roman Khabibov
2019-09-11 13:32                 ` Nikita Pettik
2019-09-13 14:57                   ` Roman Khabibov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox