|
23 | 23 |
|
24 | 24 | import java.util.ArrayList; |
25 | 25 | import java.util.List; |
26 | | - |
27 | 26 | import net.sf.jsqlparser.expression.AllComparisonExpression; |
28 | 27 | import net.sf.jsqlparser.expression.AnalyticExpression; |
29 | 28 | import net.sf.jsqlparser.expression.AnyComparisonExpression; |
|
45 | 44 | import net.sf.jsqlparser.expression.KeepExpression; |
46 | 45 | import net.sf.jsqlparser.expression.LongValue; |
47 | 46 | import net.sf.jsqlparser.expression.MySQLGroupConcat; |
48 | | -import net.sf.jsqlparser.expression.ValueListExpression; |
49 | 47 | import net.sf.jsqlparser.expression.NotExpression; |
50 | 48 | import net.sf.jsqlparser.expression.NullValue; |
51 | 49 | import net.sf.jsqlparser.expression.NumericBind; |
|
59 | 57 | import net.sf.jsqlparser.expression.TimeValue; |
60 | 58 | import net.sf.jsqlparser.expression.TimestampValue; |
61 | 59 | import net.sf.jsqlparser.expression.UserVariable; |
| 60 | +import net.sf.jsqlparser.expression.ValueListExpression; |
62 | 61 | import net.sf.jsqlparser.expression.WhenClause; |
63 | 62 | import net.sf.jsqlparser.expression.operators.arithmetic.Addition; |
64 | 63 | import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseAnd; |
|
93 | 92 | import net.sf.jsqlparser.expression.operators.relational.RegExpMySQLOperator; |
94 | 93 | import net.sf.jsqlparser.schema.Column; |
95 | 94 | import net.sf.jsqlparser.schema.Table; |
| 95 | +import net.sf.jsqlparser.statement.Block; |
96 | 96 | import net.sf.jsqlparser.statement.Commit; |
97 | 97 | import net.sf.jsqlparser.statement.SetStatement; |
98 | 98 | import net.sf.jsqlparser.statement.Statement; |
|
135 | 135 |
|
136 | 136 | /** |
137 | 137 | * Find all used tables within an select statement. |
138 | | - * |
| 138 | + * |
139 | 139 | * Override extractTableName method to modify the extracted table names (e.g. without schema). |
140 | 140 | */ |
141 | 141 | public class TablesNamesFinder implements SelectVisitor, FromItemVisitor, ExpressionVisitor, ItemsListVisitor, SelectItemVisitor, StatementVisitor { |
142 | 142 |
|
143 | 143 | private static final String NOT_SUPPORTED_YET = "Not supported yet."; |
144 | 144 | private List<String> tables; |
145 | 145 | private boolean allowColumnProcessing = false; |
146 | | - |
| 146 | + |
147 | 147 | /** |
148 | 148 | * There are special names, that are not table names but are parsed as tables. These names are |
149 | 149 | * collected here and are not included in the tables - names anymore. |
@@ -210,25 +210,26 @@ public void visit(PlainSelect plainSelect) { |
210 | 210 | if (plainSelect.getWhere() != null) { |
211 | 211 | plainSelect.getWhere().accept(this); |
212 | 212 | } |
213 | | - |
214 | | - if(plainSelect.getHaving() != null){ |
| 213 | + |
| 214 | + if (plainSelect.getHaving() != null) { |
215 | 215 | plainSelect.getHaving().accept(this); |
216 | 216 | } |
217 | | - |
| 217 | + |
218 | 218 | if (plainSelect.getOracleHierarchical() != null) { |
219 | 219 | plainSelect.getOracleHierarchical().accept(this); |
220 | 220 | } |
221 | 221 | } |
222 | 222 |
|
223 | 223 | /** |
224 | 224 | * Override to adapt the tableName generation (e.g. with / without schema). |
| 225 | + * |
225 | 226 | * @param table |
226 | | - * @return |
| 227 | + * @return |
227 | 228 | */ |
228 | 229 | protected String extractTableName(Table table) { |
229 | 230 | return table.getFullyQualifiedName(); |
230 | 231 | } |
231 | | - |
| 232 | + |
232 | 233 | @Override |
233 | 234 | public void visit(Table tableName) { |
234 | 235 | String tableWholeName = extractTableName(tableName); |
@@ -471,7 +472,7 @@ public void visit(AnyComparisonExpression anyComparisonExpression) { |
471 | 472 | @Override |
472 | 473 | public void visit(SubJoin subjoin) { |
473 | 474 | subjoin.getLeft().accept(this); |
474 | | - for(Join join : subjoin.getJoinList()) { |
| 475 | + for (Join join : subjoin.getJoinList()) { |
475 | 476 | join.getRightItem().accept(this); |
476 | 477 | } |
477 | 478 | } |
@@ -543,10 +544,11 @@ public void visit(ValuesList valuesList) { |
543 | 544 | } |
544 | 545 |
|
545 | 546 | /** |
546 | | - * Initializes table names collector. Important is the usage of Column instances to find |
547 | | - * table names. This is only allowed for expression parsing, where a better place for |
548 | | - * tablenames could not be there. For complete statements only from items are used to avoid |
549 | | - * some alias as tablenames. |
| 547 | + * Initializes table names collector. Important is the usage of Column instances to find table |
| 548 | + * names. This is only allowed for expression parsing, where a better place for tablenames could |
| 549 | + * not be there. For complete statements only from items are used to avoid some alias as |
| 550 | + * tablenames. |
| 551 | + * |
550 | 552 | * @param allowColumnProcessing |
551 | 553 | */ |
552 | 554 | protected void init(boolean allowColumnProcessing) { |
@@ -621,7 +623,7 @@ public void visit(KeepExpression aexpr) { |
621 | 623 | @Override |
622 | 624 | public void visit(MySQLGroupConcat groupConcat) { |
623 | 625 | } |
624 | | - |
| 626 | + |
625 | 627 | @Override |
626 | 628 | public void visit(ValueListExpression valueList) { |
627 | 629 | valueList.getExpressionList().accept(this); |
@@ -808,4 +810,11 @@ public void visit(UseStatement use) { |
808 | 810 | public void visit(ParenthesisFromItem parenthesis) { |
809 | 811 | parenthesis.getFromItem().accept(this); |
810 | 812 | } |
| 813 | + |
| 814 | + @Override |
| 815 | + public void visit(Block block) { |
| 816 | + if (block.getStatements() != null) { |
| 817 | + visit(block.getStatements()); |
| 818 | + } |
| 819 | + } |
811 | 820 | } |
0 commit comments