Skip to content

Commit 8f8439e

Browse files
authored
fix: [FEATURE] TablesNamesFinder does not support CREATE VIEW #2123 (#2124)
1 parent 18c1a2c commit 8f8439e

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,8 +1151,11 @@ public void visit(CreateTable createTable) {
11511151
}
11521152

11531153
@Override
1154-
public <S> Void visit(CreateView createView, S context) {
1155-
throwUnsupported(createView);
1154+
public <S> Void visit(CreateView create, S context) {
1155+
visit(create.getView(), null);
1156+
if (create.getSelect() != null) {
1157+
create.getSelect().accept((SelectVisitor<?>) this, context);
1158+
}
11561159
return null;
11571160
}
11581161

src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,19 @@ public void testInsertSelect() throws Exception {
152152
}
153153

154154
@Test
155-
public void testCreateSelect() throws Exception {
155+
public void testCreateTableSelect() throws Exception {
156156
String sqlStr = "CREATE TABLE mytable AS SELECT mycolumn FROM mytable2";
157157
assertThat(TablesNamesFinder.findTables(sqlStr)).containsExactlyInAnyOrder("mytable",
158158
"mytable2");
159159
}
160160

161+
@Test
162+
public void testCreateViewSelect() throws Exception {
163+
String sqlStr = "CREATE VIEW mytable AS SELECT mycolumn FROM mytable2";
164+
assertThat(TablesNamesFinder.findTables(sqlStr)).containsExactlyInAnyOrder("mytable",
165+
"mytable2");
166+
}
167+
161168
@Test
162169
public void testInsertSubSelect() throws JSQLParserException {
163170
String sqlStr =

0 commit comments

Comments
 (0)