File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
test/java/net/sf/jsqlparser/util Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ How to use it
12
12
13
13
4) Oracle Alternative Quoting is partially supported for common brackets such as ``q'{...}' ``, ``q'[...]' ``, ``q'(...)' `` and ``q''...'' ``.
14
14
15
- 5) Supported Statement Separators are Semicolon ``\ ; ``, ``GO ``, Slash ``\ / `` or 2 empty lines.
15
+ 5) Supported Statement Separators are Semicolon ``; ``, ``GO ``, Slash ``/ `` or two empty lines `` \n\n\n `` .
16
16
17
17
18
18
Compile from Source Code
@@ -186,6 +186,23 @@ Traverse the Java Object Tree using the Visitor Patterns:
186
186
// Invoke the Statement Visitor
187
187
stmt. accept(statementVisitor);
188
188
189
+ Find Table Names
190
+ ==============================
191
+
192
+ The class ``net.sf.jsqlparser.util.TablesNamesFinder `` can be used to return all Table Names from a Query or an Expression.
193
+
194
+ .. code-block :: java
195
+
196
+ // find in Statements
197
+ String sqlStr = " select * from A left join B on A.id=B.id and A.age = (select age from C)" ;
198
+ Set<String > tableNames = TablesNamesFinder . findTables(sqlStr);
199
+ assertThat( tableNames ). containsExactlyInAnyOrder(" A" , " B" , " C" );
200
+
201
+ // find in Expressions
202
+ String exprStr = " A.id=B.id and A.age = (select age from C)" ;
203
+ tableNames = TablesNamesFinder . findTables(sqlStr);
204
+ assertThat( tableNames ). containsExactlyInAnyOrder(" A" , " B" , " C" );
205
+
189
206
190
207
Build a SQL Statement
191
208
==============================
Original file line number Diff line number Diff line change @@ -489,6 +489,11 @@ public void testConnectedByRootOperator() throws JSQLParserException {
489
489
@ Test
490
490
void testJoinSubSelect () throws JSQLParserException {
491
491
String sqlStr = "select * from A left join B on A.id=B.id and A.age = (select age from C)" ;
492
- assertThat (TablesNamesFinder .findTables (sqlStr )).containsExactlyInAnyOrder ("A" , "B" , "C" );
492
+ Set <String > tableNames = TablesNamesFinder .findTables (sqlStr );
493
+ assertThat ( tableNames ).containsExactlyInAnyOrder ("A" , "B" , "C" );
494
+
495
+ String exprStr = "A.id=B.id and A.age = (select age from C)" ;
496
+ tableNames = TablesNamesFinder .findTables (sqlStr );
497
+ assertThat ( tableNames ).containsExactlyInAnyOrder ("A" , "B" , "C" );
493
498
}
494
499
}
You can’t perform that action at this time.
0 commit comments