From 8f8439e485a412e6b7046bf2de28c44db0ca7a24 Mon Sep 17 00:00:00 2001 From: Cedric Dandoy <153516516+cptnricard@users.noreply.github.com> Date: Sun, 15 Dec 2024 09:12:26 -0600 Subject: [PATCH] fix: [FEATURE] TablesNamesFinder does not support CREATE VIEW #2123 (#2124) --- .../java/net/sf/jsqlparser/util/TablesNamesFinder.java | 7 +++++-- .../net/sf/jsqlparser/util/TablesNamesFinderTest.java | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java b/src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java index 122d5cf2e..3e8bc9e1b 100644 --- a/src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java +++ b/src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java @@ -1151,8 +1151,11 @@ public void visit(CreateTable createTable) { } @Override - public Void visit(CreateView createView, S context) { - throwUnsupported(createView); + public Void visit(CreateView create, S context) { + visit(create.getView(), null); + if (create.getSelect() != null) { + create.getSelect().accept((SelectVisitor) this, context); + } return null; } diff --git a/src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java b/src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java index 66304b1da..111fba75a 100644 --- a/src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java +++ b/src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java @@ -152,12 +152,19 @@ public void testInsertSelect() throws Exception { } @Test - public void testCreateSelect() throws Exception { + public void testCreateTableSelect() throws Exception { String sqlStr = "CREATE TABLE mytable AS SELECT mycolumn FROM mytable2"; assertThat(TablesNamesFinder.findTables(sqlStr)).containsExactlyInAnyOrder("mytable", "mytable2"); } + @Test + public void testCreateViewSelect() throws Exception { + String sqlStr = "CREATE VIEW mytable AS SELECT mycolumn FROM mytable2"; + assertThat(TablesNamesFinder.findTables(sqlStr)).containsExactlyInAnyOrder("mytable", + "mytable2"); + } + @Test public void testInsertSubSelect() throws JSQLParserException { String sqlStr =