7373import net .sf .jsqlparser .expression .operators .relational .NotEqualsTo ;
7474import net .sf .jsqlparser .schema .Column ;
7575import net .sf .jsqlparser .schema .Table ;
76+ import net .sf .jsqlparser .statement .delete .Delete ;
77+ import net .sf .jsqlparser .statement .insert .Insert ;
78+ import net .sf .jsqlparser .statement .replace .Replace ;
7679import net .sf .jsqlparser .statement .select .FromItemVisitor ;
7780import net .sf .jsqlparser .statement .select .Join ;
7881import net .sf .jsqlparser .statement .select .LateralSubSelect ;
8487import net .sf .jsqlparser .statement .select .SubSelect ;
8588import net .sf .jsqlparser .statement .select .ValuesList ;
8689import net .sf .jsqlparser .statement .select .WithItem ;
90+ import net .sf .jsqlparser .statement .update .Update ;
8791
8892/**
8993 * Find all used tables within an select statement.
@@ -98,15 +102,65 @@ public class TablesNamesFinder implements SelectVisitor, FromItemVisitor, Expres
98102 */
99103 private List <String > otherItemNames ;
100104
105+ /**
106+ * Main entry for this Tool class. A list of found tables is returned.
107+ *
108+ * @param delete
109+ * @return
110+ */
111+ public List <String > getTableList (Delete delete ) {
112+ init ();
113+ tables .add (delete .getTable ().getName ());
114+ delete .getWhere ().accept (this );
115+
116+ return tables ;
117+ }
118+
119+ /**
120+ * Main entry for this Tool class. A list of found tables is returned.
121+ *
122+ * @param insert
123+ * @return
124+ */
125+ public List <String > getTableList (Insert insert ) {
126+ init ();
127+ tables .add (insert .getTable ().getName ());
128+ if (insert .getItemsList () != null ) {
129+ insert .getItemsList ().accept (this );
130+ }
131+
132+ return tables ;
133+ }
134+
135+ /**
136+ * Main entry for this Tool class. A list of found tables is returned.
137+ *
138+ * @param replace
139+ * @return
140+ */
141+ public List <String > getTableList (Replace replace ) {
142+ init ();
143+ tables .add (replace .getTable ().getName ());
144+ if (replace .getExpressions () != null ) {
145+ for (Expression expression : replace .getExpressions ()) {
146+ expression .accept (this );
147+ }
148+ }
149+ if (replace .getItemsList () != null ) {
150+ replace .getItemsList ().accept (this );
151+ }
152+
153+ return tables ;
154+ }
155+
101156 /**
102157 * Main entry for this Tool class. A list of found tables is returned.
103158 *
104159 * @param select
105160 * @return
106161 */
107162 public List <String > getTableList (Select select ) {
108- otherItemNames = new ArrayList <String >();
109- tables = new ArrayList <String >();
163+ init ();
110164 if (select .getWithItemsList () != null ) {
111165 for (WithItem withItem : select .getWithItemsList ()) {
112166 withItem .accept (this );
@@ -117,6 +171,27 @@ public List<String> getTableList(Select select) {
117171 return tables ;
118172 }
119173
174+ /**
175+ * Main entry for this Tool class. A list of found tables is returned.
176+ *
177+ * @param update
178+ * @return
179+ */
180+ public List <String > getTableList (Update update ) {
181+ init ();
182+ tables .add (update .getTable ().getName ());
183+ if (update .getExpressions () != null ) {
184+ for (Expression expression : update .getExpressions ()) {
185+ expression .accept (this );
186+ }
187+ }
188+ if (update .getWhere () != null ) {
189+ update .getWhere ().accept (this );
190+ }
191+
192+ return tables ;
193+ }
194+
120195 @ Override
121196 public void visit (WithItem withItem ) {
122197 otherItemNames .add (withItem .getName ().toLowerCase ());
@@ -400,4 +475,9 @@ public void visit(MultiExpressionList multiExprList) {
400475 @ Override
401476 public void visit (ValuesList valuesList ) {
402477 }
478+
479+ private void init () {
480+ otherItemNames = new ArrayList <String >();
481+ tables = new ArrayList <String >();
482+ }
403483}
0 commit comments