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
1212
1313 4) Oracle Alternative Quoting is partially supported for common brackets such as ``q'{...}' ``, ``q'[...]' ``, ``q'(...)' `` and ``q''...'' ``.
1414
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 `` .
1616
1717
1818Compile from Source Code
@@ -186,6 +186,23 @@ Traverse the Java Object Tree using the Visitor Patterns:
186186 // Invoke the Statement Visitor
187187 stmt. accept(statementVisitor);
188188
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+
189206
190207 Build a SQL Statement
191208==============================
Original file line number Diff line number Diff line change @@ -489,6 +489,11 @@ public void testConnectedByRootOperator() throws JSQLParserException {
489489 @ Test
490490 void testJoinSubSelect () throws JSQLParserException {
491491 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" );
493498 }
494499}
You can’t perform that action at this time.
0 commit comments