File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
main/java/net/sf/jsqlparser/util
test/java/net/sf/jsqlparser/util Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -185,6 +185,17 @@ public List<String> getTableList(Update update) {
185185 expression .accept (this );
186186 }
187187 }
188+
189+ if (update .getFromItem () != null ) {
190+ update .getFromItem ().accept (this );
191+ }
192+
193+ if (update .getJoins () != null ) {
194+ for (Join join : update .getJoins ()) {
195+ join .getRightItem ().accept (this );
196+ }
197+ }
198+
188199 if (update .getWhere () != null ) {
189200 update .getWhere ().accept (this );
190201 }
@@ -217,7 +228,9 @@ public void visit(PlainSelect plainSelect) {
217228 public void visit (Table tableName ) {
218229 String tableWholeName = tableName .getWholeTableName ();
219230 if (!otherItemNames .contains (tableWholeName .toLowerCase ())) {
220- tables .add (tableWholeName );
231+ if (!tables .contains (tableWholeName )) {
232+ tables .add (tableWholeName );
233+ }
221234 }
222235 }
223236
Original file line number Diff line number Diff line change @@ -235,6 +235,19 @@ public void testGetTableListFromUpdate2() throws Exception {
235235 assertTrue (tableList .contains ("MY_TABLE1" ));
236236 assertTrue (tableList .contains ("MY_TABLE3" ));
237237 }
238+
239+ public void testGetTableListFromUpdate3 () throws Exception {
240+ String sql = "UPDATE MY_TABLE1 SET a = 5 FROM MY_TABLE1 INNER JOIN MY_TABLE2 on MY_TABLE1.C = MY_TABLE2.D WHERE 0 < (SELECT COUNT(b) FROM MY_TABLE3)" ;
241+ net .sf .jsqlparser .statement .Statement statement = pm .parse (new StringReader (sql ));
242+
243+ Update updateStatement = (Update ) statement ;
244+ TablesNamesFinder tablesNamesFinder = new TablesNamesFinder ();
245+ List <String > tableList = tablesNamesFinder .getTableList (updateStatement );
246+ assertEquals (3 , tableList .size ());
247+ assertTrue (tableList .contains ("MY_TABLE1" ));
248+ assertTrue (tableList .contains ("MY_TABLE2" ));
249+ assertTrue (tableList .contains ("MY_TABLE3" ));
250+ }
238251
239252 private String getLine (BufferedReader in ) throws Exception {
240253 return CCJSqlParserManagerTest .getLine (in );
You can’t perform that action at this time.
0 commit comments