Skip to content

fix: [FEATURE] TablesNamesFinder does not support CREATE VIEW #2123 #2124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading