Skip to content

Commit

Permalink
fix: [FEATURE] TablesNamesFinder does not support CREATE VIEW #2123 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cptnricard authored Dec 15, 2024
1 parent 18c1a2c commit 8f8439e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1151,8 +1151,11 @@ public void visit(CreateTable createTable) {
}

@Override
public <S> Void visit(CreateView createView, S context) {
throwUnsupported(createView);
public <S> Void visit(CreateView create, S context) {
visit(create.getView(), null);
if (create.getSelect() != null) {
create.getSelect().accept((SelectVisitor<?>) this, context);
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 8f8439e

Please sign in to comment.